Feature/site group management and details#247
Feature/site group management and details#247ram-from-tvl wants to merge 51 commits intoopenclimatefix:mainfrom
Conversation
- Add management.py with functions for site group operations: * Site selection by UUID and client ID with validation * Get all site UUIDs and client site IDs * Update site groups and user site group assignments * Add all sites to a site group with bulk operations * Email validation utility - Add read/details.py with functions for retrieving detailed information: * Get comprehensive user details including sites and groups * Get detailed site information with all attributes * Get site group details with associated sites and users * Email validation utility - Update package __init__.py files to expose new functions - Add comprehensive test coverage for both modules - Add usage example demonstrating all new functionality These modules provide a clean API for managing site groups and retrieving detailed information about users, sites, and site groups in the PVSite database.
- Remove unused imports (Union, datetime, pytest, LocationAssetType) - Fix lines exceeding 100 characters by breaking long lines - Improve exception handling with 'raise ... from err' pattern - Remove examples folder as requested - Clean up whitespace and formatting issues All flake8 violations have been addressed: - T201: Removed print statements by deleting examples - E501: Fixed line length violations - F401: Removed unused imports - W293: Cleaned up blank line whitespace - B904: Fixed exception re-raising pattern
1c67378 to
0f7f795
Compare
- Fix long line in details.py docstring (E501) - Remove unused imports from test files (F401): * get_site_group_details from test_details.py * update_site_group and change_user_site_group from test_management.py - Clean up trailing whitespace on blank lines (W293) - Ensure proper line endings All flake8 violations should now be resolved.
5135a25 to
d7c3926
Compare
- Add extra blank line in module docstring for better formatting - Maintain consistency with Python docstring conventions
25cd8d3 to
fdcedb2
Compare
- Fix D205 docstring style requirement - Add blank line between summary and description in details.py - Ensure proper docstring formatting compliance
81dfbe4 to
d9f4e73
Compare
594a8c6 to
4436cf9
Compare
ce25934 to
a015ab7
Compare
|
Hi @peterdudfield , |
|
I think most of the functions should be put in here is they are to do with sites. Please note that some functions are already move over here. Could you onyl add the ones that are not in here arleady |
- Move get_all_site_uuids, get_all_client_site_ids, and get_site_details from management.py and details.py to read/site.py - Remove redundant functions from management.py that overlapped with existing site.py functions - Update import structure in __init__.py files to maintain API compatibility - Addresses feedback from PR review to consolidate site-related functions in appropriate module Fixes organizational structure as requested in PR review feedback.
- Addresses linting error F401 for unused import - Cleaned up imports to only include functions that are actually used
I have made some reorganisation and updated the code. please let me know if anything is redundant and requires changes. |
- Added get_site_details function in src/pvsite_datamodel/read/details.py - Function returns comprehensive site information as expected by tests - Fixed import to use get_site_by_uuid from site module instead of non-existent get_site_details - Handles asset type enum conversion and formatting - Includes all site properties like capacity, location, groups, etc.
- Remove trailing whitespace from blank lines - Split long line 95 to comply with 100 character limit - Fix W293 and E501 linting errors
- Fix test_select_site_by_client_id_success to mock the correct function select_site_by_client_id - Add test_select_site_by_client_id_not_found for error case - Fix TestGetAllSites tests to mock the correct functions instead of get_all_sites - Clean up duplicate imports in management.py - Import functions directly instead of using wrapper functions Fixes: - AttributeError: get_site_by_client_site_id does not exist - TypeError: Mock objects not behaving like proper lists in get_all_* functions
- Remove unused imports for get_all_site_uuids, get_all_client_site_ids, get_site_by_client_site_id - Shorten long import line to comply with 100 character limit - Add get_all_site_uuids and get_all_client_site_ids functions using local imports - Keep select_site_by_client_id using direct database query implementation Fixes: - F401 imported but unused errors - E501 line too long error
- Fix test_select_site_by_client_id_success to properly mock database query instead of function - Fix test_select_site_by_client_id_not_found to mock query returning None - Fix test_get_all_site_uuids and test_get_all_client_site_ids to mock underlying functions in read.site module - Remove problematic function-level mocking that was causing Mock objects to be returned instead of expected types Tests now properly mock the database interactions and return expected data types.
src/pvsite_datamodel/site_group.py
Outdated
| @@ -0,0 +1,193 @@ | |||
| """This module contains functions for managing site groups.""" | |||
There was a problem hiding this comment.
could this be moved int the read folder?
src/pvsite_datamodel/read/details.py
Outdated
| from pvsite_datamodel.read.site import get_site_by_uuid | ||
|
|
||
|
|
||
| def get_user_details( |
There was a problem hiding this comment.
this can stay in the dashboard
There was a problem hiding this comment.
Hi @peterdudfield
Is it better to remove details.py from the read folder.
Thankyou!
There was a problem hiding this comment.
Hi @peterdudfield
Could you please hare more information on this PR. I have made some changes so far. please let me know if its good to go..?
Thank you!
src/pvsite_datamodel/read/details.py
Outdated
| return user_sites, user_site_group, user_site_count | ||
|
|
||
|
|
||
| def get_site_group_details( |
There was a problem hiding this comment.
this can stay in the dashboard
src/pvsite_datamodel/read/details.py
Outdated
| return site_group_sites, site_group_users | ||
|
|
||
|
|
||
| def validate_email(email: str) -> bool: |
There was a problem hiding this comment.
should this not be in user.py
There was a problem hiding this comment.
oh, youve moved it over there arleady, so remove this
src/pvsite_datamodel/read/details.py
Outdated
| return False | ||
|
|
||
|
|
||
| def get_site_details(session, site_uuid: str) -> Dict[str, str]: |
There was a problem hiding this comment.
keep this in the dashboard
| @@ -0,0 +1,178 @@ | |||
| """Tests for the site_group module.""" | |||
There was a problem hiding this comment.
move inside read folder
tests/test_site_group.py
Outdated
| assert user_site_group == "new_site_group" | ||
|
|
||
|
|
||
| def test_validate_email(): |
There was a problem hiding this comment.
but you should remove it, as its bee moved to a different rest function already
tests/test_site_group.py
Outdated
| select_site_by_uuid) | ||
|
|
||
|
|
||
| @patch("pvsite_datamodel.site_group.get_site_by_uuid") |
There was a problem hiding this comment.
remove all mocking, see how other tests have been done
| import datetime as dt | ||
|
|
||
| from pvsite_datamodel import APIRequestSQL | ||
| from pvsite_datamodel.sqlmodels import APIRequestSQL |
There was a problem hiding this comment.
undo all these changes from pvsite_datamodel import APIRequestSQL is fine
| assert len(db_session.query(UserSQL).all()) == 1 | ||
|
|
||
|
|
||
| class TestValidateEmail: |
Hi @peterdudfield |
|
Hi @peterdudfield, |
…group - Remove get_all_site_uuids from main __init__.py imports and __all__ list - Add get_all_site_uuids function to site_group.py using get_all_sites - This resolves ImportError: cannot import name 'get_all_site_uuids'
- Remove get_site_details from imports in __init__.py - Remove get_site_details from __all__ list - Function doesn't exist in codebase, causing ImportError - Resolves: ImportError: cannot import name 'get_site_details'
- Add validate_email import to src/pvsite_datamodel/read/__init__.py - Function exists in user.py but wasn't exported from read module - Resolves: ImportError: cannot import name 'validate_email' from 'pvsite_datamodel.read' - Fixes test_get_user_by_email.py import error
|
Hi @peterdudfield |
Add Site Group Management and Details Modules
Fixes #231
This PR introduces two new modules to enhance the PVSite datamodel with better site group management capabilities and detailed information retrieval functions.
Management Module (
src/pvsite_datamodel/management.py)Details Module (
src/pvsite_datamodel/read/details.py)Testing & Documentation
Files Changed
src/pvsite_datamodel/read/site_group.py(new)src/pvsite_datamodel/read/details.py(new)src/pvsite_datamodel/__init__.py(updated exports)src/pvsite_datamodel/read/__init__.py(updated exports)tests/test_management.py(new)tests/read/test_details.py(new)examples/usage_example.py(new)Would appreciate any feedback or suggestions for improvements!