|
6 | 6 | from main.test_case import APITestCase |
7 | 7 | from eap.models import ( |
8 | 8 | EAP, |
| 9 | + Action, |
9 | 10 | EarlyAction, |
| 11 | + EAPDocument, |
10 | 12 | EAPActivationReport, |
11 | | - Action, |
12 | | - EarlyActionIndicator, |
13 | 13 | ) |
14 | 14 |
|
15 | 15 | from api.factories.country import CountryFactory |
|
21 | 21 | EAPDocumentFactory, |
22 | 22 | EAPFactory, |
23 | 23 | EAPActivationFactory, |
| 24 | + EAPActivationReportFactory, |
24 | 25 | ) |
25 | 26 |
|
26 | 27 |
|
@@ -245,6 +246,12 @@ def test_create_and_update_eap(self): |
245 | 246 | self.assertEqual(len(response['references']), 1) |
246 | 247 | self.assertEqual(len(response['partners']), 1) |
247 | 248 |
|
| 249 | + # test patch |
| 250 | + data = {'status': EAP.Status.APPROVED} |
| 251 | + response = self.client.patch(f'/api/v2/eap/{created.id}/', data=data, format='json').json() |
| 252 | + pached = EAP.objects.get(id=response['id']) |
| 253 | + self.assertEqual(pached.status, EAP.Status.APPROVED) |
| 254 | + |
248 | 255 | def test_get_eap(self): |
249 | 256 | user1 = UserFactory.create(username='abc') |
250 | 257 | eap1, eap2, eap3 = EAPFactory.create_batch(3, created_by=user1) |
@@ -353,3 +360,56 @@ def test_create_and_update_eap_activation_report(self): |
353 | 360 | self.assertEqual(len(final_report_updated_resp['operational_plans']), 1) |
354 | 361 | self.assertEqual(len(final_report_updated_resp['operational_plans'][0]['early_actions_achievements']), 2) |
355 | 362 | self.assertEqual(len(final_report_updated_resp['operational_plans'][0]['indicators']), 2) |
| 363 | + |
| 364 | + # test patch |
| 365 | + data = {'ifrc_financial_report': self.document1.id} |
| 366 | + with self.capture_on_commit_callbacks(execute=True): |
| 367 | + final_report_patched_resp = self.client.patch( |
| 368 | + f'/api/v2/eap-activation-report/{created.id}/', |
| 369 | + data, |
| 370 | + format='json' |
| 371 | + ).json() |
| 372 | + updated = EAPActivationReport.objects.get(id=final_report_patched_resp['id']) |
| 373 | + self.assertEqual(final_report_patched_resp['ifrc_financial_report'], self.document1.id) |
| 374 | + |
| 375 | + def test_get_eap_activation_report(self): |
| 376 | + user1 = UserFactory.create(username='abc') |
| 377 | + report1, report2, report3 = EAPActivationReportFactory.create_batch(3, created_by=user1) |
| 378 | + self.client.force_authenticate(user=user1) |
| 379 | + response1 = self.client.get('/api/v2/eap-activation-report/').json() |
| 380 | + self.assertEqual(response1['results'][0]['created_by'], user1.id) |
| 381 | + self.assertEqual(len(response1['results']), 3) |
| 382 | + assert all(item in [data['id'] for data in response1['results']] for item in [report1.id, report2.id, report3.id]) |
| 383 | + |
| 384 | + # query single eap |
| 385 | + response = self.client.get(f'/api/v2/eap-activation-report/{report1.id}/').json() |
| 386 | + self.assertEqual(response['created_by'], user1.id) |
| 387 | + self.assertEqual(response['id'], report1.id) |
| 388 | + |
| 389 | + # try with another user |
| 390 | + user2 = User.objects.create(username='xyz') |
| 391 | + self.client.force_authenticate(user=user2) |
| 392 | + report4, report5 = EAPActivationReportFactory.create_batch(2, created_by=user2) |
| 393 | + response2 = self.client.get('/api/v2/eap-activation-report/').json() |
| 394 | + self.assertEqual(response2['results'][0]['created_by'], user2.id) |
| 395 | + self.assertIn(report4.id, [data['id'] for data in response2['results']]) |
| 396 | + self.assertNotIn([data['id'] for data in response2['results']], [data['id'] for data in response1['results']]) |
| 397 | + |
| 398 | + # try with users who has no any eap created |
| 399 | + user3 = User.objects.create(username='ram') |
| 400 | + self.client.force_authenticate(user=user3) |
| 401 | + response3 = self.client.get('/api/v2/eap-activation-report/').json() |
| 402 | + self.assertEqual(response3['count'], 5) |
| 403 | + |
| 404 | + def test_eap_upload_multiple_file(self): |
| 405 | + file_count = EAPDocument.objects.count() |
| 406 | + url = '/api/v2/eap-file/multiple/' |
| 407 | + data = { |
| 408 | + 'file': [open(self.file, 'rb'), open(self.file, 'rb'), open(self.file, 'rb')] |
| 409 | + } |
| 410 | + |
| 411 | + self.authenticate() |
| 412 | + response = self.client.post(url, data, format='multipart') |
| 413 | + self.assert_201(response) |
| 414 | + self.assertEqual(EAPDocument.objects.count(), file_count + 3) |
| 415 | + |
0 commit comments