Skip to content

Commit

Permalink
Minor change to mock method on real class
Browse files Browse the repository at this point in the history
  • Loading branch information
braddf committed Aug 13, 2024
1 parent ceadff6 commit 9afb2f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
5 changes: 1 addition & 4 deletions src/national.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
# Initialize Elexon API client
api_client = ApiClient()
elexon_forecast_api = GenerationForecastApi(api_client)
elexon_forecast_generation_wind_and_solar_day_ahead_get = (
elexon_forecast_api.forecast_generation_wind_and_solar_day_ahead_get
)


@router.get(
Expand Down Expand Up @@ -238,7 +235,7 @@ def get_elexon_forecast(
"""

try:
response = elexon_forecast_generation_wind_and_solar_day_ahead_get(
response = elexon_forecast_api.forecast_generation_wind_and_solar_day_ahead_get(
_from=start_datetime_utc.isoformat(),
to=end_datetime_utc.isoformat(),
process_type=process_type,
Expand Down
24 changes: 12 additions & 12 deletions src/tests/test_elexon_forecast.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from typing import Optional
from unittest.mock import patch
from unittest.mock import MagicMock, patch

import pandas as pd
import pytest
from elexonpy.api.generation_forecast_api import GenerationForecastApi

from pydantic_models import BaseModel, SolarForecastResponse

API_URL = "/v0/solar/GB/national/elexon"

class MockClass(BaseModel):

class MockClass(BaseModel):
start_time: str
quantity: float
business_type: Optional[str] = "Solar generation"
Expand All @@ -31,18 +33,17 @@ def to_dict(self):
}
),
]
mock_response = MagicMock()
mock_response.data = mock_data


class MockResponse:
def __init__(self):
self.data = mock_data


@patch("national.elexon_forecast_generation_wind_and_solar_day_ahead_get")
@patch.object(GenerationForecastApi, "forecast_generation_wind_and_solar_day_ahead_get")
def test_get_elexon_forecast_mock(mock_function, api_client):
mock_function.return_value = MockResponse()
# Set mock_response
mock_function.return_value = mock_response

response = api_client.get("/v0/solar/GB/national/elexon")
# Call the API endpoint
response = api_client.get(API_URL)
print("Response Headers:", response.headers)
# Assertions
assert response.status_code == 200
Expand All @@ -57,8 +58,7 @@ def test_get_elexon_forecast_mock(mock_function, api_client):

@pytest.mark.integration
def test_get_elexon_forecast(api_client):

response = api_client.get("/v0/solar/GB/national/elexon")
response = api_client.get(API_URL)

# Assertions
assert response.status_code == 200
Expand Down

0 comments on commit 9afb2f1

Please sign in to comment.