Skip to content

Commit

Permalink
Add some tests for other states
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewLester committed Apr 24, 2023
1 parent 4664aaa commit e524772
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_inverters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
enode_api_base_url = os.getenv("ENODE_API_BASE_URL", "https://enode-api.sandbox.enode.io")


def test_post_inverters_for_site_fake(client, sites, fake):
test_inverter_client_id = "6c078ca2-2e75-40c8-9a7f-288bd0b70065"
json = [test_inverter_client_id]
response = client.post(f"/sites/{sites[0].site_uuid}/inverters", json=json)

assert response.status_code == 200


def test_post_inverters_for_site(client, sites, httpx_mock):
test_inverter_client_id = "6c078ca2-2e75-40c8-9a7f-288bd0b70065"
json = [test_inverter_client_id]
Expand All @@ -19,6 +27,11 @@ def test_post_inverters_for_site(client, sites, httpx_mock):
assert response.json()["inverters"][0]["id"] == test_inverter_client_id


def test_get_inverters_for_site_fake(client, sites, inverters, fake):
response = client.get(f"/sites/{sites[0].site_uuid}/inverters")
assert response.status_code == 200


def test_get_inverters_for_site(client, sites, inverters, httpx_mock):
mock_inverter_response("id1", httpx_mock)
mock_inverter_response("id2", httpx_mock)
Expand All @@ -31,6 +44,12 @@ def test_get_inverters_for_site(client, sites, inverters, httpx_mock):
assert len(inverters) == len(response_inverters.inverters)


def test_get_inverters_for_nonexistant_site(client, sites, inverters, httpx_mock):
nonexistant_site_uuid = "1cd11139-790a-46c0-8849-0c7c8e810ba5"
response = client.get(f"/sites/{nonexistant_site_uuid}/inverters")
assert response.status_code == 404


def test_get_enode_inverters_fake(client, fake):
response = client.get("/enode/inverters")
assert response.status_code == 200
Expand Down
48 changes: 48 additions & 0 deletions tests/test_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ def test_post_site(db_session, client, clients):
assert sites[0].site_uuid is not None


def test_update_site_fake(fake, sites, client, clients):
pv_site = PVSiteMetadata(
client_name="test_client_1",
client_uuid="eeee-eeee",
client_site_id=34,
client_site_name="the site name",
region="the site's region",
dno="the site's dno",
gsp="the site's gsp",
orientation=180,
tilt=90,
latitude=50,
longitude=0,
installed_capacity_kw=1,
created_utc=datetime.now(timezone.utc).isoformat(),
)

pv_site_dict = json.loads(pv_site.json())

site_uuid = sites[0].site_uuid
response = client.put(f"/sites/{site_uuid}", json=pv_site_dict)
assert response.status_code == 200, response.text


def test_post_site_and_update(db_session, client, clients):
pv_site = PVSiteMetadata(
client_name="test_client_1",
Expand Down Expand Up @@ -108,3 +132,27 @@ def test_post_site_and_update(db_session, client, clients):
sites = db_session.query(SiteSQL).all()
assert sites[0].orientation == pv_site.orientation
assert sites[0].tilt == pv_site.tilt


def test_update_nonexistant_site(sites, client, clients):
pv_site = PVSiteMetadata(
client_name="test_client_1",
client_uuid="eeee-eeee",
client_site_id=34,
client_site_name="the site name",
region="the site's region",
dno="the site's dno",
gsp="the site's gsp",
orientation=180,
tilt=90,
latitude=50,
longitude=0,
installed_capacity_kw=1,
created_utc=datetime.now(timezone.utc).isoformat(),
)

pv_site_dict = json.loads(pv_site.json())

nonexistant_site_uuid = "1cd11139-790a-46c0-8849-0c7c8e810ba5"
response = client.put(f"/sites/{nonexistant_site_uuid}", json=pv_site_dict)
assert response.status_code == 404

0 comments on commit e524772

Please sign in to comment.