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
89e461fd
Commit
89e461fd
authored
Apr 18, 2020
by
Dave Nathanael
Browse files
[RED] Add test for new CaseSubject and InvestigationCAse
parent
bd7e66c3
Pipeline
#41131
failed with stages
in 2 minutes and 9 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/cases/tests/test_units/test_case_subjects.py
View file @
89e461fd
...
...
@@ -48,6 +48,7 @@ class CaseSubjectViewTest(APITestCase):
url
=
self
.
BASE_URL
response
=
self
.
client
.
get
(
url
)
response
.
data
.
results
[
0
].
pop
(
"created_at"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
data
=
{
"count"
:
1
,
...
...
@@ -121,6 +122,7 @@ class CaseSubjectViewTest(APITestCase):
url
=
self
.
BASE_URL
+
str
(
self
.
case_subject_1
.
id
)
+
"/"
response
=
self
.
client
.
get
(
url
)
response
.
data
.
pop
(
"created_at"
)
data
=
{
"id"
:
str
(
self
.
case_subject_1
.
id
),
...
...
@@ -200,10 +202,10 @@ class CaseSubjectViewTest(APITestCase):
case_subject_history_prev_count
=
CaseSubjectHistory
.
objects
.
all
().
count
()
response
=
self
.
client
.
put
(
path
=
url
,
data
=
data
,
format
=
"json"
,)
response
.
data
.
pop
(
"
id
"
)
response
.
data
.
pop
(
"
created_at
"
)
case_subject_
prev
_count
=
CaseSubject
.
objects
.
all
().
count
()
case_subject_history_
prev
_count
=
CaseSubjectHistory
.
objects
.
all
().
count
()
case_subject_
current
_count
=
CaseSubject
.
objects
.
all
().
count
()
case_subject_history_
current
_count
=
CaseSubjectHistory
.
objects
.
all
().
count
()
self
.
assertJSONEqual
(
json
.
dumps
(
response
.
data
),
data
)
self
.
assertEqual
(
...
...
apps/cases/tests/test_units/test_investigation_cases.py
View file @
89e461fd
...
...
@@ -6,7 +6,7 @@ from rest_framework.authtoken.models import Token
from
rest_framework.test
import
APITestCase
,
APIClient
from
apps.accounts.tests.factories.accounts
import
AccountFactory
,
UserFactory
from
apps.cases.models
import
InvestigationCase
from
apps.cases.models
import
InvestigationCase
,
InvestigationCaseHistory
from
apps.cases.tests.factories.case_subjects
import
CaseSubjectFactory
from
apps.cases.tests.factories.cases
import
InvestigationCaseFactory
...
...
@@ -23,7 +23,7 @@ class InvestigationCaseViewTest(APITestCase):
@
classmethod
def
setUpTestData
(
self
):
self
.
BASE_URL
=
"/cases/investigation-cases/"
self
.
BASE_POSITIVE_URL
=
"/cases/
investigation-cases/
positive-cases/"
self
.
BASE_POSITIVE_URL
=
"/cases/positive-cases/"
self
.
user_1
=
UserFactory
(
username
=
"user_1"
,
password
=
"justpass"
)
self
.
author
=
AccountFactory
(
user
=
self
.
user_1
,
admin
=
True
)
...
...
@@ -31,19 +31,19 @@ class InvestigationCaseViewTest(APITestCase):
self
.
case_subject
=
CaseSubjectFactory
()
self
.
reference_case
=
InvestigationCaseFactory
(
case_subject
_id
=
self
.
case_subject
.
subject_id
,
case_subject
=
self
.
case_subject
,
author
=
self
.
author
,
outcome
=
"BTA+"
,
)
self
.
case
=
InvestigationCaseFactory
(
author
=
self
.
author
,
case_subject
_id
=
self
.
case_subject
.
subject_id
,
reference_case
_id
=
self
.
reference_case
.
case_id
,
case_subject
=
self
.
case_subject
,
reference_case
=
self
.
reference_case
,
)
self
.
other_deleted_case
=
InvestigationCaseFactory
(
author
=
self
.
author
,
case_subject
_id
=
self
.
case_subject
.
subject_id
,
reference_case
_id
=
self
.
reference_case
.
case_id
,
case_subject
=
self
.
case_subject
,
reference_case
=
self
.
reference_case
,
deleted_at
=
datetime
.
now
(
tz
=
pytz
.
timezone
(
TIMEZONE
)),
)
...
...
@@ -52,7 +52,7 @@ class InvestigationCaseViewTest(APITestCase):
def
test_string_representation
(
self
):
active_case_str
=
(
f
"[Active] ID.
{
self
.
case
.
revision_
id
}
| by
{
self
.
case
.
author
}
"
f
"[Active] ID.
{
self
.
case
.
id
}
| by
{
self
.
case
.
author
}
"
)
self
.
assertEqual
(
active_case_str
,
str
(
self
.
case
))
...
...
@@ -67,12 +67,9 @@ class InvestigationCaseViewTest(APITestCase):
self
.
assertIn
(
'"count":1'
,
response_string
)
self
.
assertIn
(
'"next":null'
,
response_string
)
self
.
assertIn
(
'"previous":null'
,
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
revision_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
case_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
case_subject
.
revision_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
case_subject
.
subject_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
reference_case
.
revision_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
reference_case
.
case_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
case_subject
.
id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
reference_case
.
id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
reference_case
.
author
.
id
),
response_string
)
self
.
assertIn
(
str
(
self
.
case
.
author
.
id
),
response_string
)
...
...
@@ -97,10 +94,8 @@ class InvestigationCaseViewTest(APITestCase):
self
.
assertIn
(
'"count":1'
,
response_string
)
self
.
assertIn
(
'"next":null'
,
response_string
)
self
.
assertIn
(
'"previous":null'
,
response_string
)
self
.
assertIn
(
str
(
self
.
reference_case
.
revision_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
reference_case
.
case_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
reference_case
.
case_subject
.
revision_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
reference_case
.
case_subject
.
subject_id
),
response_string
)
self
.
assertIn
(
str
(
self
.
reference_case
.
id
),
response_string
)
self
.
assertIn
(
str
(
self
.
reference_case
.
case_subject
.
id
),
response_string
)
self
.
assertIn
(
str
(
self
.
reference_case
.
author
.
id
),
response_string
)
def
test_list_positive_investigation_case_paginate_failed
(
self
):
...
...
@@ -133,14 +128,34 @@ class InvestigationCaseViewTest(APITestCase):
self
.
assertIn
(
'"count":0'
,
response_string
)
def
test_list_investigation_cases_search_success
(
self
):
url
=
self
.
BASE_URL
+
"?search="
+
self
.
case
.
risk_factors
[:
-
1
]
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
response_string
=
response
.
rendered_content
.
decode
(
"utf-8"
)
self
.
assertIn
(
'"count":1'
,
response_string
)
def
test_list_investigation_cases_search_failed
(
self
):
url
=
self
.
BASE_URL
+
"?search=1234567890"
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
response_string
=
response
.
rendered_content
.
decode
(
"utf-8"
)
self
.
assertIn
(
'"count":0'
,
response_string
)
def
test_retrieve_investigation_case_success
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
case
.
revision_
id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
case
.
id
)
+
"/"
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
def
test_retrieve_investigation_case_fails_on_deleted_subject
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
other_deleted_case
.
revision_
id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
other_deleted_case
.
id
)
+
"/"
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
)
...
...
@@ -148,15 +163,13 @@ class InvestigationCaseViewTest(APITestCase):
def
test_create_new_investigation_case_success
(
self
):
url
=
self
.
BASE_URL
case_subject_prev_active_count
=
(
InvestigationCase
.
objects
.
active_revisions
().
count
()
)
case_prev_all_count
=
InvestigationCase
.
objects
.
all
().
count
()
investigation_case_prev_count
=
InvestigationCase
.
objects
.
all
().
count
()
investigation_case_history_prev_count
=
InvestigationCaseHistory
.
objects
.
all
().
count
()
data
=
{
"reference_case
_id
"
:
str
(
self
.
reference_case
.
case_
id
),
"reference_case"
:
str
(
self
.
reference_case
.
id
),
"case_relation"
:
self
.
case
.
case_relation
,
"case_subject
_id
"
:
str
(
self
.
case
.
case_subject
.
subject_
id
),
"case_subject"
:
str
(
self
.
case
.
case_subject
.
id
),
"medical_symptoms"
:
self
.
case
.
medical_symptoms
,
"risk_factors"
:
self
.
case
.
risk_factors
,
"is_referral_needed"
:
self
.
case
.
is_referral_needed
,
...
...
@@ -164,25 +177,17 @@ class InvestigationCaseViewTest(APITestCase):
}
response
=
self
.
client
.
post
(
path
=
url
,
data
=
data
,
format
=
"json"
,)
case_current_
active_
count
=
InvestigationCase
.
objects
.
a
ctive_revisions
().
count
()
case
_current_
all_
count
=
InvestigationCase
.
objects
.
all
().
count
()
investigation_
case_current_count
=
InvestigationCase
.
objects
.
a
ll
().
count
()
investigation_case_history
_current_count
=
InvestigationCase
History
.
objects
.
all
().
count
()
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
self
.
assertEqual
(
case_current_active_count
,
case_subject_prev_active_count
+
1
)
self
.
assertEqual
(
case_current_all_count
,
case_prev_all_count
+
1
)
# Have investigation case creation log
logs_response
=
self
.
client
.
get
(
"/logs/"
)
response_string
=
logs_response
.
rendered_content
.
decode
(
"utf-8"
)
self
.
assertIn
(
'"object_id":"{}"'
.
format
(
response
.
data
[
"case_id"
]),
response_string
)
self
.
assertIn
(
'"revision_id":"{}"'
.
format
(
response
.
data
[
"revision_id"
]),
response_string
self
.
assertEqual
(
investigation_case_current_count
,
investigation_case_prev_count
+
1
)
self
.
assertIn
(
'"action_type":"{}"'
.
format
(
ACTIVITY_TYPE_CREATE
),
response_string
# New InvestigationCaseHistory added
self
.
assertEqual
(
investigation_case_history_current_count
,
investigation_case_history_prev_count
+
1
)
def
test_create_new_investigation_case_fails_with_incomplete_data
(
self
):
...
...
@@ -196,23 +201,20 @@ class InvestigationCaseViewTest(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
test_edit_investigation_success
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
case
.
revision_
id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
case
.
id
)
+
"/"
data
=
{
"case_subject
_id
"
:
str
(
self
.
case_subject
.
subject_
id
),
"reference_case
_id
"
:
str
(
self
.
reference_case
.
case_
id
),
"case_subject"
:
str
(
self
.
case_subject
.
id
),
"reference_case"
:
str
(
self
.
reference_case
.
id
),
"case_relation"
:
self
.
case
.
case_relation
,
"medical_symptoms"
:
self
.
case
.
medical_symptoms
,
"risk_factors"
:
self
.
case
.
risk_factors
,
"is_referral_needed"
:
not
self
.
case
.
is_referral_needed
,
"medical_facility_reference"
:
self
.
case
.
medical_facility_reference
,
}
prev_all_investigation_case_revision_count
=
(
InvestigationCase
.
objects
.
all
().
count
()
)
prev_active_investigation_case_revision_count
=
(
InvestigationCase
.
objects
.
active_revisions
().
count
()
)
investigation_case_prev_count
=
InvestigationCase
.
objects
.
all
().
count
()
investigation_case_history_prev_count
=
InvestigationCaseHistory
.
objects
.
all
().
count
()
response
=
self
.
client
.
put
(
path
=
url
,
data
=
data
,
format
=
"json"
,)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
...
...
@@ -220,86 +222,66 @@ class InvestigationCaseViewTest(APITestCase):
response
.
data
[
"is_referral_needed"
],
not
self
.
case
.
is_referral_needed
)
current_investigation_case_revision_count
=
(
InvestigationCase
.
objects
.
all
().
count
()
)
current_active_investigation_case_revision_count
=
(
InvestigationCase
.
objects
.
active_revisions
().
count
()
)
investigation_case_current_count
=
InvestigationCase
.
objects
.
all
().
count
()
investigation_case_history_current_count
=
InvestigationCaseHistory
.
objects
.
all
().
count
()
self
.
assertEqual
(
current_investigation_case_revision_count
,
prev_all_investigation_case_revision_count
+
1
,
)
self
.
assertEqual
(
current_active_investigation_case_revision_count
,
prev_active_investigation_case_revision_count
,
investigation_case_current_count
,
investigation_case_prev_count
)
# Have investigation case update log
response
=
self
.
client
.
get
(
"/logs/"
)
response_string
=
response
.
rendered_content
.
decode
(
"utf-8"
)
self
.
assertIn
(
'"object_id":"{}"'
.
format
(
self
.
case
.
case_id
),
response_string
)
self
.
assertIn
(
'"revision_id":"{}"'
.
format
(
self
.
case
.
revision_id
),
response_string
# New InvestigationCaseHistory added
self
.
assertEqual
(
investigation_case_history_current_count
,
investigation_case_history_prev_count
+
1
)
self
.
assertIn
(
'"action_type":"{}"'
.
format
(
ACTIVITY_TYPE_EDIT
),
response_string
)
def
test_edit_investigation_case_fails_with_incomplete_data
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
case
.
revision_
id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
case
.
id
)
+
"/"
data
=
{
"medical_facility_reference"
:
"PUSKESMAS_X"
,
"case_subject_id"
:
None
,
}
prev_active_investigation_case_revision_count
=
(
InvestigationCase
.
objects
.
active_revisions
().
count
()
)
investigation_case_prev_count
=
InvestigationCase
.
objects
.
all
().
count
()
investigation_case_history_prev_count
=
InvestigationCaseHistory
.
objects
.
all
().
count
()
response
=
self
.
client
.
put
(
path
=
url
,
data
=
data
,
format
=
"json"
,)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
current_active_investigation_case_revision_count
=
(
InvestigationCase
.
objects
.
active_revisions
().
count
()
investigation_case_current_count
=
InvestigationCase
.
objects
.
all
().
count
()
investigation_case_history_current_count
=
InvestigationCaseHistory
.
objects
.
all
().
count
()
self
.
assertEqual
(
investigation_case_current_count
,
investigation_case_prev_count
)
# No new InvestigationCaseHistory added
self
.
assertEqual
(
current_active_investigation_case_revision_count
,
prev_active_investigation_case_revision_count
,
investigation_case_history_current_count
,
investigation_case_history_prev_count
)
def
test_soft_delete_investigation_case_success
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
case
.
revision_
id
)
+
"/"
url
=
self
.
BASE_URL
+
str
(
self
.
case
.
id
)
+
"/"
prev_deleted_all_count
=
InvestigationCase
.
objects
.
all
(
with_deleted
=
True
).
count
()
prev_deleted_count
=
InvestigationCase
.
objects
.
deleted
().
count
()
investigation_case_prev_count
=
InvestigationCase
.
objects
.
all
().
count
()
investigation_case_history_prev_count
=
InvestigationCaseHistory
.
objects
.
all
().
count
()
response
=
self
.
client
.
delete
(
path
=
url
,
format
=
"json"
,)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertIsNotNone
(
InvestigationCase
.
objects
.
all
(
with_deleted
=
True
)
.
filter
(
revision_
id
=
self
.
case
.
revision_
id
)
.
filter
(
id
=
self
.
case
.
id
)
.
first
()
)
current_deleted_all_count
=
InvestigationCase
.
objects
.
all
(
with_deleted
=
True
).
count
()
current_deleted_count
=
InvestigationCase
.
objects
.
deleted
().
count
()
self
.
assertEqual
(
current_deleted_all_count
,
prev_deleted_all_count
)
self
.
assertEqual
(
current_deleted_count
,
prev_deleted_count
+
1
)
investigation_case_current_count
=
InvestigationCase
.
objects
.
all
().
count
()
investigation_case_history_current_count
=
InvestigationCaseHistory
.
objects
.
all
().
count
()
# Have investigation case deletion log
response
=
self
.
client
.
get
(
"/logs/"
)
response_string
=
response
.
rendered_content
.
decode
(
"utf-8"
)
self
.
assertIn
(
'"object_id":"{}"'
.
format
(
self
.
case
.
case_id
),
response_string
)
self
.
assertIn
(
'"revision_id":"{}"'
.
format
(
self
.
case
.
revision_id
),
response_string
self
.
assertEqual
(
investigation_case_current_count
,
investigation_case_prev_count
-
1
)
self
.
assertIn
(
'"action_type":"{}"'
.
format
(
ACTIVITY_TYPE_DELETE
),
response_string
# New InvestigationCaseHistory added
self
.
assertEqual
(
investigation_case_history_current_count
,
investigation_case_history_prev_count
+
1
)
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