|
10 | 10 | from django.core import management |
11 | 11 | from rest_framework import status |
12 | 12 |
|
| 13 | +from api.factories.event import EventFactory |
13 | 14 | from api.models import Country, DisasterType, District, Region, RegionName |
14 | 15 | from api.utils import get_model_name |
15 | 16 | from deployments.factories.project import SectorFactory |
@@ -119,6 +120,7 @@ def test_post_dref_creation(self, send_notification): |
119 | 120 | old_count = Dref.objects.count() |
120 | 121 | national_society = Country.objects.create(name="xzz") |
121 | 122 | disaster_type = DisasterType.objects.create(name="abc") |
| 123 | + event = EventFactory.create(name="Test event") |
122 | 124 | data = { |
123 | 125 | "title": "Dref test title", |
124 | 126 | "type_of_onset": Dref.OnsetType.SLOW.value, |
@@ -182,6 +184,7 @@ def test_post_dref_creation(self, send_notification): |
182 | 184 | "originator_email": "test@gmail.com", |
183 | 185 | "national_society": national_society.id, |
184 | 186 | "disaster_type": disaster_type.id, |
| 187 | + "event": event.id, |
185 | 188 | # NOTE: Test Many to Many fields |
186 | 189 | "risk_security": [ |
187 | 190 | {"risk": "Test Risk 1", "mitigation_measure": "Test Mitigation Measure"}, |
@@ -246,6 +249,7 @@ def test_post_dref_creation(self, send_notification): |
246 | 249 | response = self.client.post(url, data, format="json") |
247 | 250 | self.assertEqual(response.status_code, 201) |
248 | 251 | self.assertEqual(Dref.objects.count(), old_count + 1) |
| 252 | + self.assertEqual(response.data["event"], event.id) |
249 | 253 | instance = Dref.objects.get(id=response.data["id"]) |
250 | 254 | instance.users.add(self.user.id) |
251 | 255 | instance_user_email = [user.email for user in instance.users.all()] |
@@ -1928,10 +1932,14 @@ def test_completed_dref_operations(self): |
1928 | 1932 | def test_filter_active_dref(self): |
1929 | 1933 | country_1 = Country.objects.create(name="country1") |
1930 | 1934 | country_2 = Country.objects.create(name="country2") |
1931 | | - |
| 1935 | + event = EventFactory.create(name="Test Event") |
1932 | 1936 | # create some dref |
1933 | 1937 | dref_1 = DrefFactory.create( |
1934 | | - is_active=True, type_of_dref=Dref.DrefType.ASSESSMENT, country=country_1, created_by=self.root_user |
| 1938 | + is_active=True, |
| 1939 | + type_of_dref=Dref.DrefType.ASSESSMENT, |
| 1940 | + country=country_1, |
| 1941 | + created_by=self.root_user, |
| 1942 | + event=event, |
1935 | 1943 | ) |
1936 | 1944 | dref_2 = DrefFactory.create(is_active=True, type_of_dref=Dref.DrefType.LOAN, country=country_2, created_by=self.root_user) |
1937 | 1945 | # some dref final report |
@@ -1968,6 +1976,12 @@ def test_filter_active_dref(self): |
1968 | 1976 | self.assertEqual(len(response.data["results"]), 1) |
1969 | 1977 | self.assertEqual(response.data["results"][0]["final_report_details"]["id"], dref_final_report.id) |
1970 | 1978 |
|
| 1979 | + # filter by event |
| 1980 | + url = f"/api/v2/active-dref/?event={event.id}" |
| 1981 | + response = self.client.get(url) |
| 1982 | + self.assertEqual(response.status_code, 200) |
| 1983 | + self.assertEqual(len(response.data["results"]), 1) |
| 1984 | + |
1971 | 1985 | def test_dref_share_users(self): |
1972 | 1986 | user1 = UserFactory.create( |
1973 | 1987 | username="user1@test.com", |
|
0 commit comments