Fakultas Ilmu Komputer UI

Commit 6122aa02 authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

[RED] Change test to assert renamed fields

parent 4066c0ec
Pipeline #49748 failed with stages
in 1 minute and 30 seconds
......@@ -34,3 +34,39 @@ UNDETERMINED = "undetermined"
# Total
TOTAL = "total_count"
# CSV Fields
INVESTIGATION_CASE_RENDERER_FIELDS = [
"case_subject__name",
"case_subject__address",
"case_subject__age",
"case_subject__is_male",
"case_subject__district",
"case_subject__sub_district",
"case_relation",
"reference_case__case_subject__name",
"outcome",
"medical_symptoms",
"risk_factors",
"medical_facility_reference",
"created_at",
"author__name",
]
INVESTIGATION_CASE_HEADER_FIELDS = [
"nama",
"alamat",
"usia",
"jenis_kelamin",
"kabupaten",
"kecamatan",
"jenis_kontak",
"subyek_kasus_acuan",
"hasil_pemeriksaan",
"gejala_medis",
"faktor_risiko",
"rujukan_fasilitas_kesehatan",
"tanggal_pencatatan",
"kader_pencatat",
]
\ No newline at end of file
......@@ -2,13 +2,22 @@ import json
import csv
import io
from rest_framework import status
from rest_framework.test import APITestCase
from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase, APIClient
from apps.constants import HEADER_PREFIX
from apps.accounts.tests.factories.accounts import AccountFactory, UserFactory
from apps.cases.models import CaseSubject
from apps.cases.tests.factories.case_subjects import CaseSubjectFactory
from apps.cases.tests.factories.cases import InvestigationCaseFactory
from apps.exportables.renderers import INVESTIGATION_CASE_RENDERER_FIELDS
from apps.exportables.constants import (
INVESTIGATION_CASE_HEADER_FIELDS,
INVESTIGATION_CASE_RENDERER_FIELDS,
)
def init_data():
InvestigationCaseFactory(
......@@ -56,8 +65,15 @@ def init_data():
class ExportableViewTest(APITestCase):
@classmethod
def setUpTestData(cls):
cls.user = UserFactory(username="user", password="justpass")
cls.admin = AccountFactory(admin=True, user=cls.user)
cls.token, _ = Token.objects.get_or_create(user=cls.user)
init_data()
def setUp(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token.key)
def test_exportable_data_return_values(self):
url = "/exportables/"
response = self.client.get(url)
......@@ -188,9 +204,16 @@ class ExportableViewTest(APITestCase):
class ExportInvestigationCaseViewTest(APITestCase):
@classmethod
def setUpTestData(cls):
cls.user = UserFactory(username="user", password="justpass")
cls.admin = AccountFactory(admin=True, user=cls.user)
cls.token, _ = Token.objects.get_or_create(user=cls.user)
cls.BASE_URL = "/exportables/investigation-cases-csv/"
init_data()
def setUp(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token.key)
def export_csv_test_util(self, filter):
url = self.BASE_URL + filter
response = self.client.get(url)
......@@ -206,7 +229,7 @@ class ExportInvestigationCaseViewTest(APITestCase):
body = list(reader)
headers = body.pop(0)
self.assertEqual(headers, INVESTIGATION_CASE_RENDERER_FIELDS)
self.assertEqual(headers, INVESTIGATION_CASE_HEADER_FIELDS)
return body
def wrong_query_param_test_util(self, filter):
......
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