def test_authentication_sets_auth_token(self): with mock.patch('kazoo.client.ApiKeyAuthRequest') as mock_req_class: mock_req = mock.Mock() mock_req.execute.return_value = {"auth_token": "authorizethis"} mock_req_class.return_value = mock_req client = Client(api_key="dsfjasbfkasdf") client.authenticate() mock_req.execute.assert_called_with(client.BASE_URL) self.assertEqual(client.auth_token, "authorizethis")
def assert_invalid_constructor_args(self, **kwargs): with self.assertRaises(RuntimeError): client = Client(**kwargs)
def test_with_token_creates_api_key_auth_request(self): client = Client(api_key="fhasdlkjfblkasd") self.assertEqual(type(client.auth_request), ApiKeyAuthRequest)
def test_with_username_and_password_creates_user_auth_request(self): client = Client(account_name="user", password="******", username="******") self.assertEqual(type(client.auth_request), UsernamePasswordAuthRequest)
def test_with_valid_username_creds_does_not_raise(self): client = Client(account_name="user", password="******", username="******")
def test_with_api_key_does_not_raise(self): client = Client(api_key="sometoken")
def test_without_api_key_or_credentials_or_user_raises(self): with self.assertRaises(RuntimeError): client = Client()