-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
|
||
from tests.factories import EventFactory | ||
|
||
from django.urls import reverse | ||
from rest_framework.test import force_authenticate | ||
|
||
from response.core.views import EventsViewSet | ||
|
||
def test_list_events(arf, api_user): | ||
|
||
persisted_events = EventFactory.create_batch(10) | ||
|
||
req = arf.get(reverse("event-list")) | ||
force_authenticate(req, user=api_user) | ||
response = EventsViewSet.as_view({"get": "list"})(req) | ||
|
||
assert response.status_code == 200, "Got non-200 response from API" | ||
content = json.loads(response.rendered_content) | ||
|
||
assert "results" in content, "Response didn't have results key" | ||
incidents = content["results"] | ||
assert len(incidents) == len( | ||
persisted_events, | ||
), "Didn't get expected number of events back" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import factory | ||
import random | ||
|
||
from .incident import IncidentFactory | ||
from .action import ActionFactory | ||
|
||
from faker import Factory | ||
|
||
from response.core.models import Event | ||
from response.core.serializers import IncidentSerializer, ActionSerializer | ||
|
||
faker = Factory.create() | ||
|
||
|
||
def incident_payload(): | ||
return IncidentSerializer(IncidentFactory.create()).data | ||
|
||
|
||
def action_payload(): | ||
return ActionSerializer(ActionFactory.create()).data | ||
|
||
|
||
class EventFactory(factory.DjangoModelFactory): | ||
class Meta: | ||
model = Event | ||
|
||
timestamp = factory.LazyFunction( | ||
lambda: faker.date_time_between(start_date="-6m", end_date="now", tzinfo=None) | ||
) | ||
event_type = random.choice([Event.ACTION_EVENT_TYPE, Event.INCIDENT_EVENT_TYPE]) | ||
|
||
payload = random.choice([incident_payload, action_payload])() |