Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
match_state in api schema; allow patching of match_state; tests of same
Browse files Browse the repository at this point in the history
  • Loading branch information
naknomum committed Oct 17, 2023
1 parent fc27d37 commit 04a5386
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/modules/sightings/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class PatchSightingDetailsParameters(PatchJSONParameters):
'/locationId',
'/taxonomies',
'/verbatimLocality',
'/match_state',
)

@classmethod
Expand Down Expand Up @@ -162,6 +163,17 @@ def replace(cls, obj, field, value, state):
elif field == 'verbatimLocality':
obj.verbatim_locality = value
ret_val = True
elif field == 'match_state':
from app.modules.sightings.models import SightingMatchState

try:
SightingMatchState(value)
except KeyError:
raise HoustonException(
log, f'match_state value passed ({value}) is invalid'
)
obj.match_state = value
ret_val = True

return ret_val

Expand Down
1 change: 1 addition & 0 deletions app/modules/sightings/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class Meta(TimedSightingSchema.Meta):
'assets',
'featuredAssetGuid',
'stage',
'match_state',
'jobs',
'creator',
'time',
Expand Down
14 changes: 14 additions & 0 deletions tests/modules/sightings/resources/test_create_sighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ def test_create_and_modify_and_delete_sighting(
sighting_id,
patch_data=[
{'op': 'replace', 'path': '/locationId', 'value': region2_id},
{'op': 'replace', 'path': '/match_state', 'value': 'reviewed'},
],
)
# check that change was made
response = sighting_utils.read_sighting(flask_app_client, researcher_1, sighting_id)
assert response.json['locationId'] == region2_id
assert response.json['match_state'] == 'reviewed'

new_configs = [{'algorithms': ['hotspotter_nosv']}]
sighting_utils.patch_sighting(
Expand Down Expand Up @@ -177,6 +179,7 @@ def test_create_and_modify_and_delete_sighting(
'featuredAssetGuid',
'unreviewed_start_time',
'creator',
'match_state',
'curation_start_time',
'detection_start_time',
}
Expand Down Expand Up @@ -255,6 +258,17 @@ def test_create_and_modify_and_delete_sighting(
expected_status_code=400,
)

# invalid match_state
sighting_utils.patch_sighting(
flask_app_client,
researcher_1,
sighting_id,
patch_data=[
{'op': 'add', 'path': '/match_state', 'value': 'failure'},
],
expected_status_code=409,
)

# patch op=add will create a new (3rd) encounter
sighting_utils.patch_sighting(
flask_app_client,
Expand Down

0 comments on commit 04a5386

Please sign in to comment.