def test_get_fuel_prices_for_station_server_error(self, m: Mocker) -> None: m.get( '{}/prices/station/21199'.format(API_URL_BASE), status_code=500, text='Internal Server Error.', ) client = FuelCheckClient() with self.assertRaises(FuelCheckError) as cm: client.get_fuel_prices_for_station(21199) self.assertEqual(str(cm.exception), 'Internal Server Error.')
def test_get_fuel_prices_for_station(self, m: Mocker) -> None: m.get('{}/prices/station/100'.format(API_URL_BASE), json={ 'prices': [{ 'fueltype': 'E10', 'price': 146.9, 'lastupdated': '02/06/2018 02:03:04', }, { 'fueltype': 'P95', 'price': 150.0, 'lastupdated': '02/06/2018 02:03:04', }] }) client = FuelCheckClient() result = client.get_fuel_prices_for_station(100) self.assertEqual(len(result), 2) self.assertEqual(result[0].fuel_type, 'E10') self.assertEqual(result[0].price, 146.9) self.assertEqual( result[0].last_updated, datetime.datetime( day=2, month=6, year=2018, hour=2, minute=3, second=4, ))
def test_get_fuel_prices_for_station_client_error(self, m: Mocker) -> None: m.get('{}/prices/station/21199'.format(API_URL_BASE), status_code=400, json={ "errorDetails": [{ "code": "E0014", "description": "Invalid service station code \"21199\"" }] }) client = FuelCheckClient() with self.assertRaises(FuelCheckError) as cm: client.get_fuel_prices_for_station(21199) self.assertEqual(str(cm.exception), 'Invalid service station code "21199"')
class FuelCheckClientIntegrationTest(unittest.TestCase): def setUp(self): self.client = FuelCheckClient() def test_get_reference_data(self) -> None: response = self.client.get_reference_data() self.assertGreater(len(response.stations), 1500) def test_get_fuel_prices(self) -> None: response = self.client.get_fuel_prices() self.assertGreater(len(response.stations), 1500) self.assertGreater(len(response.prices), 1500) def test_get_fuel_prices_for_station(self) -> None: response = self.client.get_reference_data() station_id = response.stations[0].code response = self.client.get_fuel_prices_for_station(station_id) self.assertGreaterEqual(len(response), 1)