diff --git a/blinkpy.py b/blinkpy.py index 7f58a4c..67aa2ca 100644 --- a/blinkpy.py +++ b/blinkpy.py @@ -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({ diff --git a/tests/test_blink_system.py b/tests/test_blink_system.py new file mode 100644 index 0000000..9027beb --- /dev/null +++ b/tests/test_blink_system.py @@ -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) + \ No newline at end of file