Skip to content

Commit

Permalink
tests: Add test_api
Browse files Browse the repository at this point in the history
- Add some basic tests for the dashboard overview api
- Update test_data to contain the quality data
  • Loading branch information
michaelwood committed May 19, 2022
1 parent e1c637b commit a9dd12d
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datastore/db/fixtures/test_data.json

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions datastore/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from django.urls import reverse_lazy
from django.test import TestCase
from django.core.management import call_command


class DashBoardAPITests(TestCase):
@classmethod
def setUpTestData(cls):
call_command("loaddata", "test_data.json")

def test_dashboard_api_overview_grants(self):
expected_data = {
"aggregate": {
"total": {
"grants": 50,
"GBP": 26350.0,
"publishers": 10,
"recipients": 1,
"funders": 1,
},
"jsonFiles": 0,
"csvFiles": 0,
"xlsxFiles": 100,
"odsFiles": 0,
"awardYears": {
"2022": 0,
"2021": 0,
"2020": 0,
"2019": 50,
"2018": 0,
"2017": 0,
"2016": 0,
"2015": 0,
"2014": 0,
"2013": 0,
},
"orgIdTypes": {},
"awardedThisYear": 0,
"awardedLastThreeMonths": 0,
},
"quality": {
"hasBeneficiaryLocationName": 100,
"hasRecipientOrgLocations": 100,
"hasGrantDuration": 100,
"hasGrantProgrammeTitle": 100,
"hasGrantClassification": 0,
"hasBeneficiaryLocationGeoCode": 100,
"hasRecipientOrgCompanyOrCharityNumber": 0,
"has50pcExternalOrgId": 0,
},
}

data = self.client.get(reverse_lazy("api:overview") + "?mode=grants").json()

self.assertEqual(data, expected_data)

def test_dashboard_api_overview_publishers(self):
expected_data = {
"aggregate": {
"total": {
"grants": 50,
"GBP": 26350.0,
"publishers": 10,
"recipients": 1,
"funders": 1,
},
"jsonFiles": 0,
"csvFiles": 0,
"xlsxFiles": 100,
"odsFiles": 0,
"publishedThisYear": 0,
"publishedLastThreeMonths": 0,
"awardYears": {
"2022": 0,
"2021": 0,
"2020": 0,
"2019": 100,
"2018": 0,
"2017": 0,
"2016": 0,
"2015": 0,
"2014": 0,
"2013": 0,
},
"recipientsExternalOrgId": {
"0% - 10%": 100.0,
"10% - 20%": 0.0,
"20% - 30%": 0.0,
"30% - 40%": 0.0,
"40% - 50%": 0.0,
"50% - 60%": 0.0,
"60% - 70%": 0.0,
"70% - 80%": 0.0,
"90% - 100%": 0.0,
},
},
"quality": {
"hasBeneficiaryLocationName": 100,
"hasRecipientOrgLocations": 100,
"hasGrantDuration": 100,
"hasGrantProgrammeTitle": 100,
"hasGrantClassification": 0,
"hasBeneficiaryLocationGeoCode": 100,
"hasRecipientOrgCompanyOrCharityNumber": 0,
"has50pcExternalOrgId": 0,
},
}

data = self.client.get(reverse_lazy("api:overview") + "?mode=publishers").json()

self.assertEqual(data, expected_data)

0 comments on commit a9dd12d

Please sign in to comment.