def _api_mollie_get_client(self): mollie_client = MollieClient() # TODO: [PGA] Add partical validation for keys e.g. production key should start from live_ if self.state == 'enabled': mollie_client.set_api_key(self.mollie_api_key_prod) elif self.state == 'test': mollie_client.set_api_key(self.mollie_api_key_test) mollie_client.set_user_agent_component('Odoo', service.common.exp_version()['server_version']) mollie_client.set_user_agent_component('MollieOdoo', self.env.ref('base.module_payment_mollie_official').installed_version) return mollie_client
def test_client_set_user_agent_component(response): """We should be able to add useragent components. Note: we don't use the fixture client because it is shared between tests, and we don't want it to be clobbered with random User-Agent strings. """ client = Client() assert 'Hoeba' not in client.user_agent client.set_user_agent_component('Hoeba', '1.0.0') assert 'Hoeba/1.0.0' in client.user_agent response.get('https://api.mollie.com/v2/methods', 'methods_list') client.set_api_key('test_123') client.methods.list() request = response.calls[0].request assert 'Hoeba/1.0.0' in request.headers['User-Agent']
def test_client_update_user_agent_component(): """We should be able to update the User-Agent component when using the same key.""" client = Client() client.set_user_agent_component('Test', '1.0.0') assert 'Test/1.0.0' in client.user_agent # now update the component using the same key client.set_user_agent_component('Test', '2.0.0') assert 'Test/2.0.0' in client.user_agent assert 'Test/1.0.0' not in client.user_agent # and update with a key that will be converted to the same value client.set_user_agent_component('TEST', '3.0.0') assert 'Test/3.0.0' in client.user_agent assert 'Test/2.0.0' not in client.user_agent assert 'Test/1.0.0' not in client.user_agent
def test_client_set_user_agent_component_correct_value_syntax(value, expected): """When we receive UA component values that don't adhere to the proposed syntax, they are corrected.""" client = Client() client.set_user_agent_component('Something', value) assert "Something/{expected}".format( expected=expected) in client.user_agent
def test_client_set_user_agent_component_correct_key_syntax(key, expected): """When we receive UA component keys that don't adhere to the proposed syntax, they are corrected.""" client = Client() client.set_user_agent_component(key, '1.0.0') assert "{expected}/1.0.0".format(expected=expected) in client.user_agent
def test_client_set_user_agent_component_correct_value_syntax(value, expected): """When we receive UA component values that don't adhere to the proposed syntax, they are corrected.""" client = Client() client.set_user_agent_component('Something', value) assert "Something/{expected}".format(expected=expected) in client.user_agent