Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Dec 22, 2023
1 parent 805003b commit e841385
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 6 additions & 7 deletions pvconsumer/pv_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
from typing import List, Optional

import pandas as pd
import pvconsumer
from pvconsumer.solar_sheffield_passiv import get_all_systems_from_solar_sheffield
from pvconsumer.utils import pv_output, solar_sheffield_passiv
from pvoutput import PVOutput
from pvsite_datamodel.read import get_all_sites
from pvsite_datamodel.sqlmodels import GenerationSQL, SiteSQL
from sqlalchemy import func
from sqlalchemy.orm import Session

import pvconsumer
from pvconsumer.solar_sheffield_passiv import get_all_systems_from_solar_sheffield
from pvconsumer.utils import pv_output, solar_sheffield_passiv

# from pvconsumer.utils import df_to_list_pv_system, list_pv_system_to_df

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -146,7 +145,7 @@ def get_pv_systems(
pv_system.status_interval_minutes = int(metadata.status_interval_minutes)

elif provider == solar_sheffield_passiv:
pv_system = [s for s in pv_systems if s.pv_system_id == pv_system.pv_system_id][0]
pv_system = pv_systems[pv_systems["pv_system_id"] == pv_system.pv_system_id].iloc[0]
else:
raise Exception(f"Can not use provider {provider}")

Expand All @@ -156,8 +155,8 @@ def get_pv_systems(
max_ml_id = 0

site = SiteSQL(
client_site_id=pv_system.pv_system_id,
client_site_name=f"{provider}_pv_system.pv_system_name",
client_site_id=str(pv_system.pv_system_id),
client_site_name=f"{provider}_{pv_system.pv_system_id}",
latitude=pv_system.latitude,
longitude=pv_system.longitude,
capacity_kw=pv_system.capacity_kw,
Expand Down
2 changes: 1 addition & 1 deletion pvconsumer/solar_sheffield_passiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_all_systems_from_solar_sheffield(pv_system_ids: List[int] = None) -> pd.
data_df = raw_to_dataframe(response=response)

data_df.rename(columns={"system_id": "pv_system_id"}, inplace=True)
data_df.rename(columns={"kWp": "installed_capacity_kw"}, inplace=True)
data_df.rename(columns={"kWp": "capacity_kw"}, inplace=True)
data_df.rename(columns={"longitude_rounded": "longitude"}, inplace=True)
data_df.rename(columns={"latitude_rounded": "latitude"}, inplace=True)

Expand Down
16 changes: 16 additions & 0 deletions tests/intergration/test_ss_passiv.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
from datetime import datetime, timedelta, timezone

import pytest
from pvconsumer.pv_systems import get_pv_systems
from pvconsumer.solar_sheffield_passiv import (
get_all_latest_pv_yield_from_solar_sheffield,
get_all_systems_from_solar_sheffield,
)
from pvconsumer.utils import solar_sheffield_passiv


def test_get_pv_systems_ss(db_session, filename):
pv_systems = get_pv_systems(
session=db_session, filename=filename, provider=solar_sheffield_passiv
)

assert len(pv_systems) > 0


def test_test_get_pv_systems_error(db_session, filename):
with pytest.raises(Exception):
_ = get_pv_systems(session=db_session, filename=filename, provider="fake")


def test_get_all_systems():
Expand Down

0 comments on commit e841385

Please sign in to comment.