Fakultas Ilmu Komputer UI
Skip to content
GitLab
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
7e1f0a7f
Commit
7e1f0a7f
authored
May 27, 2020
by
Dave Nathanael
Browse files
[RED] Add test for csv file export endpoint
parent
e01f43ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
apps/exportables/tests/test_units/test_exportables.py
View file @
7e1f0a7f
import
json
import
csv
import
io
from
rest_framework
import
status
from
rest_framework.test
import
APITestCase
...
...
@@ -6,6 +8,8 @@ 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
class
ExportableViewTest
(
APITestCase
):
@
classmethod
...
...
@@ -176,3 +180,21 @@ class ExportableViewTest(APITestCase):
}
self
.
assertJSONEqual
(
response
.
content
,
data
)
def
test_export_investigation_data_to_csv_all
(
self
):
url
=
"/exportables/investigation-cases-csv/"
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
get
(
'Content-Disposition'
),
'attachment; filename="cases.csv"'
)
response_content
=
response
.
content
.
decode
(
'utf-8'
)
reader
=
csv
.
reader
(
io
.
StringIO
(
response_content
))
body
=
list
(
reader
)
headers
=
body
.
pop
(
0
)
self
.
assertEqual
(
headers
,
INVESTIGATION_CASE_RENDERER_FIELDS
)
self
.
assertEqual
(
len
(
body
),
5
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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