Example #1
0
    def test_get_fuel_price_trends_server_error(self, m: Mocker) -> None:
        m.post(
            '{}/prices/trends/'.format(API_URL_BASE),
            status_code=500,
            text='Internal Server Error.',
        )
        client = FuelCheckClient()
        with self.assertRaises(FuelCheckError) as cm:
            client.get_fuel_price_trends(longitude=151.0,
                                         latitude=-33.0,
                                         fuel_types=['E10', 'P95'])

        self.assertEqual(str(cm.exception), 'Internal Server Error.')
Example #2
0
    def test_get_fuel_price_trends(self, m: Mocker) -> None:
        m.post('{}/prices/trends/'.format(API_URL_BASE),
               json={
                   'Variances': [
                       {
                           'Code': 'E10',
                           'Period': 'Day',
                           'Price': 150.0
                       },
                       {
                           'Code': 'E10',
                           'Period': 'Week',
                           'Price': 151.0
                       },
                       {
                           'Code': 'E10',
                           'Period': 'Month',
                           'Price': 152.0
                       },
                       {
                           'Code': 'E10',
                           'Period': 'Year',
                           'Price': 153.0
                       },
                       {
                           'Code': 'P95',
                           'Period': 'Day',
                           'Price': 150.0
                       },
                       {
                           'Code': 'P95',
                           'Period': 'Week',
                           'Price': 151.0
                       },
                       {
                           'Code': 'P95',
                           'Period': 'Month',
                           'Price': 152.0
                       },
                       {
                           'Code': 'P95',
                           'Period': 'Year',
                           'Price': 153.0
                       },
                   ],
                   'AveragePrices': [{
                       'Code': 'E10',
                       'Period': 'Day',
                       'Price': 150.0,
                       'Captured': '2018-06-02'
                   }, {
                       'Code': 'E10',
                       'Period': 'Year',
                       'Price': 151.0,
                       'Captured': 'October 2017'
                   }],
               })

        client = FuelCheckClient()
        result = client.get_fuel_price_trends(longitude=151.0,
                                              latitude=-33.0,
                                              fuel_types=['E10', 'P95'])

        self.assertEqual(len(result.variances), 8)
        self.assertEqual(result.variances[0].price, 150.0)
        self.assertEqual(result.variances[0].period, Period.DAY)
        self.assertEqual(result.variances[0].fuel_type, 'E10')

        self.assertEqual(len(result.average_prices), 2)
        self.assertEqual(result.average_prices[0].fuel_type, 'E10')
        self.assertEqual(result.average_prices[0].period, Period.DAY)
        self.assertEqual(result.average_prices[0].captured,
                         datetime.datetime(year=2018, month=6, day=2))
        self.assertEqual(result.average_prices[0].price, 150.0)

        self.assertEqual(result.average_prices[1].period, Period.YEAR)
        self.assertEqual(result.average_prices[1].captured,
                         datetime.datetime(year=2017, month=10, day=1))