def test_when_api_app_provided_check_if_breaks_on_error(self, test_post): settings.ACCOUNTKEY = 'acckey123' settings.SECRETKEY = 'secret321' mock_resp = Mock() mock_resp.json.return_value = {} # this will raise KeyError test_post.return_value = mock_resp with self.assertRaises(SystemExit): auth.log_in_for_userkey()
def test_when_ask_for_password_check_if_userkey_is_set_and_saved( self, test_getpass, test_post, test_save_userkey): test_getpass.return_value = 'pass25word' mock_resp = Mock() mock_resp.json.return_value = {'userkey': 'user123key'} test_post.return_value = mock_resp auth.log_in_for_userkey() self.assertEqual(settings.USERKEY, 'user123key') test_save_userkey.assert_called_with('user123key')
def test_when_api_app_provided_check_if_userkey_is_set_and_saved( self, test_post, test_save_userkey): settings.ACCOUNTKEY = 'acckey123' settings.SECRETKEY = 'secret321' mock_resp = Mock() mock_resp.json.return_value = {'userkey': 'user123key'} test_post.return_value = mock_resp auth.log_in_for_userkey() self.assertEqual(settings.USERKEY, 'user123key') test_save_userkey.assert_called_with('user123key')
def test_when_api_app_provided_check_if_correct_post_args(self, test_post): settings.ACCOUNTKEY = 'acckey123' settings.SECRETKEY = 'secret321' data = {'login': '******', 'accountkey': 'acckey123'} headers = auth.apisign(self.url, 'secret321', **data) mock_resp = Mock() mock_resp.json.return_value = {'userkey': '123'} test_post.return_value = mock_resp auth.log_in_for_userkey() test_post.assert_called_with(self.url, data=data, headers=headers)
def test_when_ask_for_password_check_if_correct_post_args( self, test_getpass, test_post): settings.ACCOUNTKEY = None test_getpass.return_value = 'pass25word' data = {'login': '******', 'password': '******'} headers = {} mock_resp = Mock() mock_resp.json.return_value = {'userkey': 'user123key'} test_post.return_value = mock_resp auth.log_in_for_userkey() test_post.assert_called_with(self.url, data=data, headers=headers)
def test_when_ask_for_password_check_if_continues_on_error( self, test_getpass, test_post, test_username): test_username.return_value = 'login123' settings.ACCOUNTKEY = None test_getpass.return_value = 'pass25word' mock_resp = Mock() mock_resp.json.side_effect = [{}, { 'userkey': 'user123key' }] # first time call - KeyError test_post.return_value = mock_resp auth.log_in_for_userkey() self.assertEqual(test_post.call_count, 2)