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