def test_correct_client_is_associated_with_resources(self, mock_get_data): mock_get_data.return_value = {'id': 123} en_client = Client(api_language='en') de_client = Client(api_language='de') en_itin = en_client.itineraries.get(123) de_itin = de_client.itineraries.get(123) self.assertEqual(en_itin._client, en_client) self.assertEqual(de_itin._client, de_client)
def test_product_type_is_set_properly(self, mock_request): data = { 'products': [ { 'type': 'departures', 'sub_type': 'Tour', 'id': 1, } ], } promotion = Promotion(data, client=Client()) product = promotion.products[0] self.assertEqual(product.type, 'departures') self.assertEqual(product.to_dict(), { 'id': 1, 'type': 'departures', 'sub_type': 'Tour', }) # Ensure when the product implicitly fetched it makes a request, and # retains the type fields. self.assertEqual(mock_request.call_count, 0) mock_request.return_value = { 'finish_address': { 'country': { 'name': 'Australia', } } } self.assertEqual(product.finish_address.country.name, 'Australia') self.assertEqual(product.type, 'departures')
def test_retries_no_connection_pooling(self): """Should initialize the client's requestor with the passed number of retries.""" expected_retries = 42 client_with_retries = Client(max_retries=expected_retries) # Connection pooling defaults to https only https_retries = client_with_retries.requestor.adapters[ 'https://'].max_retries.total self.assertEqual(https_retries, expected_retries)
def test_query_key_with_language(self): self.client = Client(application_key='') self.client.api_language = 'de' query = Query(self.client, self.resource) key = query.query_key(1) expected = '{}:1:de'.format(self.resource_name) self.assertEqual(key, expected) # Unsetting the language should also remove it from the key self.client.api_language = None key = query.query_key(1) expected = '{}:1'.format(self.resource_name) self.assertEqual(key, expected)
def test_fetch_resource(self, resource, resource_id): # Test if a resource can be parsed properly. This is useful to catch # changes in the API api = Client() query = getattr(api, resource._resource_name) instance = query.get(resource_id) # Test that we take into account all of the fields of the json data # returned by the API (this only checks for the top-level fields, not # those of nested objects) self.assertEqual(sorted(instance._allowed_fields()), sorted(instance._raw_data.keys()))
def test_departure_addon_product_types(self): departure = Departure(DUMMY_DEPARTURE, client=Client()) for addon in departure.addons: # Product should use a resource class that matches with its type self.assertEqual(addon.product._resource_name, addon.product.type) # Each addon instance should have only one resource class listed # for it's "product" field product_resource_fields = [ (field, resource_class) for (field, resource_class) in addon._resource_fields if field == 'product'] self.assertEqual(len(product_resource_fields), 1)
def test_query_key_with_underscore_live(self): client = Client(application_key='live_abs') output = client.tour_dossiers.query_key(123) expected = 'tour_dossiers:123' self.assertEqual(output, expected)
def test_query_key_with_no_underscore(self): client = Client(application_key='somestringnounderscore') output = client.tour_dossiers.query_key(123) expected = 'tour_dossiers:123' self.assertEqual(output, expected)
def setUp(self): self.client = Client()
def test_query_key_test(self): client = Client(application_key='test') output = client.tour_dossiers.query_key(123) expected = 'tour_dossiers:123' self.assertEqual(output, expected)
def setUp(self): self.client = Client(cache_backend='gapipy.cache.SimpleCache') self.cache = self.client._cache self.cache.clear()
def setUpClass(cls): cls.tour = Client().tours.get(21715)
def setUp(self): self.client = Client() self.resources = Resources(_resource_name='resources', _uri=None)
def test_fake_amount_is_set_properly(self): departure = Departure(DUMMY_DEPARTURE, client=Client()) prices = departure.rooms[0].price_bands[0].prices for price in prices: promotion = price.promotions[0].to_dict() self.assertTrue('amount' in promotion)
def setUpClass(cls): cls.dossier = Client().tour_dossiers.get(21715)
def test_query_key_with_env_with_language(self): self.client = Client(application_key='test_abcd') self.client.api_language = 'de' output = self.client.tour_dossiers.query_key(123) expected = 'tour_dossiers:123:de:test' self.assertEqual(output, expected)
def test_query_key_with_env_with_one_id(self): client = Client(application_key='test_abcd') output = client.tour_dossiers.query_key(1) expected = 'tour_dossiers:1:test' self.assertEqual(output, expected)
def setUp(self): self.client = Client() self.cache = self.client._cache self.cache.clear()
def setUp(self): self.gapi = Client()
def setUp(self): # Any ol' resource will do. self.client = Client(application_key='test_abcd') self.resource = get_available_resource_classes()[0] self.resource_name = self.resource._resource_name