Skip to content

Add put endpoint for editing site #88

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

Merged
merged 94 commits into from
Apr 23, 2023
Merged

Conversation

ericcccsliu
Copy link
Collaborator

@ericcccsliu ericcccsliu commented Apr 22, 2023

Pull Request

Adds PUT endpoint for editing site details!

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
Please also list any relevant details for your test configuration

  • wrote tests!

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

peterdudfield and others added 30 commits March 24, 2023 21:04
This doesn't change the result but speeds up the query in general.
Add WHERE statement on query for past forecasts
Make site_uuid field on PVSiteMetadata model optional
@ericcccsliu ericcccsliu marked this pull request as draft April 22, 2023 18:06
@codecov
Copy link

codecov bot commented Apr 23, 2023

Codecov Report

Merging #88 (9ed54b5) into h4i/enode (a4fb461) will increase coverage by 2.24%.
The diff coverage is 95.09%.

@@              Coverage Diff              @@
##           h4i/enode      #88      +/-   ##
=============================================
+ Coverage      87.31%   89.56%   +2.24%     
=============================================
  Files              9       11       +2     
  Lines            410      527     +117     
=============================================
+ Hits             358      472     +114     
- Misses            52       55       +3     
Impacted Files Coverage Δ
pv_site_api/session.py 37.50% <0.00%> (ø)
pv_site_api/auth.py 90.47% <90.47%> (ø)
pv_site_api/main.py 92.23% <94.80%> (+1.68%) ⬆️
pv_site_api/cache.py 97.14% <97.14%> (ø)
pv_site_api/__init__.py 100.00% <100.00%> (ø)
pv_site_api/_db_helpers.py 100.00% <100.00%> (ø)
pv_site_api/pydantic_models.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@AndrewLester AndrewLester changed the base branch from main to h4i/enode April 23, 2023 17:32
@ericcccsliu ericcccsliu marked this pull request as ready for review April 23, 2023 19:46
@@ -26,7 +25,6 @@ def test_get_site_list(client, sites):

def test_put_site_fake(client, fake):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't part of your stuff, but for consistency, rename to test_post_site_fake?

if site is None:
raise HTTPException(status_code=404, detail="Site not found")

# update site information
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# update site information

site.longitude = site_info.longitude
site.capacity_kw = site_info.installed_capacity_kw

# commit changes to database
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# commit changes to database

client = session.query(ClientSQL).first()
assert client is not None

# get the site to update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# get the site to update

@ericcccsliu ericcccsliu merged commit a058e32 into h4i/enode Apr 23, 2023
@ericcccsliu ericcccsliu deleted the el/add-post-endpoint branch April 23, 2023 20:10
@ericcccsliu ericcccsliu changed the title [WIP] Add put endpoint for editing site Add put endpoint for editing site Apr 23, 2023
AndrewLester added a commit that referenced this pull request Apr 23, 2023
* Bump version: 0.0.36 → 0.0.37

* TDD: add failing test, looking at forecasts in the future

* add start utc filter on forecast future qery

* lint

* lint

* isort

* add freeze gun to dev dependencies

* self PR comments

* Bump version: 0.0.37 → 0.0.38

* Make site_uuid field on PVSiteMetadata model optional

* Make pydantic field optional

* Move test site with real UUID to real db test

* Don't use uuid in tests

* Add part of check back

* Ensure autogenerated site uuid is not null in database

* Add WHERE statement on query for past forecasts

This doesn't change the result but speeds up the query in general.

* Bump version: 0.0.38 → 0.0.39

* Bump version: 0.0.39 → 0.0.40

* add logging

* lint

* run blacks

* add extra logs

* Bump version: 0.0.40 → 0.0.41

* add structlogging

* add structlog to requiremwnts

* add logging

* Bump version: 0.0.41 → 0.0.42

* Add structlog initialisation

* blacks

* isort

* Bump version: 0.0.42 → 0.0.43

* Uniformize check to FAKE and fix related test

* Set codecov targets

* Hard-code the "now" time for all tests

This means that the same tests are run now matter the time at which we
run them.

* add caching

* fix

* lint

* isort

* fix for routes calling routes

* lint

* Bump version: 0.0.43 → 0.0.44

* PR comment

* add args to cache

* lint

* Update pv_site_api/cache.py

Co-authored-by: Simon Lemieux <1105380+simlmx@users.noreply.github.com>

* tidy

* Bump version: 0.0.44 → 0.0.45

* What I've got

* Add basic authorization to the /sites* routes

The caller of the routes must have a proper Bearer authorization
header set.

* refactor

* add tests

* fix error in import

* update pvsite-datamodel (in line with main)

* fix bug

* fix incompatible types

* lint and format

* add site existence check

* add back correct datamodel dependency

* fix test name

* allow tests to pass by adding fake condition

* remove 404 check

* use or instead of is not none

* Bump version: 0.0.45 → 0.0.46

* add site existence check

* format and lint

* Bump version: 0.0.46 → 0.0.47

* add post endpoint

* add test back in

* fix errors and format

* add site name to test

* fix tiny error

* fix another small error

* run tests

* fix bugs

* lint and format

* fix fake

* :pleading-face:

* yet another is_fake() addition

* address comments

---------

Co-authored-by: Peter Dudfield <34686298+peterdudfield@users.noreply.github.com>
Co-authored-by: BumpVersion Action <bumpversion@github-actions>
Co-authored-by: peterdudfield <peter.dudfield@hotmail.com>
Co-authored-by: AndrewLester <alester220@gmail.com>
Co-authored-by: Simon Lemieux <1105380+simlmx@users.noreply.github.com>
Co-authored-by: devsjc <sol@openclimatefix.org>
AndrewLester pushed a commit that referenced this pull request Apr 24, 2023
* Bump version: 0.0.36 → 0.0.37

* TDD: add failing test, looking at forecasts in the future

* add start utc filter on forecast future qery

* lint

* lint

* isort

* add freeze gun to dev dependencies

* self PR comments

* Bump version: 0.0.37 → 0.0.38

* Make site_uuid field on PVSiteMetadata model optional

* Make pydantic field optional

* Move test site with real UUID to real db test

* Don't use uuid in tests

* Add part of check back

* Ensure autogenerated site uuid is not null in database

* Add WHERE statement on query for past forecasts

This doesn't change the result but speeds up the query in general.

* Bump version: 0.0.38 → 0.0.39

* Bump version: 0.0.39 → 0.0.40

* add logging

* lint

* run blacks

* add extra logs

* Bump version: 0.0.40 → 0.0.41

* add structlogging

* add structlog to requiremwnts

* add logging

* Bump version: 0.0.41 → 0.0.42

* Add structlog initialisation

* blacks

* isort

* Bump version: 0.0.42 → 0.0.43

* Uniformize check to FAKE and fix related test

* Set codecov targets

* Hard-code the "now" time for all tests

This means that the same tests are run now matter the time at which we
run them.

* add caching

* fix

* lint

* isort

* fix for routes calling routes

* lint

* Bump version: 0.0.43 → 0.0.44

* PR comment

* add args to cache

* lint

* Update pv_site_api/cache.py

Co-authored-by: Simon Lemieux <1105380+simlmx@users.noreply.github.com>

* tidy

* Bump version: 0.0.44 → 0.0.45

* What I've got

* Add basic authorization to the /sites* routes

The caller of the routes must have a proper Bearer authorization
header set.

* refactor

* add tests

* fix error in import

* update pvsite-datamodel (in line with main)

* fix bug

* fix incompatible types

* lint and format

* add site existence check

* add back correct datamodel dependency

* fix test name

* allow tests to pass by adding fake condition

* remove 404 check

* use or instead of is not none

* Bump version: 0.0.45 → 0.0.46

* add site existence check

* format and lint

* Bump version: 0.0.46 → 0.0.47

* add post endpoint

* add test back in

* fix errors and format

* add site name to test

* fix tiny error

* fix another small error

* run tests

* fix bugs

* lint and format

* fix fake

* :pleading-face:

* yet another is_fake() addition

* address comments

---------

Co-authored-by: Peter Dudfield <34686298+peterdudfield@users.noreply.github.com>
Co-authored-by: BumpVersion Action <bumpversion@github-actions>
Co-authored-by: peterdudfield <peter.dudfield@hotmail.com>
Co-authored-by: AndrewLester <alester220@gmail.com>
Co-authored-by: Simon Lemieux <1105380+simlmx@users.noreply.github.com>
Co-authored-by: devsjc <sol@openclimatefix.org>

Fix some functions

Fix Enode link endpoint

Remove duplicate fixture

Rename /inverters to /enode/inverters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants