-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create inverter accessing points #80
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things here, but overall very nice job.
pv_site_api/main.py
Outdated
assert client is not None | ||
|
||
async with httpx.AsyncClient() as httpxClient: | ||
headers = {"Enode-User-Id": client.client_uuid} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work getting this all up
tests/test_inverters.py
Outdated
# def test_get_inverters(db_session, client, forecast_values): | ||
# response = client.get(f"/sites/{site_uuid}/clearsky_estimate") | ||
# assert response.status_code == 200 | ||
|
||
# clearsky_estimate = ClearskyEstimate(**response.json()) | ||
# assert len(clearsky_estimate.clearsky_estimate) > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next, we'll want to uncomment this test (and change the endpoint in it). Here's the issue: your endpoints will end up trying to make a request to Enode, but we shouldn't do that in the test. Instead, you'll use https://pypi.org/project/pytest-httpx/
to have the Enode API requests get intercepted and swapped with fake data. Read the docs there for info, then add the library via poetry add -D pytest-httpx
. You'll first need to bump the version of httpx
in the pyproject.toml
to 0.24.0
.
Then, add this code to conftest.py
:
@pytest.fixture
def non_mocked_hosts() -> list:
return ["testserver"]
Then, in your tests, add httpx_mock
as a parameter (to the non fake ones) and use it to mock a Enode request:
httpx_mock.add_response(url="https://enode-api.production.enode.io/inverters")
To actually set the data in the mocked response, follow the docs for the library.
Co-authored-by: Andrew Lester <[email protected]>
Co-authored-by: Andrew Lester <[email protected]>
Co-authored-by: Andrew Lester <[email protected]>
Codecov Report
@@ Coverage Diff @@
## h4i/enode #80 +/- ##
=============================================
+ Coverage 84.82% 86.93% +2.11%
=============================================
Files 9 9
Lines 336 398 +62
=============================================
+ Hits 285 346 +61
- Misses 51 52 +1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
Pull Request
Description
Create the following endpoints:
/sites/<site_uuid>/inverters
/inverters
get_inverters_for_client
function to get the inverters.Fixes #71