Fakultas Ilmu Komputer UI

Commit 7e1f0a7f authored by Dave Nathanael's avatar Dave Nathanael
Browse files

[RED] Add test for csv file export endpoint

parent e01f43ab
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):
......@@ -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)
'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(len(body), 5)
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