Fakultas Ilmu Komputer UI

Commit aa428e5a authored by Dave Nathanael's avatar Dave Nathanael
Browse files

[GREEN] Add tests for CSV export wrong query params

parent 0373138d
......@@ -10,11 +10,8 @@ from apps.cases.tests.factories.cases import InvestigationCaseFactory
from apps.exportables.renderers import INVESTIGATION_CASE_RENDERER_FIELDS
class ExportableViewTest(APITestCase):
@classmethod
def setUpTestData(cls):
InvestigationCaseFactory(
def init_data():
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Beji",
age=19,
......@@ -22,38 +19,44 @@ class ExportableViewTest(APITestCase):
),
is_positive=True,
)
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Cilodong",
age=20,
is_male=False,
),
is_positive=True,
)
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Tapos",
age=21,
is_male=True,
),
is_positive=False,
)
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Unknown",
age=21,
is_male=False,
),
is_positive=False,
)
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Sawangan",
age=22,
is_male=True,
),
is_positive=None,
)
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Cilodong",
age=20,
is_male=False,
),
is_positive=True,
)
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Tapos",
age=21,
is_male=True,
),
is_positive=False,
)
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Unknown",
age=21,
is_male=False,
),
is_positive=False,
)
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Sawangan",
age=22,
is_male=True,
),
is_positive=None,
)
class ExportableViewTest(APITestCase):
@classmethod
def setUpTestData(cls):
init_data()
def test_exportable_data_return_values(self):
url = "/exportables/"
......@@ -181,8 +184,15 @@ class ExportableViewTest(APITestCase):
self.assertJSONEqual(response.content, data)
class ExportInvestigationCaseViewTest(APITestCase):
@classmethod
def setUpTestData(cls):
cls.BASE_URL = "/exportables/investigation-cases-csv/"
init_data()
def export_csv_test_util(self, filter):
url = "/exportables/investigation-cases-csv/" + filter
url = self.BASE_URL + filter
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
......@@ -199,6 +209,12 @@ class ExportableViewTest(APITestCase):
self.assertEqual(headers, INVESTIGATION_CASE_RENDERER_FIELDS)
return body
def wrong_query_param_test_util(self, filter):
url = self.BASE_URL + filter
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_export_investigation_data_to_csv_all(self):
body = self.export_csv_test_util("")
self.assertEqual(len(body), 5)
......@@ -214,3 +230,12 @@ class ExportableViewTest(APITestCase):
def test_export_investigation_data_to_csv_filter_district(self):
body = self.export_csv_test_util("?district=Beji")
self.assertEqual(len(body), 1)
def test_export_investigation_data_to_csv_wrong_gender_format(self):
self.wrong_query_param_test_util("?is_male=asdf")
def test_export_investigation_data_to_csv_wrong_min_age_format(self):
self.wrong_query_param_test_util("?min_age=abc&max_age=12")
def test_export_investigation_data_to_csv_wrong_max_age_format(self):
self.wrong_query_param_test_util("?min_age=10&max_age=asd")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment