Fakultas Ilmu Komputer UI

Commit e675ad4f authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

Merge branch 'django-admin-page' into 'staging'

Register Models to Django-Admin Page

See merge request !26
parents 24382149 4d28fef4
Pipeline #39468 passed with stages
in 9 minutes and 51 seconds
from django.contrib import admin
from apps.accounts.models import Account
# Register your models here.
admin.site.register(Account)
......@@ -43,6 +43,6 @@ class Migration(migrations.Migration):
),
),
],
options={"verbose_name_plural": "accounts", "db_table": "account",},
options={"verbose_name_plural": "accounts", "db_table": "account", },
),
]
......@@ -20,3 +20,8 @@ class Account(models.Model):
class Meta:
db_table = "account"
verbose_name_plural = "accounts"
def __str__(self):
if self.is_admin:
return f"[Admin] {self.user.username}"
return f"[Officer] {self.user.username}"
......@@ -35,6 +35,13 @@ class AccountViewTest(APITestCase):
def setUp(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token_1.key)
def test_string_representation(self):
admin_str = f"[Admin] {self.admin.user.username}"
self.assertEqual(admin_str, str(self.admin))
officer_str = f"[Officer] {self.officer.user.username}"
self.assertEqual(officer_str, str(self.officer))
def test_list_all_accounts_success(self):
url = self.BASE_URL
......
from django.contrib import admin
from apps.cases.models import (
CaseSubject,
InvestigationCase,
MonitoringCase,
PositiveCase,
)
# Register your models here.
admin.site.register(CaseSubject)
admin.site.register(InvestigationCase)
admin.site.register(MonitoringCase)
admin.site.register(PositiveCase)
......@@ -29,6 +29,17 @@ class CaseSubject(models.Model):
verbose_name_plural = "case subjects"
ordering = ["-created_at"]
def __str__(self):
if self.is_active:
return (
f"[Active] Rev. {self.revision_id} - {self.name} | "
+ f"{self.district}, {self.sub_district}"
)
return (
f"[Inactive] Rev. {self.revision_id} - {self.name} | "
+ f"{self.district}, {self.sub_district}"
)
def delete(self):
if self.deleted_at is None:
self.is_active = False
......@@ -59,6 +70,11 @@ class PositiveCase(models.Model):
verbose_name_plural = "positive cases"
ordering = ["-created_at"]
def __str__(self):
if self.is_active:
return f"[Active] Rev. {self.revision_id} | by {self.author}"
return f"[Inactive] Rev. {self.revision_id} | by {self.author}"
def delete(self):
if self.deleted_at is None:
self.is_active = False
......@@ -100,6 +116,11 @@ class InvestigationCase(models.Model):
verbose_name_plural = "investigation cases"
ordering = ["-created_at"]
def __str__(self):
if self.is_active:
return f"[Active] Rev. {self.revision_id} | by {self.author}"
return f"[Inactive] Rev. {self.revision_id} | by {self.author}"
def delete(self):
if self.deleted_at is None:
self.is_active = False
......@@ -149,6 +170,11 @@ class MonitoringCase(models.Model):
verbose_name_plural = "monitoring cases"
ordering = ["-created_at"]
def __str__(self):
if self.is_active:
return f"[Active] Rev. {self.revision_id} | by {self.author}"
return f"[Inactive] Rev. {self.revision_id} | by {self.author}"
def save(self, *args, **kwargs):
self.clean()
return super(MonitoringCase, self).save(*args, **kwargs)
......
......@@ -38,6 +38,19 @@ class CaseSubjectViewTest(APITestCase):
def setUp(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token_1.key)
def test_string_representation(self):
inactive_case_subject_str = (
f"[Inactive] Rev. {self.case_subject_3.revision_id} - {self.case_subject_3.name} | "
+ f"{self.case_subject_3.district}, {self.case_subject_3.sub_district}"
)
self.assertEqual(inactive_case_subject_str, str(self.case_subject_3))
active_case_subject_str = (
f"[Active] Rev. {self.case_subject_1.revision_id} - {self.case_subject_1.name} | "
+ f"{self.case_subject_1.district}, {self.case_subject_1.sub_district}"
)
self.assertEqual(active_case_subject_str, str(self.case_subject_1))
def test_list_case_subjects_only_shows_active_entries_success(self):
url = self.BASE_URL
......
......@@ -46,7 +46,7 @@ class InvestigationCaseViewTest(APITestCase):
reference_case_id=self.reference_case.case_id,
deleted_at=datetime.now(tz=pytz.timezone(TIMEZONE)),
)
self.other_inactive_case = InvestigationCaseFactory(
self.inactive_case = InvestigationCaseFactory(
author=self.author,
case_subject_id=self.case_subject.subject_id,
reference_case_id=self.reference_case.case_id,
......@@ -56,6 +56,17 @@ class InvestigationCaseViewTest(APITestCase):
def setUp(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token_1.key)
def test_string_representation(self):
inactive_case_str = (
f"[Inactive] Rev. {self.inactive_case.revision_id} | by {self.inactive_case.author}"
)
self.assertEqual(inactive_case_str, str(self.inactive_case))
active_case_str = (
f"[Active] Rev. {self.case.revision_id} | by {self.case.author}"
)
self.assertEqual(active_case_str, str(self.case))
def test_list_investigation_cases_success(self):
url = self.BASE_URL
......@@ -223,15 +234,15 @@ class InvestigationCaseViewTest(APITestCase):
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string)
def test_edit_inactive_investigation_case_fails(self):
url = self.BASE_URL + str(self.other_inactive_case.revision_id) + "/"
url = self.BASE_URL + str(self.inactive_case.revision_id) + "/"
data = {
"case_subject_id": str(self.other_inactive_case.case_subject_id),
"case_subject_id": str(self.inactive_case.case_subject_id),
"reference_case_id": str(self.reference_case.case_id),
"case_relation": self.other_inactive_case.case_relation,
"medical_symptoms": self.other_inactive_case.medical_symptoms,
"risk_factors": self.other_inactive_case.risk_factors,
"is_referral_needed": not self.other_inactive_case.is_referral_needed,
"medical_facility_reference": self.other_inactive_case.medical_facility_reference,
"case_relation": self.inactive_case.case_relation,
"medical_symptoms": self.inactive_case.medical_symptoms,
"risk_factors": self.inactive_case.risk_factors,
"is_referral_needed": not self.inactive_case.is_referral_needed,
"medical_facility_reference": self.inactive_case.medical_facility_reference,
}
response = self.client.put(path=url, data=data, format="json",)
......@@ -299,7 +310,7 @@ class InvestigationCaseViewTest(APITestCase):
)
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.inactive_case.revision_id) + "/"
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
......@@ -53,7 +53,7 @@ class MonitoringCaseViewTest(APITestCase):
positive_case_id=self.positive_case.case_id,
deleted_at=datetime.now(tz=pytz.timezone(TIMEZONE)),
)
self.other_inactive_case = MonitoringCaseFactory(
self.inactive_case = MonitoringCaseFactory(
author=self.author,
positive_case_id=self.positive_case.case_id,
is_active=False,
......@@ -62,6 +62,17 @@ class MonitoringCaseViewTest(APITestCase):
def setUp(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token.key)
def test_string_representation(self):
inactive_case_str = (
f"[Inactive] Rev. {self.inactive_case.revision_id} | by {self.inactive_case.author}"
)
self.assertEqual(inactive_case_str, str(self.inactive_case))
active_case_str = (
f"[Active] Rev. {self.case_1.revision_id} | by {self.case_1.author}"
)
self.assertEqual(active_case_str, str(self.case_1))
def test_list_monitoring_cases_success(self):
url = self.BASE_URL
......@@ -193,7 +204,7 @@ class MonitoringCaseViewTest(APITestCase):
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string)
def test_edit_inactive_monitoring_case_fails(self):
url = self.BASE_URL + str(self.other_inactive_case.revision_id) + "/"
url = self.BASE_URL + str(self.inactive_case.revision_id) + "/"
data = {
"positive_case_id": str(self.positive_case.revision_id),
......@@ -240,6 +251,6 @@ class MonitoringCaseViewTest(APITestCase):
)
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.inactive_case.revision_id) + "/"
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
......@@ -37,7 +37,7 @@ class PositiveCaseViewTest(APITestCase):
case_subject_id=self.case_subject.subject_id,
deleted_at=datetime.now(tz=pytz.timezone(TIMEZONE)),
)
self.other_inactive_case = PositiveCaseFactory(
self.inactive_case = PositiveCaseFactory(
author=self.author,
case_subject_id=self.case_subject.subject_id,
is_active=False,
......@@ -46,6 +46,17 @@ class PositiveCaseViewTest(APITestCase):
def setUp(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token_1.key)
def test_string_representation(self):
inactive_case_str = (
f"[Inactive] Rev. {self.inactive_case.revision_id} | by {self.inactive_case.author}"
)
self.assertEqual(inactive_case_str, str(self.inactive_case))
active_case_str = (
f"[Active] Rev. {self.case.revision_id} | by {self.case.author}"
)
self.assertEqual(active_case_str, str(self.case))
def test_list_positive_cases_success(self):
url = self.BASE_URL
......@@ -191,7 +202,7 @@ class PositiveCaseViewTest(APITestCase):
self.assertIn('"action_type":"{}"'.format(ACTIVITY_TYPE_EDIT), response_string)
def test_edit_inactive_positive_case_fails(self):
url = self.BASE_URL + str(self.other_inactive_case.revision_id) + "/"
url = self.BASE_URL + str(self.inactive_case.revision_id) + "/"
data = {
"case_subject_id": str(self.case.case_subject_id),
......@@ -246,6 +257,6 @@ class PositiveCaseViewTest(APITestCase):
)
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.inactive_case.revision_id) + "/"
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
......@@ -13,7 +13,9 @@ router = DefaultRouter()
router.register(r"case-subjects", CaseSubjectViewSet, basename="case-subject")
router.register(r"positive-cases", PositiveCaseViewSet, basename="positive-case")
router.register(r"monitoring-cases", MonitoringCaseViewSet, basename="monitoring-case")
router.register(r"investigation-cases", InvestigationCaseViewSet, basename="investigation-case")
router.register(
r"investigation-cases", InvestigationCaseViewSet, basename="investigation-case"
)
urlpatterns = [
path("", include(router.urls)),
......
from django.contrib import admin
from apps.logs.models import Log
# Register your models here.
admin.site.register(Log)
......@@ -29,6 +29,9 @@ class Log(models.Model):
verbose_name_plural = "activity logs"
ordering = ["-created_at"]
def __str__(self):
return f"{self.created_at} | [{self.action_type}] {self.model_name} - {self.author}"
def get_model(self):
model_app = MODEL_APP_MAPPING.get(self.model_name)
Model = apps.get_model(model_app, self.model_name)
......
......@@ -50,6 +50,13 @@ class ActivityLogViewTest(APITestCase):
def setUp(self):
self.client = APIClient(HTTP_AUTHORIZATION=HEADER_PREFIX + self.token.key)
def test_string_representation(self):
log_str = (
f"{self.log.created_at} | [{self.log.action_type}] "
+ f"{self.log.model_name} - {self.log.author}"
)
self.assertEqual(log_str, str(self.log))
def test_list_only_current_author_logs_success(self):
url = "/logs/"
......
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