Example #1
0
def test_get_grid_supply_point(api: OctoAPI):

    assert api.get_grid_supply_point("SW1A 1AA") == Region.London
    assert api.get_grid_supply_point("SW1A1AA") == Region.London

    with pytest.raises(ValueError,
                       match="Cannot map the postcode '12345' to a GSP."):
        api.get_grid_supply_point("12345")
Example #2
0
def test_get_tariff_charges(api: OctoAPI):
	charges = api.get_tariff_charges(
			product_code="VAR-17-01-11",
			tariff_code="E-1R-VAR-17-01-11-A",
			fuel="electricity",
			rate_type=RateType.StandardUnitRate,
			)
	assert len(charges) == 6
	expected = [
			RateInfo(
					value_exc_vat=15.51,
					value_inc_vat=16.2855,
					valid_from="2020-11-01T00:00:00Z",
					valid_to=None,
					),
			RateInfo(
					value_exc_vat=14.78,
					value_inc_vat=15.519,
					valid_from="2020-01-15T00:00:00Z",
					valid_to="2020-11-01T00:00:00Z",
					),
			RateInfo(
					value_exc_vat=15.07,
					value_inc_vat=15.8235,
					valid_from="2019-04-30T23:00:00Z",
					valid_to="2020-01-15T00:00:00Z",
					),
			RateInfo(
					value_exc_vat=15.62,
					value_inc_vat=16.401,
					valid_from="2018-11-20T00:00:00Z",
					valid_to="2019-04-30T23:00:00Z",
					),
			RateInfo(
					value_exc_vat=13.94,
					value_inc_vat=14.637,
					valid_from="2018-08-05T23:00:00Z",
					valid_to="2018-11-20T00:00:00Z",
					),
			RateInfo(
					value_exc_vat=12.34,
					value_inc_vat=12.957,
					valid_from="2017-01-11T10:00:00Z",
					valid_to="2018-08-05T23:00:00Z",
					),
			]
	assert list(charges) == expected
	assert charges == expected

	with pytest.raises(ValueError, match="'page_size' may not be greater than 1,500"):
		api.get_tariff_charges(
				product_code="VAR-17-01-11",
				tariff_code="E-1R-VAR-17-01-11-A",
				fuel="electricity",
				rate_type=RateType.StandardUnitRate,
				page_size=2000,
				)
Example #3
0
def test_get_meter_point_details(api: OctoAPI):

    assert api.get_meter_point_details("2000024512368") == MeterPointDetails(
        mpan="2000024512368",
        gsp=Region.Southern,
        profile_class=1,
    )

    assert isinstance(api.get_meter_point_details("2000024512368"),
                      MeterPointDetails)
Example #4
0
def test_get_products(api: OctoAPI):
	assert isinstance(api.get_products(), PaginatedResponse)
	assert api.get_products()[0] == Product(
			code="1201",
			direction="IMPORT",
			full_name="Affect Standard Tariff",
			display_name="Affect Standard Tariff",
			description="Affect Standard Tariff",
			is_variable=True,
			is_green=False,
			is_tracker=False,
			is_prepay=False,
			is_business=False,
			is_restricted=False,
			term=None,
			available_from="2016-01-01T00:00:00Z",
			available_to=None,
			brand="AFFECT_ENERGY",
			links=[{
					"href": "https://api.octopus.energy/v1/products/1201/",
					"rel": "self",
					"method": "GET",
					}]
			)

	assert api.get_products(is_green=True)[0] == Product(
			code="AGILE-18-02-21",
			direction="IMPORT",
			full_name="Agile Octopus February 2018",
			display_name="Agile Octopus",
			description='',
			is_variable=True,
			is_green=True,
			is_tracker=False,
			is_prepay=False,
			is_business=False,
			is_restricted=False,
			term=12,
			available_from="2017-01-01T00:00:00Z",
			available_to=None,
			brand="OCTOPUS_ENERGY",
			links=[{
					"href": "https://api.octopus.energy/v1/products/AGILE-18-02-21/",
					"rel": "self",
					"method": "GET",
					}]
			)

	assert not api.get_products(is_tracker=True)
	assert not api.get_products(is_prepay=True, is_variable=False)
Example #5
0
def test_get_consumption(api: OctoAPI):
    consumption = api.get_consumption(
        mpan="2000024512368",
        serial_number="-------------",
        fuel="electricity",
    )

    assert isinstance(consumption, PaginatedResponse)
    assert len(consumption) == 2496
    assert consumption[0] == Consumption(
        consumption=0.313,
        interval_start="2020-10-03T00:00:00+01:00",
        interval_end="2020-10-03T00:30:00+01:00",
    )
    assert consumption[115] == Consumption(
        consumption=0.409,
        interval_start="2020-09-30T14:30:00+01:00",
        interval_end="2020-09-30T15:00:00+01:00",
    )

    assert consumption[115:116] == [
        Consumption(
            consumption=0.409,
            interval_start="2020-09-30T14:30:00+01:00",
            interval_end="2020-09-30T15:00:00+01:00",
        ),
        Consumption(
            consumption=0.421,
            interval_start="2020-09-30T14:00:00+01:00",
            interval_end="2020-09-30T14:30:00+01:00",
        ),
    ]

    with pytest.raises(IndexError, match="index out of range"):
        consumption[2496]

    with pytest.raises(IndexError, match="index out of range"):
        consumption[2497]

    with pytest.raises(ValueError,
                       match="'page_size' may not be greater than 25,000"):
        api.get_consumption(mpan="2000024512368",
                            serial_number="-------------",
                            fuel="electricity",
                            page_size=10000000)
Example #6
0
def test_get_agile_tariff_charges(api: OctoAPI):
	charges = api.get_tariff_charges(
			product_code="AGILE-18-02-21",
			tariff_code="E-1R-AGILE-18-02-21-C",
			fuel="electricity",
			rate_type=RateType.StandardUnitRate,
			)

	assert len(charges) == 65611
	assert len(charges._results) == 100
	assert charges[100] == RateInfo(
			value_exc_vat=9.76,
			value_inc_vat=10.248,
			valid_from=datetime(2020, 9, 26, 19, 30, tzinfo=timezone.utc),
			valid_to=datetime(2020, 9, 26, 20, 0, tzinfo=timezone.utc),
			)
	assert len(charges._results) == 200
Example #7
0
def test_get_consumption_grouping(api: OctoAPI):
    consumption = api.get_consumption(mpan="2000024512368",
                                      serial_number="-------------",
                                      fuel="electricity",
                                      group_by="week")

    assert len(consumption) == 8

    assert consumption[0] == Consumption(
        consumption=114.734,
        interval_start="2020-09-28T00:00:00+01:00",
        interval_end="2020-10-03T00:30:00+01:00",
    )
    assert consumption[5] == Consumption(
        consumption=185.26,
        interval_start="2020-08-24T00:00:00+01:00",
        interval_end="2020-08-31T00:00:00+01:00",
    )
Example #8
0
def test_get_consumption_for_period(api: OctoAPI):
    consumption = api.get_consumption(
        mpan="2000024512368",
        serial_number="-------------",
        fuel="electricity",
        period_from=datetime.datetime(2020, 8, 3, 0, 0, 0, tzinfo=bst),
        period_to=datetime.datetime(2020, 9, 3, 0, 0, 0, tzinfo=bst),
    )

    assert isinstance(consumption, PaginatedResponse)
    assert len(consumption) == 1058
    assert consumption[0] == Consumption(
        consumption=0.263,
        interval_start="2020-09-03T01:00:00+01:00",
        interval_end="2020-09-03T01:30:00+01:00",
    )
    assert consumption[30] == Consumption(
        consumption=0.418,
        interval_start="2020-09-02T10:00:00+01:00",
        interval_end="2020-09-02T10:30:00+01:00",
    )
Example #9
0
def test_get_consumption_reverse(api: OctoAPI):
    consumption = api.get_consumption(mpan="2000024512368",
                                      serial_number="-------------",
                                      fuel="electricity",
                                      reverse=True)

    assert len(consumption) == 2496

    for idx, val in enumerate(consumption):
        if idx == 117:
            break

    assert consumption[0] == Consumption(
        consumption=0,
        interval_start="2020-08-12T00:30:00+01:00",
        interval_end="2020-08-12T01:00:00+01:00",
    )
    assert consumption[115] == Consumption(
        consumption=0.295,
        interval_start="2020-08-14T10:00:00+01:00",
        interval_end="2020-08-14T10:30:00+01:00",
    )