def test_get_reference_data_server_error(self, m: Mocker) -> None: m.get( '{}/lovs'.format(API_URL_BASE), status_code=500, text='Internal Server Error.', ) client = FuelCheckClient() with self.assertRaises(FuelCheckError) as cm: client.get_reference_data() self.assertEqual(str(cm.exception), 'Internal Server Error.')
def test_get_reference_data_client_error(self, m: Mocker) -> None: m.get('{}/lovs'.format(API_URL_BASE), status_code=400, json={ "errorDetails": { "code": "-2146233033", "message": "String was not recognized as a valid DateTime." } }) client = FuelCheckClient() with self.assertRaises(FuelCheckError) as cm: client.get_reference_data() self.assertEqual(str(cm.exception), 'String was not recognized as a valid DateTime.')
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)
def test_get_reference_data(self, m: Mocker) -> None: fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures/lovs.json') with open(fixture_path) as fixture: m.get('{}/lovs'.format(API_URL_BASE), json=json.load(fixture)) client = FuelCheckClient() response = client.get_reference_data() self.assertEqual(len(response.brands), 2) self.assertEqual(len(response.fuel_types), 2) self.assertEqual(len(response.stations), 2) self.assertEqual(len(response.trend_periods), 2) self.assertEqual(len(response.sort_fields), 2) self.assertEqual(response.brands[0], 'Cool Fuel Brand') self.assertEqual(response.fuel_types[0].code, 'E10') self.assertEqual(response.fuel_types[0].name, 'Ethanol 94') self.assertEqual(response.stations[0].name, 'Cool Fuel Brand Hurstville') self.assertEqual(response.trend_periods[0].period, 'Day') self.assertEqual(response.trend_periods[0].description, 'Description for day') self.assertEqual(response.sort_fields[0].code, 'Sort 1') self.assertEqual(response.sort_fields[0].name, 'Sort field 1')