Fakultas Ilmu Komputer UI

Commit 2bb9409d authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

[REFACTOR] Remove unimplemented case handlers and fix some tests

parent 9d4335d9
Pipeline #41500 passed with stages
in 20 minutes and 35 seconds
......@@ -26,6 +26,10 @@ class AccountSerializer(serializers.ModelSerializer):
"username",
]
def save(self):
account = self.context.get('request').user.account
super(AccountSerializer, self).save(author=account)
class AccountRegisterSerializer(serializers.ModelSerializer):
username = serializers.CharField(max_length=128)
......@@ -51,7 +55,3 @@ class AccountRegisterSerializer(serializers.ModelSerializer):
def to_representation(self, instance):
serializer = AccountSerializer(instance)
return serializer.data
def save(self):
account = self.context.get('request').user.account
super(AccountRegisterSerializer, self).save(author=account)
......@@ -193,6 +193,10 @@ class AccountViewTest(APITestCase):
def test_delete_success(self):
url = self.BASE_URL + str(self.officer.id) + "/"
account_prev_count = Account.objects.all().count()
account_history_prev_count = AccountHistory.objects.all().count()
account_deleted_prev_count = Account.objects.deleted().count()
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
......@@ -206,6 +210,15 @@ class AccountViewTest(APITestCase):
f'"action_type":"{ACTIVITY_TYPE_DELETE}"', response_string
)
account_current_count = Account.objects.all().count()
account_history_current_count = AccountHistory.objects.all().count()
account_deleted_current_count = Account.objects.deleted().count()
self.assertEqual(account_current_count, account_prev_count - 1)
self.assertEqual(account_history_current_count, account_history_prev_count + 1)
self.assertEqual(account_deleted_current_count, account_deleted_prev_count + 1)
def test_retrieve_current_profile_success(self):
url = self.PROFILE_URL
......
......@@ -196,6 +196,7 @@ class CaseSubjectViewTest(APITestCase):
url = self.BASE_URL + str(self.case_subject_1.id) + "/"
case_subject_prev_count = CaseSubject.objects.all().count()
case_subject_history_prev_count = CaseSubjectHistory.objects.all().count()
case_subject_deleted_prev_count = CaseSubject.objects.deleted().count()
response = self.client.delete(path=url, format="json")
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
......@@ -207,6 +208,8 @@ class CaseSubjectViewTest(APITestCase):
case_subject_current_count = CaseSubject.objects.all().count()
case_subject_history_current_count = CaseSubjectHistory.objects.all().count()
case_subject_deleted_current_count = CaseSubject.objects.deleted().count()
self.assertEqual(case_subject_current_count, case_subject_prev_count - 1)
self.assertEqual(case_subject_history_current_count, case_subject_history_prev_count + 1)
self.assertEqual(case_subject_deleted_current_count, case_subject_deleted_prev_count + 1)
......@@ -222,6 +222,7 @@ class InvestigationCaseViewTest(APITestCase):
investigation_case_prev_count = InvestigationCase.objects.all().count()
investigation_case_history_prev_count = InvestigationCaseHistory.objects.all().count()
investigation_case_deleted_prev_count = InvestigationCase.objects.deleted().count()
response = self.client.delete(path=url, format="json",)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
......@@ -233,10 +234,10 @@ class InvestigationCaseViewTest(APITestCase):
investigation_case_current_count = InvestigationCase.objects.all().count()
investigation_case_history_current_count = InvestigationCaseHistory.objects.all().count()
investigation_case_deleted_current_count = InvestigationCase.objects.deleted().count()
self.assertEqual(
investigation_case_current_count, investigation_case_prev_count - 1
)
self.assertEqual(investigation_case_current_count, investigation_case_prev_count - 1)
self.assertEqual(investigation_case_deleted_current_count, investigation_case_deleted_prev_count + 1)
# New InvestigationCaseHistory added
self.assertEqual(
......
......@@ -135,6 +135,11 @@ class MonitoringCaseViewTest(APITestCase):
def test_soft_delete_monitoring_case_success(self):
url = self.BASE_URL + str(self.case_1.id) + "/"
monitoring_case_prev_count = MonitoringCase.objects.all().count()
monitoring_case_history_prev_count = MonitoringCaseHistory.objects.all().count()
monitoring_case_deleted_prev_count = MonitoringCase.objects.deleted().count()
response = self.client.delete(path=url, format="json",)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertIsNotNone(
......@@ -143,6 +148,18 @@ class MonitoringCaseViewTest(APITestCase):
.first()
)
monitoring_case_current_count = MonitoringCase.objects.all().count()
monitoring_case_history_current_count = MonitoringCaseHistory.objects.all().count()
monitoring_case_deleted_current_count = MonitoringCase.objects.deleted().count()
self.assertEqual(monitoring_case_current_count, monitoring_case_prev_count - 1)
self.assertEqual(monitoring_case_deleted_current_count, monitoring_case_deleted_prev_count + 1)
# New MonitoringCaseHistory added
self.assertEqual(
monitoring_case_history_current_count, monitoring_case_history_prev_count + 1
)
# Have monitoring case deletion log
response = self.client.get(self.LOGS_URL)
response_string = response.rendered_content.decode("utf-8")
......
......@@ -83,11 +83,7 @@ class HistoryEnabledModel(SoftDeleteModel):
return self
def delete(self, *args, **kwargs):
if "author" in kwargs.keys():
author = kwargs.pop("author")
else:
author = None
author = kwargs.get("author")
action = ACTIVITY_TYPE_DELETE
super(HistoryEnabledModel, self).delete(author=author)
self._assign_history(action, author)
......
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