Skip to content

Commit 019330e

Browse files
minor code cleanup
1 parent b23926f commit 019330e

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

python/nwsc_dummy_service/ncd_web_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def handler(self):
8888
# they've now been returned to IDSS Engine clients at least once
8989
current_app.logger.info('Got all new profiles: %s', profiles)
9090
for profile in profiles:
91-
self.profile_store.move_to_existing(profile['id'])
91+
self.profile_store.mark_as_existing(profile['id'])
9292

9393
else:
9494
# status query param should have been 'existing' or 'new'

python/nwsc_dummy_service/src/profile_store.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
logger = logging.getLogger(__name__)
2222

2323

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

119-
def move_to_existing(self, profile_id: str) -> bool:
118+
def mark_as_existing(self, profile_id: str) -> bool:
120119
"""Mark a formerly "new" Support Profile as "existing", a.k.a. has been returned in
121120
API response at least once and should no longer be processed as "new"
122121
@@ -141,10 +140,7 @@ def move_to_existing(self, profile_id: str) -> bool:
141140
# move the JSON file from the "new" to the "existing" directory and update cache
142141
existing_filepath = os.path.join(self._existing_dir, f'{profile_id}.json')
143142
os.rename(new_filepath, existing_filepath)
144-
145-
# update this profile's is_new flag in in-memory cache
146-
profile_index = self.profile_cache.index(cached_profile)
147-
self.profile_cache[profile_index].is_new = False
143+
cached_profile.is_new = False
148144

149145
return True
150146

python/nwsc_dummy_service/test/test_ncd_web_service.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,12 @@ def test_get_new_profiles(wrapper: AppWrapper, mock_request: Mock, mock_profile_
152152
assert status_code == 200
153153
assert response.json == {'profiles': [example_profile], 'errors': []}
154154

155-
func_call_args = mock_profile_store.return_value.get_all.mock_calls
156-
assert func_call_args[0][2] == {'filter_new_profiles': True} # filter_new_profiles set to True
155+
get_call_args = mock_profile_store.return_value.get_all.mock_calls
156+
assert get_call_args[0][2] == {'filter_new_profiles': True} # filter_new_profiles set to True
157+
158+
# expect that we told ProfileStore to label this profile as not new
159+
mark_existing_call_args = mock_profile_store.return_value.mark_as_existing.mock_calls
160+
assert mark_existing_call_args[0][1][0] == example_profile['id']
157161

158162

159163
def test_create_profile_success(wrapper: AppWrapper, mock_request: Mock, mock_profile_store: Mock):

python/nwsc_dummy_service/test/test_profile_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_move_to_existing_success(store: ProfileStore):
150150
new_profiles = store.get_all(filter_new_profiles=True)
151151
assert [p['id'] for p in new_profiles] == [EXAMPLE_UUID]
152152

153-
store.move_to_existing(EXAMPLE_UUID)
153+
store.mark_as_existing(EXAMPLE_UUID)
154154

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

0 commit comments

Comments
 (0)