Initial checkin for test_blink_system.py
This commit is contained in:
+2
-1
@@ -422,11 +422,12 @@ class Blink(object):
|
||||
|
||||
def get_auth_token(self):
|
||||
"""Retrieves the authentication token from Blink"""
|
||||
|
||||
if not isinstance(self._username, str):
|
||||
raise BlinkAuthenticationException(ERROR.USERNAME)
|
||||
if not isinstance(self._password, str):
|
||||
raise BlinkAuthenticationException(ERROR.PASSWORD)
|
||||
|
||||
|
||||
headers = {'Host': DEFAULT_URL,
|
||||
'Content-Type': 'application/json'}
|
||||
data = json.dumps({
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import requests
|
||||
import unittest
|
||||
import blinkpy
|
||||
from unittest import mock
|
||||
import constants as const
|
||||
|
||||
USERNAME = 'foobar'
|
||||
PASSWORD = 'deadbeef'
|
||||
|
||||
class TestBlinkSystem(unittest.TestCase):
|
||||
"""Test the Blink class in blinkpy."""
|
||||
def test_initialization(self):
|
||||
"""Verify we can initialize blink."""
|
||||
blink = blinkpy.Blink(username=USERNAME, password=PASSWORD)
|
||||
self.assertEqual(blink._username, USERNAME)
|
||||
self.assertEqual(blink._password, PASSWORD)
|
||||
|
||||
def test_no_credentials(self):
|
||||
"""Check that we throw an exception when no username/password."""
|
||||
blink = blinkpy.Blink()
|
||||
with self.assertRaises(blinkpy.BlinkAuthenticationException):
|
||||
blink.get_auth_token()
|
||||
with self.assertRaises(blinkpy.BlinkAuthenticationException):
|
||||
blink.setup_system()
|
||||
|
||||
def test_no_auth_header(self):
|
||||
"""Check that we throw an excpetion when no auth header given."""
|
||||
blink = blinkpy.Blink(username=USERNAME, password=PASSWORD)
|
||||
with self.assertRaises(blinkpy.BlinkException):
|
||||
blink.get_ids()
|
||||
|
||||
@mock.patch('blinkpy.getpass.getpass')
|
||||
def test_manual_login(self, getpwd):
|
||||
"""Check that we can manually use the login() function."""
|
||||
blink = blinkpy.Blink()
|
||||
getpwd.return_value = PASSWORD
|
||||
with mock.patch('builtins.input', return_value=USERNAME):
|
||||
blink.login()
|
||||
self.assertEqual(blink._username, USERNAME)
|
||||
self.assertEqual(blink._password, PASSWORD)
|
||||
|
||||
Reference in New Issue
Block a user