Beispiel #1
0
    def test_get_fuel_prices_within_radius_server_error(self,
                                                        m: Mocker) -> None:
        m.post(
            '{}/prices/nearby'.format(API_URL_BASE),
            status_code=500,
            text='Internal Server Error.',
        )
        client = FuelCheckClient()
        with self.assertRaises(FuelCheckError) as cm:
            client.get_fuel_prices_within_radius(
                longitude=151.0,
                latitude=-33.0,
                radius=10,
                fuel_type='E10',
            )

        self.assertEqual(str(cm.exception), 'Internal Server Error.')
Beispiel #2
0
    def test_get_fuel_prices_within_radius(self, m: Mocker) -> None:
        m.post('{}/prices/nearby'.format(API_URL_BASE),
               json={
                   'stations': [
                       {
                           'stationid': 'SAAAAAA',
                           'brandid': 'BAAAAAA',
                           'brand': 'Cool Fuel Brand',
                           'code': 678,
                           'name': 'Cool Fuel Brand Luxembourg',
                           'address': '123 Fake Street',
                           'location': {},
                       },
                       {
                           'stationid': 'SAAAAAB',
                           'brandid': 'BAAAAAB',
                           'brand': 'Fake Fuel Brand',
                           'code': 679,
                           'name': 'Fake Fuel Brand Luxembourg',
                           'address': '123 Fake Street',
                           'location': {},
                       },
                       {
                           'stationid': 'SAAAAAB',
                           'brandid': 'BAAAAAB',
                           'brand': 'Fake Fuel Brand2',
                           'code': 880,
                           'name': 'Fake Fuel Brand2 Luxembourg',
                           'address': '123 Fake Street',
                           'location': {},
                       },
                   ],
                   'prices': [{
                       'stationcode': 678,
                       'fueltype': 'P95',
                       'price': 150.9,
                       'priceunit': 'litre',
                       'description': None,
                       'lastupdated': '2018-06-02 00:46:31'
                   }, {
                       'stationcode': 678,
                       'fueltype': 'P95',
                       'price': 130.9,
                       'priceunit': 'litre',
                       'description': None,
                       'lastupdated': '2018-06-02 00:46:31'
                   }, {
                       'stationcode': 880,
                       'fueltype': 'P95',
                       'price': 155.9,
                       'priceunit': 'litre',
                       'description': None,
                       'lastupdated': '2018-06-02 00:46:31'
                   }],
               })

        client = FuelCheckClient()
        result = client.get_fuel_prices_within_radius(
            longitude=151.0,
            latitude=-33.0,
            radius=10,
            fuel_type='E10',
        )
        self.assertEqual(len(result), 3)
        self.assertEqual(result[0].station.code, 678)
        self.assertEqual(result[0].price.price, 150.9)