Skip to content

Commit

Permalink
[#911] Modified profile's Zelfcheck and homepage to not show Question…
Browse files Browse the repository at this point in the history
…aireStep UI/links when no published steps
  • Loading branch information
Bart van der Schoor committed Dec 8, 2022
1 parent 2232900 commit cb4802b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from open_inwoner.accounts.choices import StatusChoices
from open_inwoner.pdc.tests.factories import CategoryFactory

from ...questionnaire.tests.factories import QuestionnaireStepFactory
from ..choices import LoginTypeChoices
from .factories import ActionFactory, DocumentFactory, UserFactory

Expand All @@ -30,17 +31,21 @@ def test_login_required(self):

def test_get_empty_profile_page(self):
response = self.app.get(self.url, user=self.user)

self.assertEquals(response.status_code, 200)
self.assertContains(response, _("U heeft geen intressegebieden aangegeven."))
self.assertContains(response, _("U heeft nog geen contacten."))
self.assertContains(response, "0 acties staan open.")
self.assertNotContains(response, reverse("questionnaire:questionnaire_list"))

def test_get_filled_profile_page(self):
action = ActionFactory(created_by=self.user)
ActionFactory(created_by=self.user)
contact = UserFactory()
self.user.user_contacts.add(contact)
category = CategoryFactory()
self.user.selected_themes.add(category)
QuestionnaireStepFactory(published=True)

response = self.app.get(self.url, user=self.user)
self.assertEquals(response.status_code, 200)
self.assertContains(response, category.name)
Expand All @@ -49,6 +54,7 @@ def test_get_filled_profile_page(self):
f"{contact.first_name} ({contact.get_contact_type_display()})",
)
self.assertContains(response, "1 acties staan open.")
self.assertContains(response, reverse("questionnaire:questionnaire_list"))

def test_only_open_actions(self):
action = ActionFactory(created_by=self.user, status=StatusChoices.closed)
Expand Down
6 changes: 5 additions & 1 deletion src/open_inwoner/accounts/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ def get_context_data(self, **kwargs):
] = f"{', '.join(contact_names)}{'...' if contacts.count() > 3 else ''}"
else:
context["contact_text"] = _("U heeft nog geen contacten.")
context["questionnaire_exists"] = QuestionnaireStep.objects.exists()

context["questionnaire_exists"] = QuestionnaireStep.objects.filter(
published=True
).exists()
context["can_change_password"] = user.login_type != LoginTypeChoices.digid

return context

def post(self, request, *args, **kwargs):
Expand Down
15 changes: 15 additions & 0 deletions src/open_inwoner/pdc/tests/test_questionnaire.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ def test_user_home_page_contains_highlighted_root_nodes(self):

self.assertContains(response, self.root_nodes[0].get_absolute_url())
self.assertContains(response, self.root_nodes[1].get_absolute_url())

def test_home_page_doesnt_show_unpublished_nodes(self):
QuestionnaireStep.objects.update(published=False)

response = self.app.get(reverse("root"))
self.assertNotContains(response, self.root_nodes[0].get_absolute_url())
self.assertNotContains(response, self.root_nodes[1].get_absolute_url())

def test_user_home_page_doesnt_show_unpublished_nodes(self):
QuestionnaireStep.objects.update(published=False)

user = UserFactory()
response = self.app.get(reverse("root"), user=user)
self.assertNotContains(response, self.root_nodes[0].get_absolute_url())
self.assertNotContains(response, self.root_nodes[1].get_absolute_url())

0 comments on commit cb4802b

Please sign in to comment.