Fakultas Ilmu Komputer UI

Commit 3d59a9dd authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

[RED] Add test for exportables (statistics feeder)

parent 4dfef732
Pipeline #47429 failed with stages
in 1 minute and 44 seconds
......@@ -24,6 +24,7 @@ class InvestigationCaseFactory(factory.DjangoModelFactory):
author = factory.SubFactory(AccountFactory)
case_subject = factory.SubFactory(CaseSubjectFactory)
author = factory.SubFactory(AccountFactory)
is_positive = None
class MonitoringCaseFactory(factory.DjangoModelFactory):
......
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ExportablesConfig(AppConfig):
name = 'exportables'
from django.db import models
# Create your models here.
import json
from rest_framework import status
from rest_framework.test import APITestCase
from apps.cases.models import CaseSubject
from apps.cases.tests.factories.case_subjects import CaseSubjectFactory
from apps.cases.tests.factories.cases import InvestigationCaseFactory
class ExportableViewTest(APITestCase):
@classmethod
def setUpTestData(cls):
InvestigationCaseFactory(
case_subject=CaseSubjectFactory(
district="Beji",
age=19,
is_male=True,
),
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,
)
def test_exportable_data_return_values(self):
url = "/exportables/"
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = {
"age": {
"19": {
"positive": 1,
"negative": 0,
"undetermined": 0,
"total_count": 1
},
"20": {
"positive": 1,
"negative": 0,
"undetermined": 0,
"total_count": 1
},
"21": {
"positive": 0,
"negative": 2,
"undetermined": 0,
"total_count": 2
},
"22": {
"positive": 0,
"negative": 0,
"undetermined": 1,
"total_count": 1
}
},
"district": {
"Beji": {
"positive": 1,
"negative": 0,
"undetermined": 0,
"total_count": 1
},
"Bojongsari": {
"positive": 0,
"negative": 0,
"undetermined": 0,
"total_count": 0
},
"Cilodong": {
"positive": 1,
"negative": 0,
"undetermined": 0,
"total_count": 1
},
"Cimanggis": {
"positive": 0,
"negative": 0,
"undetermined": 0,
"total_count": 0
},
"Cinere": {
"positive": 0,
"negative": 0,
"undetermined": 0,
"total_count": 0
},
"Cipayung": {
"positive": 0,
"negative": 0,
"undetermined": 0,
"total_count": 0
},
"Limo": {
"positive": 0,
"negative": 0,
"undetermined": 0,
"total_count": 0
},
"Pancoran Mas": {
"positive": 0,
"negative": 0,
"undetermined": 0,
"total_count": 0
},
"Sawangan": {
"positive": 0,
"negative": 0,
"undetermined": 1,
"total_count": 1
},
"Sukmajaya": {
"positive": 0,
"negative": 0,
"undetermined": 0,
"total_count": 0
},
"Tapos": {
"positive": 0,
"negative": 1,
"undetermined": 0,
"total_count": 1
},
"Unknown": {
"positive": 0,
"negative": 1,
"undetermined": 0,
"total_count": 1
}
},
"sex": {
"male": {
"positive": 1,
"negative": 1,
"undetermined": 1,
"total_count": 3
},
"female": {
"positive": 1,
"negative": 1,
"undetermined": 0,
"total_count": 2
}
},
"total_count": 5
}
self.assertJSONEqual(response.content, data)
from django.shortcuts import render
# Create your views here.
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