Ejemplo n.º 1
0
def test_get_forecasts_404():
    """Test get_forecasts with 400 status code."""
    # Arrange
    api_key = '12345'
    resource_id = '1234-1234'
    endpoint = 'forecasts'
    period = 'PT30M'
    hours = '170'
    expected_url = f'{BASE_URL}/{UTILTY_URI}/{resource_id}/{endpoint}'

    responses.add(responses.GET, expected_url, status=404)

    # Act
    site = UtilitySite(api_key, resource_id)
    with pytest.raises(SiteError):
        site.get_forecasts(period, hours)
Ejemplo n.º 2
0
def test_get_forecasts_429():
    """Test get_forecasts with 429 status code."""
    # Arrange
    api_key = '12345'
    resource_id = '1234-1234'
    endpoint = 'forecasts'
    period = 'PT30M'
    hours = '170'
    expected_url = f'{BASE_URL}/{UTILTY_URI}/{resource_id}/{endpoint}'
    headers = {'x-rate-limit-reset': '155555555'}

    responses.add(responses.GET,
                  expected_url,
                  status=429,
                  adding_headers=headers)

    # Act
    site = UtilitySite(api_key, resource_id)
    with pytest.raises(RateLimitExceeded):
        site.get_forecasts(period, hours)
Ejemplo n.º 3
0
def test_get_forecasts_200():
    """Test get_forecasts with 200 status code."""
    # Arrange
    api_key = '12345'
    resource_id = '1234-1234'
    endpoint = 'forecasts'
    period = 'PT30M'
    hours = '170'
    expected_url = f'{BASE_URL}/{UTILTY_URI}/{resource_id}/{endpoint}'

    forecast_response = {
        "forecasts": [{
            "pv_estimate": "9.5",
            "pv_estimate10": "6",
            "pv_estimate90": "13.8",
            "period_end": "2018-01-01T01:00:00.00000Z",
            "period": "PT30M"
        }, {
            "pv_estimate": "10",
            "pv_estimate10": "8",
            "pv_estimate90": "12",
            "period_end": "2018-01-01T12:30:00.00000Z",
            "period": "PT30M"
        }]
    }

    responses.add(responses.GET,
                  expected_url,
                  json=forecast_response,
                  status=200,
                  content_type='applicaiton/json')

    # Act
    site = UtilitySite(api_key, resource_id)
    forecasts = site.get_forecasts(period, hours)

    # Assert
    assert isinstance(forecasts, dict)
    assert len(forecasts['forecasts']) == 2