Skip to content

Commit

Permalink
timeline api: make metadata optional
Browse files Browse the repository at this point in the history
The API currently errors with HTTP 400 if we try to create a timeline
event without a metadata tag. This makes the field non-required in the
serializer.
  • Loading branch information
milesbxf committed Sep 25, 2019
1 parent 71f9246 commit ba57847
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion response/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Meta:


class TimelineEventSerializer(serializers.ModelSerializer):
metadata = serializers.JSONField(allow_null=True)
metadata = serializers.JSONField(allow_null=True, required=False)

class Meta:
model = TimelineEvent
Expand Down
28 changes: 21 additions & 7 deletions tests/api/test_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
faker = Faker()


def test_create_timeline_event(arf, api_user):
incident = IncidentFactory.create()

event_model = TimelineEventFactory.build(incident=incident)
event_data = serializers.TimelineEventSerializer(event_model).data

def assert_create_timeline_event(arf, api_user, incident, event_data):
req = arf.post(
reverse("incident-timeline-event-list", kwargs={"incident_pk": incident.pk}),
event_data,
Expand All @@ -32,10 +27,29 @@ def test_create_timeline_event(arf, api_user):
assert response.status_code == 201, "Got non-201 response from API"

assert TimelineEvent.objects.filter(
incident=incident, timestamp=event_model.timestamp
incident=incident, timestamp=event_data["timestamp"]
).exists()


def test_create_timeline_event(arf, api_user):
incident = IncidentFactory.create()

event_model = TimelineEventFactory.build(incident=incident)
event_data = serializers.TimelineEventSerializer(event_model).data

assert_create_timeline_event(arf, api_user, incident, event_data)


def test_create_timeline_event_no_metadata(arf, api_user):
incident = IncidentFactory.create()

event_model = TimelineEventFactory.build(incident=incident)
event_data = serializers.TimelineEventSerializer(event_model).data
del event_data["metadata"]

assert_create_timeline_event(arf, api_user, incident, event_data)


def test_list_timeline_events_by_incident(arf, api_user):
incident = IncidentFactory.create()

Expand Down

0 comments on commit ba57847

Please sign in to comment.