Skip to content

Commit

Permalink
[#1661] Moved contact form link display test to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van der Schoor committed Aug 21, 2023
1 parent 3557f47 commit 3682d82
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
Empty file.
47 changes: 47 additions & 0 deletions src/open_inwoner/cms/footer/tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from django.test import TestCase
from django.utils.translation import gettext as _

from open_inwoner.cms.footer.cms_plugins import FooterPagesPlugin
from open_inwoner.cms.tests import cms_tools
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.tests.factories import ContactFormSubjectFactory
from open_inwoner.utils.test import ClearCachesMixin


class ContactFormTestCase(ClearCachesMixin, TestCase):
def setUp(self):
super().setUp()
# clear config
config = OpenKlantConfig.get_solo()
config.klanten_service = None
config.contactmomenten_service = None
config.register_email = ""
config.register_contact_moment = False
config.register_bronorganisatie_rsin = ""
config.register_type = ""
config.register_employee_id = ""
config.save()

def test_no_form_link_shown_in_footer_if_not_has_configuration(self):
# set nothing
config = OpenKlantConfig.get_solo()
self.assertFalse(config.has_form_configuration())

html, context = cms_tools.render_plugin(FooterPagesPlugin)

self.assertNotIn(_("Contact formulier"), html)

def test_form_link_is_shown_in_footer_when_has_configuration(self):
ok_config = OpenKlantConfig.get_solo()
self.assertFalse(ok_config.has_form_configuration())

ContactFormSubjectFactory(config=ok_config)

ok_config.register_email = "[email protected]"
ok_config.save()

self.assertTrue(ok_config.has_form_configuration())

html, context = cms_tools.render_plugin(FooterPagesPlugin)

self.assertIn(_("Contact formulier"), html)
34 changes: 0 additions & 34 deletions src/open_inwoner/openklant/tests/test_contactform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

from django.contrib import messages
from django.core import mail
from django.test import override_settings
from django.urls import reverse
from django.utils.translation import gettext as _

import requests_mock
from django_webtest import WebTest

from open_inwoner.accounts.tests.factories import UserFactory
from open_inwoner.cms.tests import cms_tools
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.tests.data import MockAPICreateData
from open_inwoner.openklant.tests.factories import ContactFormSubjectFactory
Expand Down Expand Up @@ -79,38 +77,6 @@ def test_no_form_shown_if_not_has_configuration(self, m):
self.assertContains(response, _("Contact formulier niet geconfigureerd."))
self.assertEqual(0, len(response.pyquery("#contactmoment-form")))

@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
def test_no_form_link_shown_in_footer_if_not_has_configuration(self, m):
# set nothing
config = OpenKlantConfig.get_solo()
self.assertFalse(config.has_form_configuration())

cms_tools.create_homepage()

response = self.app.get(reverse("pages-root"))
links = response.pyquery(".footer__list-item")

self.assertEqual(len(links), 0)

@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
def test_form_link_is_shown_in_footer_when_has_configuration(self, m):
ok_config = OpenKlantConfig.get_solo()
self.assertFalse(ok_config.has_form_configuration())

ContactFormSubjectFactory(config=ok_config)

ok_config.register_email = "[email protected]"
ok_config.save()

self.assertTrue(ok_config.has_form_configuration())

cms_tools.create_homepage()

response = self.app.get(reverse("pages-root"))
links = response.pyquery(".footer__list-item")

self.assertIn(_("Contact formulier"), links[0].text_content())

def test_anon_form_requires_either_email_or_phonenumber(self, m):
config = OpenKlantConfig.get_solo()
config.register_email = "[email protected]"
Expand Down

0 comments on commit 3682d82

Please sign in to comment.