Skip to content

Commit

Permalink
minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenzie-grimes-noaa committed Dec 19, 2024
1 parent b23926f commit 019330e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion python/nwsc_dummy_service/ncd_web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def handler(self):
# they've now been returned to IDSS Engine clients at least once
current_app.logger.info('Got all new profiles: %s', profiles)
for profile in profiles:
self.profile_store.move_to_existing(profile['id'])
self.profile_store.mark_as_existing(profile['id'])

else:
# status query param should have been 'existing' or 'new'
Expand Down
8 changes: 2 additions & 6 deletions python/nwsc_dummy_service/src/profile_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
logger = logging.getLogger(__name__)



@dataclass
class CachedProfile:
"""Data class to hold Support Profile's data and metadata ("new" vs "existing" status)
Expand Down Expand Up @@ -116,7 +115,7 @@ def save(self, profile: dict) -> str | None:
self.profile_cache.append(cached_profile)
return cached_profile.id

def move_to_existing(self, profile_id: str) -> bool:
def mark_as_existing(self, profile_id: str) -> bool:
"""Mark a formerly "new" Support Profile as "existing", a.k.a. has been returned in
API response at least once and should no longer be processed as "new"
Expand All @@ -141,10 +140,7 @@ def move_to_existing(self, profile_id: str) -> bool:
# move the JSON file from the "new" to the "existing" directory and update cache
existing_filepath = os.path.join(self._existing_dir, f'{profile_id}.json')
os.rename(new_filepath, existing_filepath)

# update this profile's is_new flag in in-memory cache
profile_index = self.profile_cache.index(cached_profile)
self.profile_cache[profile_index].is_new = False
cached_profile.is_new = False

return True

Expand Down
8 changes: 6 additions & 2 deletions python/nwsc_dummy_service/test/test_ncd_web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ def test_get_new_profiles(wrapper: AppWrapper, mock_request: Mock, mock_profile_
assert status_code == 200
assert response.json == {'profiles': [example_profile], 'errors': []}

func_call_args = mock_profile_store.return_value.get_all.mock_calls
assert func_call_args[0][2] == {'filter_new_profiles': True} # filter_new_profiles set to True
get_call_args = mock_profile_store.return_value.get_all.mock_calls
assert get_call_args[0][2] == {'filter_new_profiles': True} # filter_new_profiles set to True

# expect that we told ProfileStore to label this profile as not new
mark_existing_call_args = mock_profile_store.return_value.mark_as_existing.mock_calls
assert mark_existing_call_args[0][1][0] == example_profile['id']


def test_create_profile_success(wrapper: AppWrapper, mock_request: Mock, mock_profile_store: Mock):
Expand Down
2 changes: 1 addition & 1 deletion python/nwsc_dummy_service/test/test_profile_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_move_to_existing_success(store: ProfileStore):
new_profiles = store.get_all(filter_new_profiles=True)
assert [p['id'] for p in new_profiles] == [EXAMPLE_UUID]

store.move_to_existing(EXAMPLE_UUID)
store.mark_as_existing(EXAMPLE_UUID)

new_profiles = store.get_all(filter_new_profiles=True)
assert new_profiles == [] # Support Profile has vanished from list of new
Expand Down

0 comments on commit 019330e

Please sign in to comment.