Fakultas Ilmu Komputer UI

Commit 04d73955 authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

[REFACTOR] Improve code stylings

parent 7ecdc3f4
Pipeline #39019 passed with stages
in 33 minutes and 11 seconds
...@@ -43,6 +43,6 @@ class Migration(migrations.Migration): ...@@ -43,6 +43,6 @@ class Migration(migrations.Migration):
), ),
), ),
], ],
options={"verbose_name_plural": "accounts", "db_table": "account", }, options={"verbose_name_plural": "accounts", "db_table": "account",},
), ),
] ]
...@@ -137,11 +137,13 @@ class AccountViewTest(APITestCase): ...@@ -137,11 +137,13 @@ class AccountViewTest(APITestCase):
# Have account creation log for the new officer # Have account creation log for the new officer
new_officer_id = Account.objects.filter(email=_account_id)[0].id new_officer_id = Account.objects.filter(email=_account_id)[0].id
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(new_officer_id), response_string) self.assertIn('"object_id":"{}"'.format(new_officer_id), response_string)
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string) self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string
)
def test_create_new_account_fails_with_no_auth_info(self): def test_create_new_account_fails_with_no_auth_info(self):
url = self.BASE_URL url = self.BASE_URL
...@@ -185,7 +187,7 @@ class AccountViewTest(APITestCase): ...@@ -185,7 +187,7 @@ class AccountViewTest(APITestCase):
) )
# Have account update log # Have account update log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.officer.id), response_string) self.assertIn('"object_id":"{}"'.format(self.officer.id), response_string)
...@@ -211,8 +213,10 @@ class AccountViewTest(APITestCase): ...@@ -211,8 +213,10 @@ class AccountViewTest(APITestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
# Have account deletion log # Have account deletion log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.officer.id), response_string) self.assertIn('"object_id":"{}"'.format(self.officer.id), response_string)
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string) self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string
)
...@@ -20,7 +20,7 @@ from apps.constants import ( ...@@ -20,7 +20,7 @@ from apps.constants import (
MODEL_NAME_ACCOUNT, MODEL_NAME_ACCOUNT,
ACTIVITY_TYPE_CREATE, ACTIVITY_TYPE_CREATE,
ACTIVITY_TYPE_EDIT, ACTIVITY_TYPE_EDIT,
ACTIVITY_TYPE_DELETE ACTIVITY_TYPE_DELETE,
) )
......
...@@ -150,12 +150,18 @@ class CaseSubjectViewTest(APITestCase): ...@@ -150,12 +150,18 @@ class CaseSubjectViewTest(APITestCase):
) )
# Have case subject creation log # Have case subject creation log
logs_response = self.client.get('/logs/') logs_response = self.client.get("/logs/")
response_string = logs_response.rendered_content.decode("utf-8") response_string = logs_response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(response.data['subject_id']), response_string) self.assertIn(
self.assertIn('"revision_id":"{}"'.format(response.data['revision_id']), response_string) '"object_id":"{}"'.format(response.data["subject_id"]), response_string
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string) )
self.assertIn(
'"revision_id":"{}"'.format(response.data["revision_id"]), response_string
)
self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string
)
def test_create_new_case_subject_fails_with_incomplete_data(self): def test_create_new_case_subject_fails_with_incomplete_data(self):
url = self.BASE_URL url = self.BASE_URL
...@@ -208,11 +214,16 @@ class CaseSubjectViewTest(APITestCase): ...@@ -208,11 +214,16 @@ class CaseSubjectViewTest(APITestCase):
) )
# Have case subject update log # Have case subject update log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.case_subject_1.subject_id), response_string) self.assertIn(
self.assertIn('"revision_id":"{}"'.format(self.case_subject_1.revision_id), response_string) '"object_id":"{}"'.format(self.case_subject_1.subject_id), response_string
)
self.assertIn(
'"revision_id":"{}"'.format(self.case_subject_1.revision_id),
response_string,
)
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string) self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string)
def test_edit_case_subject_fails_with_incomplete_data(self): def test_edit_case_subject_fails_with_incomplete_data(self):
...@@ -255,12 +266,19 @@ class CaseSubjectViewTest(APITestCase): ...@@ -255,12 +266,19 @@ class CaseSubjectViewTest(APITestCase):
self.assertEqual(current_deleted_count, prev_deleted_count + 1) self.assertEqual(current_deleted_count, prev_deleted_count + 1)
# Have case subject deletion log # Have case subject deletion log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.case_subject_1.subject_id), response_string) self.assertIn(
self.assertIn('"revision_id":"{}"'.format(self.case_subject_1.revision_id), response_string) '"object_id":"{}"'.format(self.case_subject_1.subject_id), response_string
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string) )
self.assertIn(
'"revision_id":"{}"'.format(self.case_subject_1.revision_id),
response_string,
)
self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string
)
def test_delete_inactive_case_subject_fails(self): def test_delete_inactive_case_subject_fails(self):
url = self.BASE_URL + str(self.case_subject_3.revision_id) + "/" url = self.BASE_URL + str(self.case_subject_3.revision_id) + "/"
......
...@@ -145,12 +145,18 @@ class InvestigationCaseViewTest(APITestCase): ...@@ -145,12 +145,18 @@ class InvestigationCaseViewTest(APITestCase):
self.assertEqual(case_current_all_count, case_prev_all_count + 1) self.assertEqual(case_current_all_count, case_prev_all_count + 1)
# Have investigation case creation log # Have investigation case creation log
logs_response = self.client.get('/logs/') logs_response = self.client.get("/logs/")
response_string = logs_response.rendered_content.decode("utf-8") response_string = logs_response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(response.data['case_id']), response_string) self.assertIn(
self.assertIn('"revision_id":"{}"'.format(response.data['revision_id']), response_string) '"object_id":"{}"'.format(response.data["case_id"]), response_string
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string) )
self.assertIn(
'"revision_id":"{}"'.format(response.data["revision_id"]), response_string
)
self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string
)
def test_create_new_investigation_case_fails_with_incomplete_data(self): def test_create_new_investigation_case_fails_with_incomplete_data(self):
url = self.BASE_URL url = self.BASE_URL
...@@ -207,11 +213,13 @@ class InvestigationCaseViewTest(APITestCase): ...@@ -207,11 +213,13 @@ class InvestigationCaseViewTest(APITestCase):
) )
# Have investigation case update log # Have investigation case update log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.case.case_id), response_string) self.assertIn('"object_id":"{}"'.format(self.case.case_id), response_string)
self.assertIn('"revision_id":"{}"'.format(self.case.revision_id), response_string) self.assertIn(
'"revision_id":"{}"'.format(self.case.revision_id), response_string
)
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string) self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string)
def test_edit_inactive_investigation_case_fails(self): def test_edit_inactive_investigation_case_fails(self):
...@@ -279,12 +287,16 @@ class InvestigationCaseViewTest(APITestCase): ...@@ -279,12 +287,16 @@ class InvestigationCaseViewTest(APITestCase):
self.assertEqual(current_deleted_count, prev_deleted_count + 1) self.assertEqual(current_deleted_count, prev_deleted_count + 1)
# Have investigation case deletion log # Have investigation case deletion log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.case.case_id), response_string) self.assertIn('"object_id":"{}"'.format(self.case.case_id), response_string)
self.assertIn('"revision_id":"{}"'.format(self.case.revision_id), response_string) self.assertIn(
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string) '"revision_id":"{}"'.format(self.case.revision_id), response_string
)
self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string
)
def test_delete_inactive_investigation_case_fails(self): def test_delete_inactive_investigation_case_fails(self):
url = self.BASE_URL + str(self.other_inactive_case.revision_id) + "/" url = self.BASE_URL + str(self.other_inactive_case.revision_id) + "/"
......
...@@ -135,12 +135,18 @@ class MonitoringCaseViewTest(APITestCase): ...@@ -135,12 +135,18 @@ class MonitoringCaseViewTest(APITestCase):
self.assertEqual(case_current_all_count, case_prev_all_count + 1) self.assertEqual(case_current_all_count, case_prev_all_count + 1)
# Have monitoring case creation log # Have monitoring case creation log
logs_response = self.client.get('/logs/') logs_response = self.client.get("/logs/")
response_string = logs_response.rendered_content.decode("utf-8") response_string = logs_response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(response.data['case_id']), response_string) self.assertIn(
self.assertIn('"revision_id":"{}"'.format(response.data['revision_id']), response_string) '"object_id":"{}"'.format(response.data["case_id"]), response_string
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string) )
self.assertIn(
'"revision_id":"{}"'.format(response.data["revision_id"]), response_string
)
self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string
)
def test_edit_monitoring_case_success(self): def test_edit_monitoring_case_success(self):
url = self.BASE_URL + str(self.case_1.revision_id) + "/" url = self.BASE_URL + str(self.case_1.revision_id) + "/"
...@@ -177,11 +183,13 @@ class MonitoringCaseViewTest(APITestCase): ...@@ -177,11 +183,13 @@ class MonitoringCaseViewTest(APITestCase):
) )
# Have monitoring case update log # Have monitoring case update log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.case_1.case_id), response_string) self.assertIn('"object_id":"{}"'.format(self.case_1.case_id), response_string)
self.assertIn('"revision_id":"{}"'.format(self.case_1.revision_id), response_string) self.assertIn(
'"revision_id":"{}"'.format(self.case_1.revision_id), response_string
)
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string) self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string)
def test_edit_inactive_monitoring_case_fails(self): def test_edit_inactive_monitoring_case_fails(self):
...@@ -220,12 +228,16 @@ class MonitoringCaseViewTest(APITestCase): ...@@ -220,12 +228,16 @@ class MonitoringCaseViewTest(APITestCase):
) )
# Have monitoring case deletion log # Have monitoring case deletion log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.case_1.case_id), response_string) self.assertIn('"object_id":"{}"'.format(self.case_1.case_id), response_string)
self.assertIn('"revision_id":"{}"'.format(self.case_1.revision_id), response_string) self.assertIn(
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string) '"revision_id":"{}"'.format(self.case_1.revision_id), response_string
)
self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string
)
def test_delete_inactive_monitoring_case_fails(self): def test_delete_inactive_monitoring_case_fails(self):
url = self.BASE_URL + str(self.other_inactive_case.revision_id) + "/" url = self.BASE_URL + str(self.other_inactive_case.revision_id) + "/"
......
...@@ -124,12 +124,18 @@ class PositiveCaseViewTest(APITestCase): ...@@ -124,12 +124,18 @@ class PositiveCaseViewTest(APITestCase):
self.assertEqual(case_current_all_count, case_prev_all_count + 1) self.assertEqual(case_current_all_count, case_prev_all_count + 1)
# Have positive case creation log # Have positive case creation log
logs_response = self.client.get('/logs/') logs_response = self.client.get("/logs/")
response_string = logs_response.rendered_content.decode("utf-8") response_string = logs_response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(response.data['case_id']), response_string) self.assertIn(
self.assertIn('"revision_id":"{}"'.format(response.data['revision_id']), response_string) '"object_id":"{}"'.format(response.data["case_id"]), response_string
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string) )
self.assertIn(
'"revision_id":"{}"'.format(response.data["revision_id"]), response_string
)
self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_CREATE), response_string
)
def test_create_new_positive_case_fails_with_incomplete_data(self): def test_create_new_positive_case_fails_with_incomplete_data(self):
url = self.BASE_URL url = self.BASE_URL
...@@ -175,11 +181,13 @@ class PositiveCaseViewTest(APITestCase): ...@@ -175,11 +181,13 @@ class PositiveCaseViewTest(APITestCase):
) )
# Have positive case update log # Have positive case update log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.case.case_id), response_string) self.assertIn('"object_id":"{}"'.format(self.case.case_id), response_string)
self.assertIn('"revision_id":"{}"'.format(self.case.revision_id), response_string) self.assertIn(
'"revision_id":"{}"'.format(self.case.revision_id), response_string
)
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string) self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string)
def test_edit_inactive_positive_case_fails(self): def test_edit_inactive_positive_case_fails(self):
...@@ -226,12 +234,16 @@ class PositiveCaseViewTest(APITestCase): ...@@ -226,12 +234,16 @@ class PositiveCaseViewTest(APITestCase):
) )
# Have positive case deletion log # Have positive case deletion log
response = self.client.get('/logs/') response = self.client.get("/logs/")
response_string = response.rendered_content.decode("utf-8") response_string = response.rendered_content.decode("utf-8")
self.assertIn('"object_id":"{}"'.format(self.case.case_id), response_string) self.assertIn('"object_id":"{}"'.format(self.case.case_id), response_string)
self.assertIn('"revision_id":"{}"'.format(self.case.revision_id), response_string) self.assertIn(
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string) '"revision_id":"{}"'.format(self.case.revision_id), response_string
)
self.assertIn(
'"action_type":"{}"'.format(ACTIVITY_TYPE_DELETE), response_string
)
def test_delete_inactive_positive_case_fails(self): def test_delete_inactive_positive_case_fails(self):
url = self.BASE_URL + str(self.other_inactive_case.revision_id) + "/" url = self.BASE_URL + str(self.other_inactive_case.revision_id) + "/"
......
...@@ -71,8 +71,8 @@ class CaseSubjectViewSet(viewsets.ViewSet): ...@@ -71,8 +71,8 @@ class CaseSubjectViewSet(viewsets.ViewSet):
# Add case subject creation log # Add case subject creation log
Log.objects.create( Log.objects.create(
model_name=MODEL_NAME_CASE_SUBJECT, model_name=MODEL_NAME_CASE_SUBJECT,
object_id=serializer.data['subject_id'], object_id=serializer.data["subject_id"],
revision_id=serializer.data['revision_id'], revision_id=serializer.data["revision_id"],
action_type=ACTIVITY_TYPE_CREATE, action_type=ACTIVITY_TYPE_CREATE,
author=request.user.account, author=request.user.account,
) )
...@@ -87,10 +87,8 @@ class CaseSubjectViewSet(viewsets.ViewSet): ...@@ -87,10 +87,8 @@ class CaseSubjectViewSet(viewsets.ViewSet):
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
serializer_data = serializer.validated_data serializer_data = serializer.validated_data
serializer_data['subject_id'] = previous_instance.subject_id serializer_data["subject_id"] = previous_instance.subject_id
new_instance = CaseSubject.objects.create( new_instance = CaseSubject.objects.create(**serializer_data, is_active=True,)
**serializer_data, is_active=True,
)
previous_instance.is_active = False previous_instance.is_active = False
previous_instance.save() previous_instance.save()
...@@ -251,10 +249,8 @@ class MonitoringCaseViewSet(viewsets.ViewSet): ...@@ -251,10 +249,8 @@ class MonitoringCaseViewSet(viewsets.ViewSet):
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
serializer_data = serializer.validated_data serializer_data = serializer.validated_data
serializer_data['case_id'] = previous_instance.case_id serializer_data["case_id"] = previous_instance.case_id
new_instance = MonitoringCase.objects.create( new_instance = MonitoringCase.objects.create(**serializer_data, is_active=True,)
**serializer_data, is_active=True,
)
previous_instance.is_active = False previous_instance.is_active = False
previous_instance.save() previous_instance.save()
...@@ -335,10 +331,8 @@ class PositiveCaseViewSet(viewsets.ViewSet): ...@@ -335,10 +331,8 @@ class PositiveCaseViewSet(viewsets.ViewSet):
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
serializer_data = serializer.validated_data serializer_data = serializer.validated_data
serializer_data['case_id'] = previous_instance.case_id serializer_data["case_id"] = previous_instance.case_id
new_instance = PositiveCase.objects.create( new_instance = PositiveCase.objects.create(is_active=True, **serializer_data,)
is_active=True, **serializer_data,
)
previous_instance.is_active = False previous_instance.is_active = False
previous_instance.save() previous_instance.save()
......
...@@ -36,12 +36,12 @@ MODEL_OBJECT_ID_MAPPING = { ...@@ -36,12 +36,12 @@ MODEL_OBJECT_ID_MAPPING = {
"PositiveCase": "case_id", "PositiveCase": "case_id",
} }
MODEL_NAME_ACCOUNT = 'Account' MODEL_NAME_ACCOUNT = "Account"
MODEL_NAME_CASE_SUBJECT = 'CaseSubject' MODEL_NAME_CASE_SUBJECT = "CaseSubject"
MODEL_NAME_INVESTIGATION_CASE = 'InvestigationCase' MODEL_NAME_INVESTIGATION_CASE = "InvestigationCase"
MODEL_NAME_MONITORING_CASE = 'MonitoringCase' MODEL_NAME_MONITORING_CASE = "MonitoringCase"
MODEL_NAME_POSITIVE_CASE = 'PositiveCase' MODEL_NAME_POSITIVE_CASE = "PositiveCase"
ACTIVITY_TYPE_CREATE = 'Create' ACTIVITY_TYPE_CREATE = "Create"
ACTIVITY_TYPE_EDIT = 'Edit' ACTIVITY_TYPE_EDIT = "Edit"
ACTIVITY_TYPE_DELETE = 'Delete' ACTIVITY_TYPE_DELETE = "Delete"
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