Skip to content

Commit d7c3926

Browse files
committed
fix: Address remaining linting issues
- 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.
1 parent 0f7f795 commit d7c3926

File tree

4 files changed

+71
-71
lines changed

4 files changed

+71
-71
lines changed

src/pvsite_datamodel/management.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
def select_site_by_uuid(session, site_uuid: str) -> str:
2121
"""
2222
Select site by site_uuid and validate it exists.
23-
23+
2424
Args:
2525
session: Database session
2626
site_uuid: UUID of the site
27-
27+
2828
Returns:
2929
str: The validated site UUID
30-
30+
3131
Raises:
3232
ValueError: If site UUID is not found
3333
"""
@@ -41,14 +41,14 @@ def select_site_by_uuid(session, site_uuid: str) -> str:
4141
def select_site_by_client_id(session, client_site_id: str) -> str:
4242
"""
4343
Select site by client_site_id and return its UUID.
44-
44+
4545
Args:
4646
session: Database session
4747
client_site_id: Client site ID
48-
48+
4949
Returns:
5050
str: The site UUID
51-
51+
5252
Raises:
5353
ValueError: If client site ID is not found
5454
"""
@@ -66,10 +66,10 @@ def select_site_by_client_id(session, client_site_id: str) -> str:
6666
def get_all_site_uuids(session) -> List[str]:
6767
"""
6868
Get all site UUIDs from the database.
69-
69+
7070
Args:
7171
session: Database session
72-
72+
7373
Returns:
7474
list: List of all site UUIDs as strings
7575
"""
@@ -81,10 +81,10 @@ def get_all_site_uuids(session) -> List[str]:
8181
def get_all_client_site_ids(session) -> List[str]:
8282
"""
8383
Get all client site IDs from the database.
84-
84+
8585
Args:
8686
session: Database session
87-
87+
8888
Returns:
8989
list: List of all client site IDs as strings
9090
"""
@@ -99,24 +99,24 @@ def update_site_group(
9999
) -> Tuple[Any, List[Dict[str, str]], List[str]]:
100100
"""
101101
Add a site to a site group.
102-
102+
103103
Args:
104104
session: Database session
105105
site_uuid: UUID of the site to add
106106
site_group_name: Name of the site group
107-
107+
108108
Returns:
109109
tuple: (site_group, site_group_sites, site_site_groups)
110110
"""
111111
site_group = get_site_group_by_name(
112112
session=session, site_group_name=site_group_name
113113
)
114-
114+
115115
# Add site to site group
116116
add_site_to_site_group(
117117
session=session, site_uuid=site_uuid, site_group_name=site_group_name
118118
)
119-
119+
120120
# Get updated site group sites
121121
site_group_sites = [
122122
{
@@ -125,26 +125,26 @@ def update_site_group(
125125
}
126126
for site in site_group.locations
127127
]
128-
128+
129129
# Get updated site's groups
130130
site = get_site_by_uuid(session=session, site_uuid=site_uuid)
131131
site_site_groups = [
132132
site_group.location_group_name
133133
for site_group in site.location_groups
134134
]
135-
135+
136136
return site_group, site_group_sites, site_site_groups
137137

138138

139139
def change_user_site_group(session, email: str, site_group_name: str) -> Tuple[str, str]:
140140
"""
141141
Change user to a specific site group name.
142-
142+
143143
Args:
144144
session: Database session
145145
email: Email of the user
146146
site_group_name: Name of the site group
147-
147+
148148
Returns:
149149
tuple: (user_email, user_site_group)
150150
"""
@@ -162,11 +162,11 @@ def add_all_sites_to_site_group(
162162
) -> Tuple[str, List[str]]:
163163
"""
164164
Add all sites to a specified site group.
165-
165+
166166
Args:
167167
session: Database session
168168
site_group_name: Name of the site group (default: "ocf")
169-
169+
170170
Returns:
171171
tuple: (message, sites_added)
172172
"""
@@ -200,10 +200,10 @@ def add_all_sites_to_site_group(
200200
def validate_email(email: str) -> bool:
201201
"""
202202
Validate email address format.
203-
203+
204204
Args:
205205
email: Email address to validate
206-
206+
207207
Returns:
208208
bool: True if email is valid, False otherwise
209209
"""

src/pvsite_datamodel/read/details.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""This module contains functions to get details from the database for a user, site or site group."""
1+
"""
2+
This module contains functions to get details from the database for a user,
3+
site or site group.
4+
"""
25

36
import re
47
from typing import Dict, List, Any
@@ -16,11 +19,11 @@ def get_user_details(
1619
) -> tuple[List[Dict[str, str]], str, int]:
1720
"""
1821
Get the user details from the database.
19-
22+
2023
Args:
2124
session: Database session
2225
email: User's email address
23-
26+
2427
Returns:
2528
tuple: (user_sites, user_site_group, user_site_count)
2629
"""
@@ -40,21 +43,21 @@ def get_user_details(
4043
def get_site_details(session, site_uuid: str) -> Dict[str, Any]:
4144
"""
4245
Get the site details for one site.
43-
46+
4447
Args:
4548
session: Database session
4649
site_uuid: UUID of the site
47-
50+
4851
Returns:
4952
dict: Site details dictionary
5053
"""
5154
site = get_site_by_uuid(session=session, site_uuid=site_uuid)
52-
55+
5356
if isinstance(site.asset_type, LocationAssetType):
5457
asset_type_value = str(site.asset_type.name.lower())
5558
else:
5659
asset_type_value = str(site.asset_type)
57-
60+
5861
site_details = {
5962
"site_uuid": str(site.location_uuid),
6063
"client_site_id": str(site.client_location_id),
@@ -89,11 +92,11 @@ def get_site_group_details(
8992
) -> tuple[List[Dict[str, str]], List[str]]:
9093
"""
9194
Get the site group details from the database.
92-
95+
9396
Args:
9497
session: Database session
9598
site_group_name: Name of the site group
96-
99+
97100
Returns:
98101
tuple: (site_group_sites, site_group_users)
99102
"""
@@ -114,10 +117,10 @@ def get_site_group_details(
114117
def validate_email(email: str) -> bool:
115118
"""
116119
Validate email address format.
117-
120+
118121
Args:
119122
email: Email address to validate
120-
123+
121124
Returns:
122125
bool: True if email is valid, False otherwise
123126
"""

tests/read/test_details.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pvsite_datamodel.read.details import (
66
get_user_details,
77
get_site_details,
8-
get_site_group_details,
98
validate_email,
109
)
1110

@@ -19,20 +18,20 @@ def test_get_user_details(self):
1918
mock_site1 = Mock()
2019
mock_site1.location_uuid = "site-uuid-1"
2120
mock_site1.client_location_id = "client-id-1"
22-
21+
2322
mock_site2 = Mock()
2423
mock_site2.location_uuid = "site-uuid-2"
2524
mock_site2.client_location_id = "client-id-2"
26-
25+
2726
mock_site_group = Mock()
2827
mock_site_group.location_group_name = "test-group"
2928
mock_site_group.locations = [mock_site1, mock_site2]
30-
29+
3130
mock_user = Mock()
3231
mock_user.location_group = mock_site_group
33-
32+
3433
mock_session = Mock()
35-
34+
3635
# Mock the get_user_by_email function
3736
import pvsite_datamodel.read.details
3837
original_get_user_by_email = (
@@ -41,12 +40,12 @@ def test_get_user_details(self):
4140
pvsite_datamodel.read.details.get_user_by_email = Mock(
4241
return_value=mock_user
4342
)
44-
43+
4544
try:
4645
user_sites, user_site_group, user_site_count = get_user_details(
4746
mock_session, "test@example.com"
4847
)
49-
48+
5049
assert user_site_group == "test-group"
5150
assert user_site_count == 2
5251
assert len(user_sites) == 2
@@ -65,14 +64,14 @@ class TestGetSiteDetails:
6564
def test_get_site_details_with_asset_type_enum(self):
6665
"""Test getting site details with LocationAssetType enum."""
6766
from datetime import datetime
68-
67+
6968
# Mock site object
7069
mock_asset_type = Mock()
7170
mock_asset_type.name = "PV"
72-
71+
7372
mock_ml_model = Mock()
7473
mock_ml_model.name = "test-model"
75-
74+
7675
mock_site = Mock()
7776
mock_site.location_uuid = "test-uuid"
7877
mock_site.client_location_id = "test-client-id"
@@ -93,9 +92,9 @@ def test_get_site_details_with_asset_type_enum(self):
9392
mock_site.ml_model_uuid = "model-uuid"
9493
mock_site.ml_model = mock_ml_model
9594
mock_site.created_utc = datetime(2023, 1, 1)
96-
95+
9796
mock_session = Mock()
98-
97+
9998
# Mock the get_site_by_uuid function
10099
import pvsite_datamodel.read.details
101100
original_get_site_by_uuid = (
@@ -104,10 +103,10 @@ def test_get_site_details_with_asset_type_enum(self):
104103
pvsite_datamodel.read.details.get_site_by_uuid = Mock(
105104
return_value=mock_site
106105
)
107-
106+
108107
try:
109108
site_details = get_site_details(mock_session, "test-uuid")
110-
109+
111110
assert site_details["site_uuid"] == "test-uuid"
112111
assert site_details["client_site_id"] == "test-client-id"
113112
assert site_details["asset_type"] == "pv"

0 commit comments

Comments
 (0)