-
Notifications
You must be signed in to change notification settings - Fork 2
Serialize CompletedWork flags in CompletedWorkSerializer #553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I think I'm going to try Copilot for reviewing this quickly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
commcare_connect/opportunity/api/serializers.py:271
- There is an assumption that 'visit' is a dictionary containing a 'flags' key. Consider adding a type check or exception handling to ensure that if 'visit' is not a dict, the code fails gracefully.
for slug, reason in visit.get("flags", []):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great. left a comment on the test change, also good to add a test that explicitly checks the correctness of the new field (that the flags get added in the right format)
@@ -235,7 +236,7 @@ def test_delivery_progress_endpoint( | |||
assert response.data.keys() == DeliveryProgressSerializer().get_fields().keys() | |||
assert len(response.data["deliveries"]) == 1 | |||
assert len(response.data["payments"]) == 0 | |||
assert response.data["deliveries"][0].keys() == UserVisitSerializer().get_fields().keys() | |||
assert response.data["deliveries"][0].keys() == CompletedWorkSerializer().get_fields().keys() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good catch. It was orginally like that because we switched serializers and wanted to ensure compatibility, but I agree that now that we are making additions, we should use the correct one. That said, I am not sure this assertion is buying us much, and would prefer the test to check expected values of keys we care about in the fields rather than just the presence of the keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True true. I'll update!
@@ -237,6 +242,10 @@ def test_delivery_progress_endpoint( | |||
assert len(response.data["deliveries"]) == 1 | |||
assert len(response.data["payments"]) == 0 | |||
assert response.data["deliveries"][0].keys() == CompletedWorkSerializer().get_fields().keys() | |||
assert response.data["deliveries"][0]["flags"] == [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I think about it, is this the expected format? Would it not make more sense to have it like this:
[
{
"duration": "The form was completed too quickly.",
"attachment_missing": "Form was submitted without attachments.",
},
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@calellowitz Actually, I'm going to update it as above. Feel free to let me know if that's not in fact what was envisioned. So now a single visit's flags will be consolidated into this one dictionary structure.
See c384c9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops yes. This is definitely what was intended. Thanks for the fix (and one more benefit of tests, making this stuff explicit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, shouldn't this not be a list at all. If this is always a list with a single dict, I think it can just be a dict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Product Description
No user-facing changes, only API data update.
Technical Summary
Ticket
This PR makes sure to serialize the CompletedWork records' flags as part of the CompletedWorkSerializer in a dictionary style with slug as key and description as value. For example, the jsonified response would look like this:
Additional (unexpected) update
The
test_delivery_progress_endpoint
test asserts that the serialized delivery keys be similar to theUserVisitSerializer
, but that's not the correct serializer class that's being used in the get_deliveries method of theDeliveryProgressSerializer
.I have updated the test to test against the
CompletedWorkSerializer
, but was just wondering if this was a previous oversight?Safety Assurance
Safety story
Updated
test_delivery_progress_endpoint
test to reflect new changes.Automated test coverage
No new tests, only updated an existing test
QA Plan
QA not planned
Labels & Review