Fakultas Ilmu Komputer UI

Commit 17ed0537 authored by Dave Nathanael's avatar Dave Nathanael
Browse files

[REFACTOR] Change `self` to `cls` on methods that use @classmethod

parent 2639b42e
......@@ -17,20 +17,20 @@ from apps.constants import (
class AccountViewTest(APITestCase):
@classmethod
def setUpTestData(self):
self.BASE_URL = "/accounts/"
self.PROFILE_URL = self.BASE_URL + "me/"
def setUpTestData(cls):
cls.BASE_URL = "/accounts/"
cls.PROFILE_URL = cls.BASE_URL + "me/"
self.user_1 = UserFactory(username="user_1", password="justpass")
self.user_2 = UserFactory(username="user_2", password="justpass")
self.admin = AccountFactory(admin=True, user=self.user_1)
self.officer = AccountFactory(admin=False, user=self.user_2)
self.accounts = [self.admin, self.officer]
cls.user_1 = UserFactory(username="user_1", password="justpass")
cls.user_2 = UserFactory(username="user_2", password="justpass")
cls.admin = AccountFactory(admin=True, user=cls.user_1)
cls.officer = AccountFactory(admin=False, user=cls.user_2)
cls.accounts = [cls.admin, cls.officer]
self.token_1, _ = Token.objects.get_or_create(user=self.user_1)
self.token_2, _ = Token.objects.get_or_create(user=self.user_2)
cls.token_1, _ = Token.objects.get_or_create(user=cls.user_1)
cls.token_2, _ = Token.objects.get_or_create(user=cls.user_2)
self.faker = Faker()
cls.faker = Faker()
def setUp(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token_1.key)
......
......@@ -20,17 +20,17 @@ from apps.constants import (
class CaseSubjectViewTest(APITestCase):
@classmethod
def setUpTestData(self):
self.BASE_URL = "/cases/case-subjects/"
def setUpTestData(cls):
cls.BASE_URL = "/cases/case-subjects/"
self.user_1 = UserFactory(username="user_1", password="justpass")
self.user_2 = UserFactory(username="user_2", password="justpass")
self.admin = AccountFactory(admin=True, user=self.user_1)
self.officer = AccountFactory(admin=False, user=self.user_2)
self.token_1, _ = Token.objects.get_or_create(user=self.user_1)
cls.user_1 = UserFactory(username="user_1", password="justpass")
cls.user_2 = UserFactory(username="user_2", password="justpass")
cls.admin = AccountFactory(admin=True, user=cls.user_1)
cls.officer = AccountFactory(admin=False, user=cls.user_2)
cls.token_1, _ = Token.objects.get_or_create(user=cls.user_1)
self.case_subject_1 = CaseSubjectFactory()
self.case_subject_2 = CaseSubjectFactory(
cls.case_subject_1 = CaseSubjectFactory()
cls.case_subject_2 = CaseSubjectFactory(
deleted_at=datetime.now(tz=pytz.timezone(TIMEZONE)),
)
......
......@@ -21,29 +21,29 @@ from apps.constants import (
class InvestigationCaseViewTest(APITestCase):
@classmethod
def setUpTestData(self):
self.BASE_URL = "/cases/investigation-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)
self.token_1, _ = Token.objects.get_or_create(user=self.user_1)
self.case_subject = CaseSubjectFactory()
self.reference_case = InvestigationCaseFactory(
case_subject=self.case_subject,
author=self.author,
def setUpTestData(cls):
cls.BASE_URL = "/cases/investigation-cases/"
cls.BASE_POSITIVE_URL = "/cases/positive-cases/"
cls.user_1 = UserFactory(username="user_1", password="justpass")
cls.author = AccountFactory(user=cls.user_1, admin=True)
cls.token_1, _ = Token.objects.get_or_create(user=cls.user_1)
cls.case_subject = CaseSubjectFactory()
cls.reference_case = InvestigationCaseFactory(
case_subject=cls.case_subject,
author=cls.author,
outcome="BTA+",
)
self.case = InvestigationCaseFactory(
author=self.author,
case_subject=self.case_subject,
reference_case=self.reference_case,
cls.case = InvestigationCaseFactory(
author=cls.author,
case_subject=cls.case_subject,
reference_case=cls.reference_case,
)
self.other_deleted_case = InvestigationCaseFactory(
author=self.author,
case_subject=self.case_subject,
reference_case=self.reference_case,
cls.other_deleted_case = InvestigationCaseFactory(
author=cls.author,
case_subject=cls.case_subject,
reference_case=cls.reference_case,
deleted_at=datetime.now(tz=pytz.timezone(TIMEZONE)),
)
......
......@@ -26,32 +26,32 @@ from apps.constants import (
class MonitoringCaseViewTest(APITestCase):
@classmethod
def setUpTestData(self):
self.BASE_URL = "/cases/monitoring-cases/"
self.user = UserFactory(username="user_1", password="justpass")
self.token, _ = Token.objects.get_or_create(user=self.user)
self.author = AccountFactory(user=self.user, admin=False)
self.case_subject = CaseSubjectFactory()
self.positive_investigation_case = InvestigationCaseFactory(
author=self.author,
case_subject=self.case_subject,
def setUpTestData(cls):
cls.BASE_URL = "/cases/monitoring-cases/"
cls.user = UserFactory(username="user_1", password="justpass")
cls.token, _ = Token.objects.get_or_create(user=cls.user)
cls.author = AccountFactory(user=cls.user, admin=False)
cls.case_subject = CaseSubjectFactory()
cls.positive_investigation_case = InvestigationCaseFactory(
author=cls.author,
case_subject=cls.case_subject,
reference_case=None,
)
self.case_1 = MonitoringCaseFactory(
author=self.author, investigation_case=self.positive_investigation_case,
cls.case_1 = MonitoringCaseFactory(
author=cls.author, investigation_case=cls.positive_investigation_case,
)
self.investigation_case = InvestigationCaseFactory(
author=self.author,
case_subject=self.case_subject,
cls.investigation_case = InvestigationCaseFactory(
author=cls.author,
case_subject=cls.case_subject,
reference_case=None,
)
self.case_2 = MonitoringCaseFactory(
author=self.author, investigation_case=self.investigation_case,
cls.case_2 = MonitoringCaseFactory(
author=cls.author, investigation_case=cls.investigation_case,
)
self.other_deleted_case = MonitoringCaseFactory(
author=self.author,
investigation_case=self.positive_investigation_case,
cls.other_deleted_case = MonitoringCaseFactory(
author=cls.author,
investigation_case=cls.positive_investigation_case,
deleted_at=datetime.now(tz=pytz.timezone(TIMEZONE)),
)
......
......@@ -14,34 +14,34 @@ from apps.constants import HEADER_PREFIX
class IsAuthenticatedPermissionTest(APITestCase):
@classmethod
def setUpTestData(self):
self.permission = IsAuthenticated()
self.user_1 = UserFactory(username="user_1", password="justpass")
self.user_2 = UserFactory(username="user_2", password="justpass")
self.user_3 = UserFactory(username="user_3", password="justpass")
def setUpTestData(cls):
cls.permission = IsAuthenticated()
cls.user_1 = UserFactory(username="user_1", password="justpass")
cls.user_2 = UserFactory(username="user_2", password="justpass")
cls.user_3 = UserFactory(username="user_3", password="justpass")
self.account_1 = AccountFactory(
cls.account_1 = AccountFactory(
admin=True,
user=self.user_1,
user=cls.user_1,
is_active=True,
is_verified=True
)
self.account_2 = AccountFactory(
cls.account_2 = AccountFactory(
admin=False,
user=self.user_2,
user=cls.user_2,
is_active=False,
is_verified=True
)
self.account_2 = AccountFactory(
cls.account_2 = AccountFactory(
admin=False,
user=self.user_3,
user=cls.user_3,
is_active=True,
is_verified=False
)
self.token_1, _ = Token.objects.get_or_create(user=self.user_1)
self.token_2, _ = Token.objects.get_or_create(user=self.user_2)
self.token_3, _ = Token.objects.get_or_create(user=self.user_3)
cls.token_1, _ = Token.objects.get_or_create(user=cls.user_1)
cls.token_2, _ = Token.objects.get_or_create(user=cls.user_2)
cls.token_3, _ = Token.objects.get_or_create(user=cls.user_3)
def test_has_permission_true_for_active_and_verified_user(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token_1.key)
......@@ -65,9 +65,9 @@ class IsAuthenticatedPermissionTest(APITestCase):
class CreateOnlyPermissionTest(APITestCase):
@classmethod
def setUpTestData(self):
self.permission = CreateOnly()
self.client = APIClient()
def setUpTestData(cls):
cls.permission = CreateOnly()
cls.client = APIClient()
def test_has_permission_true_for_post_request(self):
request = self.client.post("/").wsgi_request
......
......@@ -14,20 +14,20 @@ from apps.constants import HEADER_PREFIX, TIMEZONE
class ActivityLogViewTest(APITestCase):
@classmethod
def setUpTestData(self):
self.maxDiff = None
def setUpTestData(cls):
cls.maxDiff = None
officer_user = UserFactory(username="user_1", password="justpass")
self.officer_account = AccountFactory(admin=False, user=officer_user)
self.officer_token, _ = Token.objects.get_or_create(user=officer_user)
cls.officer_account = AccountFactory(admin=False, user=officer_user)
cls.officer_token, _ = Token.objects.get_or_create(user=officer_user)
admin_user = UserFactory(username="admin_user", password="justpass")
self.admin_account = AccountFactory(admin=True, user=admin_user)
self.admin_token, _ = Token.objects.get_or_create(user=admin_user)
cls.admin_account = AccountFactory(admin=True, user=admin_user)
cls.admin_token, _ = Token.objects.get_or_create(user=admin_user)
case_subject = CaseSubjectFactory()
self.case = InvestigationCaseFactory(
author=self.officer_account, case_subject=case_subject,
cls.case = InvestigationCaseFactory(
author=cls.officer_account, case_subject=case_subject,
)
def get_logs_response(self):
......
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