Mitja Nikolaus | 03e412b | 2018-09-18 17:50:15 +0200 | [diff] [blame] | 1 | """Tests for the crashreports REST API.""" |
Mitja Nikolaus | fd452f8 | 2018-11-07 11:53:59 +0100 | [diff] [blame^] | 2 | from django.urls import reverse |
| 3 | from rest_framework import status |
Mitja Nikolaus | 03e412b | 2018-09-18 17:50:15 +0200 | [diff] [blame] | 4 | |
| 5 | from crashreports.tests.utils import Dummy |
| 6 | from crashreports.tests.test_rest_api_heartbeats import HeartbeatsTestCase |
| 7 | |
| 8 | |
| 9 | class CrashreportsTestCase(HeartbeatsTestCase): |
| 10 | """Test cases for crash reports.""" |
| 11 | |
| 12 | # pylint: disable=too-many-ancestors |
| 13 | |
| 14 | LIST_CREATE_URL = "api_v1_crashreports" |
| 15 | RETRIEVE_URL = "api_v1_crashreport" |
| 16 | LIST_CREATE_BY_UUID_URL = "api_v1_crashreports_by_uuid" |
| 17 | RETRIEVE_BY_UUID_URL = "api_v1_crashreport_by_uuid" |
| 18 | |
| 19 | @staticmethod |
| 20 | def _create_dummy_data(**kwargs): |
| 21 | return Dummy.crashreport_data(**kwargs) |
Mitja Nikolaus | fd452f8 | 2018-11-07 11:53:59 +0100 | [diff] [blame^] | 22 | |
| 23 | @staticmethod |
| 24 | def _create_alternative_dummy_data(**kwargs): |
| 25 | return Dummy.alternative_crashreport_data(**kwargs) |
| 26 | |
| 27 | def test_create_duplicate(self): |
| 28 | """Test creation of a duplicate crashreport.""" |
| 29 | # Create a first crashreport |
| 30 | report_data = self._create_dummy_data(uuid=self.uuid) |
| 31 | response_first = self.user.post( |
| 32 | reverse(self.LIST_CREATE_URL), report_data |
| 33 | ) |
| 34 | self.assertEqual(response_first.status_code, status.HTTP_201_CREATED) |
| 35 | |
| 36 | # Create a second crashreport for the same day and the same time |
| 37 | response_second = self.user.post( |
| 38 | reverse(self.LIST_CREATE_URL), report_data |
| 39 | ) |
| 40 | self.assertEqual(response_second.status_code, status.HTTP_201_CREATED) |
| 41 | |
| 42 | # Assert that only one crashreport instance was created |
| 43 | url = reverse(self.LIST_CREATE_BY_UUID_URL, args=[self.uuid]) |
| 44 | response = self.fp_staff_client.get(url) |
| 45 | self.assertEqual(len(response.data["results"]), 1) |
| 46 | |
| 47 | def test_create_with_datetime(self): |
| 48 | """Override to just pass because crashreports always use datetime.""" |
| 49 | pass |