Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
b880ea57
Commit
b880ea57
authored
Jun 04, 2020
by
Jonathan Christopher Jakub
Browse files
[RED] Add authorized API client and change CSV header fields name on tests
parent
58377497
Pipeline
#49743
failed with stages
in 1 minute and 27 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/exportables/constants.py
View file @
b880ea57
...
@@ -34,3 +34,39 @@ UNDETERMINED = "undetermined"
...
@@ -34,3 +34,39 @@ UNDETERMINED = "undetermined"
# Total
# Total
TOTAL
=
"total_count"
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
apps/exportables/tests/test_units/test_exportables.py
View file @
b880ea57
...
@@ -2,13 +2,22 @@ import json
...
@@ -2,13 +2,22 @@ import json
import
csv
import
csv
import
io
import
io
from
rest_framework
import
status
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.models
import
CaseSubject
from
apps.cases.tests.factories.case_subjects
import
CaseSubjectFactory
from
apps.cases.tests.factories.case_subjects
import
CaseSubjectFactory
from
apps.cases.tests.factories.cases
import
InvestigationCaseFactory
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
():
def
init_data
():
InvestigationCaseFactory
(
InvestigationCaseFactory
(
...
@@ -56,8 +65,15 @@ def init_data():
...
@@ -56,8 +65,15 @@ def init_data():
class
ExportableViewTest
(
APITestCase
):
class
ExportableViewTest
(
APITestCase
):
@
classmethod
@
classmethod
def
setUpTestData
(
cls
):
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
()
init_data
()
def
setUp
(
self
):
self
.
client
=
APIClient
(
HTTP_AUTHORIZATION
=
HEADER_PREFIX
+
self
.
token
.
key
)
def
test_exportable_data_return_values
(
self
):
def
test_exportable_data_return_values
(
self
):
url
=
"/exportables/"
url
=
"/exportables/"
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
url
)
...
@@ -188,9 +204,16 @@ class ExportableViewTest(APITestCase):
...
@@ -188,9 +204,16 @@ class ExportableViewTest(APITestCase):
class
ExportInvestigationCaseViewTest
(
APITestCase
):
class
ExportInvestigationCaseViewTest
(
APITestCase
):
@
classmethod
@
classmethod
def
setUpTestData
(
cls
):
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/"
cls
.
BASE_URL
=
"/exportables/investigation-cases-csv/"
init_data
()
init_data
()
def
setUp
(
self
):
self
.
client
=
APIClient
(
HTTP_AUTHORIZATION
=
HEADER_PREFIX
+
self
.
token
.
key
)
def
export_csv_test_util
(
self
,
filter
):
def
export_csv_test_util
(
self
,
filter
):
url
=
self
.
BASE_URL
+
filter
url
=
self
.
BASE_URL
+
filter
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
url
)
...
@@ -206,7 +229,7 @@ class ExportInvestigationCaseViewTest(APITestCase):
...
@@ -206,7 +229,7 @@ class ExportInvestigationCaseViewTest(APITestCase):
body
=
list
(
reader
)
body
=
list
(
reader
)
headers
=
body
.
pop
(
0
)
headers
=
body
.
pop
(
0
)
self
.
assertEqual
(
headers
,
INVESTIGATION_CASE_
RENDER
ER_FIELDS
)
self
.
assertEqual
(
headers
,
INVESTIGATION_CASE_
HEAD
ER_FIELDS
)
return
body
return
body
def
wrong_query_param_test_util
(
self
,
filter
):
def
wrong_query_param_test_util
(
self
,
filter
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment