Skip to content

Commit

Permalink
Removing some magic numbers from test
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelglenister committed Nov 21, 2023
1 parent 3e7ff1b commit 834a7e4
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions infrastructure/tests/test_data_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_file_upload(self):
fy = FinancialYear.objects.get(budget_year="2019/2020")

self.assertEquals(AnnualSpendFile.objects.all().count(), 0)
self.assertEqual(OrmQ.objects.count(), 0)
orm_count = OrmQ.objects.count()

# the app name, the name of the model and the name of the view
upload_url = reverse('admin:infrastructure_annualspendfile_add')
Expand All @@ -167,26 +167,23 @@ def test_file_upload(self):
resp = self.client.post(upload_url, {'financial_year': fy.pk, 'document': f}, follow=True)
self.assertContains(resp, "Dataset is currently being processed.", status_code=200)

spend_file = AnnualSpendFile.objects.first()
spend_file = AnnualSpendFile.objects.get(id=1)
self.assertEquals(spend_file.status, AnnualSpendFile.PROGRESS)

self.assertEqual(OrmQ.objects.count(), 1)
task = OrmQ.objects.first()
task_file_id = task.task()["args"][0]
self.assertEqual(OrmQ.objects.count(), orm_count + 1)
task = OrmQ.objects.get(id=orm_count+1)
task_method = task.func()
self.assertEqual(task_method, 'infrastructure.upload.process_annual_document')
self.assertEqual(task_file_id, spend_file.id)
self.assertEqual(task_method, "infrastructure.upload.process_annual_document")
# run the code
process_annual_document(task_file_id)

process_annual_document(spend_file.id)
self.assertEquals(AnnualSpendFile.objects.count(), 1)
spend_file = AnnualSpendFile.objects.first()
self.assertEquals(spend_file.status, AnnualSpendFile.SUCCESS)
self.assertEquals(Project.objects.count(), 2)

response = self.client.get("/api/v1/infrastructure/search/")
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'PC002003005_00002')
self.assertContains(response, "PC002003005_00002")


def test_file_upload_fail(self):
Expand Down

0 comments on commit 834a7e4

Please sign in to comment.