diff --git a/pepfar_mle/common/tests/test_views.py b/pepfar_mle/common/tests/test_views.py index 485a9266..7e82d988 100644 --- a/pepfar_mle/common/tests/test_views.py +++ b/pepfar_mle/common/tests/test_views.py @@ -1,6 +1,8 @@ import pytest from django.core.exceptions import PermissionDenied +from django.urls import reverse from model_bakery import baker +from rest_framework import status from pepfar_mle.common.views import HomeView @@ -28,3 +30,31 @@ def test_approved_mixin_non_approved_authenticated_user(rf, django_user_model): view.dispatch(request) # no error raised assert "PermissionDenied" in str(e) + + +def test_home_view(user, client): + client.force_login(user) + url = reverse("home") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK + + +def test_about_view(user, client): + client.force_login(user) + url = reverse("about") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK + + +def test_facility_view(user, client): + client.force_login(user) + url = reverse("common:facilities") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK + + +def test_systems_view(user, client): + client.force_login(user) + url = reverse("common:systems") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK diff --git a/pepfar_mle/common/views.py b/pepfar_mle/common/views.py index 9118a497..47abc85b 100644 --- a/pepfar_mle/common/views.py +++ b/pepfar_mle/common/views.py @@ -12,14 +12,36 @@ def test_func(self): class HomeView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/home.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "dashboard-nav" # id of active nav element + return context + class AboutView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/about.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "dashboard-nav" # id of active nav element + return context + class FacilityView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/common/facilities.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "facilities-nav" # id of active nav element + context["selected"] = "facilities" # id of selected page + return context + class SystemsView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/common/systems.html" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "facilities-nav" # id of active nav element + context["selected"] = "systems" # id of selected page + return context diff --git a/pepfar_mle/ops/tests/test_views.py b/pepfar_mle/ops/tests/test_views.py new file mode 100644 index 00000000..5f5761b3 --- /dev/null +++ b/pepfar_mle/ops/tests/test_views.py @@ -0,0 +1,47 @@ +import pytest +from django.urls import reverse +from rest_framework import status + +pytestmark = pytest.mark.django_db + + +def test_system_versions_view(user, client): + client.force_login(user) + url = reverse("ops:versions") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK + + +def test_tickets_view(user, client): + client.force_login(user) + url = reverse("ops:tickets") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK + + +def test_activity_log_view(user, client): + client.force_login(user) + url = reverse("ops:activity_log") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK + + +def test_site_mentorship_view(user, client): + client.force_login(user) + url = reverse("ops:site_mentorship") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK + + +def test_daily_site_updates_view(user, client): + client.force_login(user) + url = reverse("ops:daily_site_updates") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK + + +def test_timesheets_view(user, client): + client.force_login(user) + url = reverse("ops:timesheets") + response = client.get(url) + assert response.status_code == status.HTTP_200_OK diff --git a/pepfar_mle/ops/views.py b/pepfar_mle/ops/views.py index 0b0f652a..253e7146 100644 --- a/pepfar_mle/ops/views.py +++ b/pepfar_mle/ops/views.py @@ -7,22 +7,58 @@ class VersionsView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/ops/versions.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "facilities-nav" # id of active nav element + context["selected"] = "versions" # id of selected page + return context + class TicketsView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/ops/tickets.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "facilities-nav" # id of active nav element + context["selected"] = "tickets" # id of selected page + return context + class ActivityLogView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/ops/activity_log.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "program-nav" # id of active nav element + context["selected"] = "activity-log" # id of selected page + return context + class SiteMentorshipView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/ops/site_mentorship.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "program-nav" # id of active nav element + context["selected"] = "site-mentorship" # id of selected page + return context + class DailySiteUpdatesView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/ops/daily_site_updates.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "program-nav" # id of active nav element + context["selected"] = "daily-site-updates" # id of selected page + return context + class TimeSheetsView(LoginRequiredMixin, ApprovedMixin, TemplateView): template_name = "pages/ops/timesheets.html" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["active"] = "program-nav" # id of active nav element + context["selected"] = "timesheets" # id of selected page + return context diff --git a/pepfar_mle/templates/fragments/atoms/dashboard_link.html b/pepfar_mle/templates/fragments/atoms/dashboard_link.html index 4d37eaf7..53edb55d 100644 --- a/pepfar_mle/templates/fragments/atoms/dashboard_link.html +++ b/pepfar_mle/templates/fragments/atoms/dashboard_link.html @@ -1,6 +1,6 @@ {% load static i18n compress%} -