def setup_method(self, method): # TODO: To run against real server please delete ../fixtures/vcr_cassettes/* and replace # login_id and api_key with valid credentials before running the tests login_id = '*****@*****.**' api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' environment = Config.ENV_DEMO self.client = Client(login_id, api_key, environment)
def test_error_is_raised_on_incorrect_authentication_details(self): login_id = 'non-existent-login-id' api_key = 'efb5ae2af84978b7a37f18dd61c8bbe139b403009faea83484405a3dcb64c4d8' tmp_client = Client(login_id, api_key, Config.ENV_DEMONSTRATION) with Betamax(tmp_client.config.session) as betamax: betamax.use_cassette( 'errors/is_raised_on_incorrect_authentication_details') error = None try: tmp_client.auth.authenticate() raise Exception("Should have failed") except AuthenticationError as e: error = e assert error.code == 'auth_failed' assert error.raw_response is not None assert error.status_code == 401 assert len(error.messages) == 1 error_message = error.messages[0] assert error_message.field == 'username' assert error_message.code == 'invalid_supplied_credentials' assert error_message.message == 'Authentication failed with the supplied credentials' # noqa assert not error_message.params
def test_error_contains_full_details_for_api_error(self): login_id = 'non-existent-login-id' api_key = 'ef0fd50fca1fb14c1fab3a8436b9ecb57528f0' tmp_client = Client(login_id, api_key, Config.ENV_DEMONSTRATION) with Betamax(tmp_client.config.session) as betamax: betamax.use_cassette('errors/contains_full_details_for_api_error') error = None try: tmp_client.auth.authenticate() raise Exception("Should have failed") except BadRequestError as e: error = e assert error is not None expected_error_fields = [ "login_id: non-existent-login-id", "api_key: " + api_key, "verb: post", "url: https://devapi.thecurrencycloud.com/v2/authenticate/api", "status_code: 400", "date:", "request_id:", "field: api_key", "code: api_key_length_is_invalid", "message: api_key should be 64 character(s) long", "length: 64" ] error_str = str(error) missing = False for f in expected_error_fields: if f not in error_str: missing = True break assert missing is False
def test_authentication_can_reuse_an_auth_token(self): special_client = Client(None, None, Config.ENV_DEMONSTRATION) special_client.config.auth_token = self.client.config.auth_token with Betamax(special_client.config.session) as betamax: betamax.use_cassette('authentication/can_use_just_a_token') response = special_client.beneficiaries.find() assert response is not None
def setup_method(self, method): login_id = '*****@*****.**' api_key = 'ef0fd50fca1fb14c1fab3a8436b9ecb65f02f129fd87eafa45ded8ae257528f0' environment = Config.ENV_DEMONSTRATION self.client = Client(login_id, api_key, environment) self.params = { 'buy_currency': 'GBP', 'sell_currency': 'USD', 'fixed_side': 'buy', 'amount': 1000, 'reason': 'mortgage payment', 'term_agreement': 'true' }
def setup_method(self, method): # TODO: To run against real server please delete ../fixtures/vcr_cassettes/* and replace # login_id and api_key with valid credentials before running the tests login_id = '*****@*****.**' api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' environment = Config.ENV_DEMO self.client = Client(login_id, api_key, environment) self.params = { 'buy_currency': 'GBP', 'sell_currency': 'USD', 'fixed_side': 'buy', 'amount': 1000, 'reason': 'mortgage payment', 'term_agreement': 'true' }
class TestAuthentication: def setup_method(self, method): # TODO: To run against real server please delete ../fixtures/vcr_cassettes/* and replace # login_id and api_key with valid credentials before running the tests login_id = '*****@*****.**' api_key = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' environment = Config.ENV_DEMO self.client = Client(login_id, api_key, environment) def test_authentication_happens_lazily(self): with Betamax(self.client.config.session) as betamax: betamax.use_cassette('authentication/happens_lazily') assert self.client.config._auth_token is None assert self.client.config.auth_token is not None def test_authentication_can_reuse_an_auth_token(self): special_client = Client(None, None, Config.ENV_DEMO) special_client.config.auth_token = "deadbeefdeadbeefdeadbeefdeadbeef" with Betamax(special_client.config.session) as betamax: betamax.use_cassette('authentication/can_use_just_a_token') response = special_client.beneficiaries.find() assert response is not None def test_authentication_can_be_closed(self): with Betamax(self.client.config.session) as betamax: betamax.use_cassette('authentication/can_be_closed') assert self.client.config.auth_token is not None assert self.client.close_session() is True assert self.client.config._auth_token is None def test_authentication_handles_session_timeout(self): # Set the token to an invalid one self.client.config.auth_token = 'deadbeefdeadbeefdeadbeefdeadbeef' with Betamax(self.client.config.session) as betamax: betamax.use_cassette('authentication/handles_session_timeout', match_requests_on=['uri', 'method']) response = self.client.beneficiaries.find() assert response is not None
class TestAuthentication: def setup_method(self, method): login_id = '*****@*****.**' api_key = 'ef0fd50fca1fb14c1fab3a8436b9ecb65f02f129fd87eafa45ded8ae257528f0' environment = Config.ENV_DEMONSTRATION self.client = Client(login_id, api_key, environment) def test_authentication_happens_lazily(self): with Betamax(self.client.config.session) as betamax: betamax.use_cassette('authentication/happens_lazily') assert self.client.config._auth_token is None assert self.client.config.auth_token is not None def test_authentication_can_reuse_an_auth_token(self): special_client = Client(None, None, Config.ENV_DEMONSTRATION) special_client.config.auth_token = self.client.config.auth_token with Betamax(special_client.config.session) as betamax: betamax.use_cassette('authentication/can_use_just_a_token') response = special_client.beneficiaries.find() assert response is not None def test_authentication_can_be_closed(self): with Betamax(self.client.config.session) as betamax: betamax.use_cassette('authentication/can_be_closed') assert self.client.config.auth_token is not None assert self.client.close_session() is True assert self.client.config._auth_token is None def test_authentication_handles_session_timeout(self): # Set the token to an invalid one self.client.config.auth_token = '1234abcd1234abcd1234abcd1234abcd' with Betamax(self.client.config.session) as betamax: betamax.use_cassette('authentication/handles_session_timeout', match_requests_on=['uri', 'method']) response = self.client.beneficiaries.find() assert response is not None
def setup_method(self, method): login_id = '*****@*****.**' api_key = '0a14256abc393cdc238672b2d42d54f5581937f3ee23b76d5cfa842f63f8364d' environment = Config.ENV_DEMONSTRATION self.client = Client(login_id, api_key, environment)
def setup_method(self, method): login_id = '*****@*****.**' api_key = 'ef0fd50fca1fb14c1fab3a8436b9ecb65f02f129fd87eafa45ded8ae257528f0' environment = Config.ENV_DEMONSTRATION self.client = Client(login_id, api_key, environment)