예제 #1
0
    def test_edit(self):
        """
        Check that editing settings in multi-site mode edits the correct
        setting, and leaves the other ones alone
        """
        TestSetting.objects.create(
            title='default',
            email='*****@*****.**',
            site=self.default_site)
        TestSetting.objects.create(
            title='other',
            email='*****@*****.**',
            site=self.other_site)
        response = self.post(site_pk=self.other_site.pk, post_data={
            'title': 'other-new', 'email': '*****@*****.**'})
        self.assertEqual(response.status_code, 302)

        # Check that the correct setting was updated
        other_setting = TestSetting.for_site(self.other_site)
        self.assertEqual(other_setting.title, 'other-new')
        self.assertEqual(other_setting.email, '*****@*****.**')

        # Check that the other setting was not updated
        default_setting = TestSetting.for_site(self.default_site)
        self.assertEqual(default_setting.title, 'default')
        self.assertEqual(default_setting.email, '*****@*****.**')
예제 #2
0
class TestSettingEditView(BaseTestSettingView):
    def setUp(self):
        default_site = Site.objects.get(is_default_site=True)

        self.test_setting = TestSetting()
        self.test_setting.title = "Site title"
        self.test_setting.email = "*****@*****.**"
        self.test_setting.site = default_site
        self.test_setting.save()

        self.login()

    def test_status_code(self):
        self.assertEqual(self.get().status_code, 200)

    def test_non_existant_model(self):
        response = self.client.get(self.edit_url("test", "foo"))
        self.assertEqual(response.status_code, 404)

    def test_edit_invalid(self):
        response = self.post(post_data={"foo": "bar"})
        self.assertContains(response, "The setting could not be saved due to errors.")
        self.assertContains(response, "This field is required.")

    def test_edit(self):
        response = self.post(post_data={"title": "Edited site title", "email": "*****@*****.**"})
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, "Edited site title")
        self.assertEqual(setting.email, "*****@*****.**")
예제 #3
0
class TestSettingEditView(BaseTestSettingView):
    def setUp(self):
        default_site = Site.objects.get(is_default_site=True)

        self.test_setting = TestSetting()
        self.test_setting.title = 'Site title'
        self.test_setting.email = '*****@*****.**'
        self.test_setting.site = default_site
        self.test_setting.save()

        self.login()

    def test_status_code(self):
        self.assertEqual(self.get().status_code, 200)

    def test_non_existant_model(self):
        response = self.client.get(self.edit_url('test', 'foo'))
        self.assertEqual(response.status_code, 404)

    def test_edit_invalid(self):
        response = self.post(post_data={'foo': 'bar'})
        self.assertContains(response, "The setting could not be saved due to errors.")
        self.assertContains(response, "This field is required.")

    def test_edit(self):
        response = self.post(post_data={'title': 'Edited site title',
                                        'email': '*****@*****.**'})
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, 'Edited site title')
        self.assertEqual(setting.email, '*****@*****.**')
예제 #4
0
class TestSettingEditView(BaseTestSettingView):
    def setUp(self):
        default_site = Site.objects.get(is_default_site=True)

        self.test_setting = TestSetting()
        self.test_setting.title = "Site title"
        self.test_setting.email = "*****@*****.**"
        self.test_setting.site = default_site
        self.test_setting.save()

        self.login()

    def test_get_edit(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)
        # there should be a menu item highlighted as active
        self.assertContains(response, "menu-active")

    def test_non_existant_model(self):
        response = self.client.get(reverse("wagtailsettings:edit", args=["test", "foo", 1]))
        self.assertEqual(response.status_code, 404)

    def test_edit_invalid(self):
        response = self.post(post_data={"foo": "bar"})
        self.assertContains(response, "The setting could not be saved due to errors.")
        self.assertContains(response, "This field is required.")

    def test_edit(self):
        response = self.post(post_data={"title": "Edited site title", "email": "*****@*****.**"})
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, "Edited site title")
        self.assertEqual(setting.email, "*****@*****.**")
예제 #5
0
    def test_edit(self):
        """
        Check that editing settings in multi-site mode edits the correct
        setting, and leaves the other ones alone
        """
        TestSetting.objects.create(title="default",
                                   email="*****@*****.**",
                                   site=self.default_site)
        TestSetting.objects.create(title="other",
                                   email="*****@*****.**",
                                   site=self.other_site)
        response = self.post(
            site_pk=self.other_site.pk,
            post_data={
                "title": "other-new",
                "email": "*****@*****.**"
            },
        )
        self.assertEqual(response.status_code, 302)

        # Check that the correct setting was updated
        other_setting = TestSetting.for_site(self.other_site)
        self.assertEqual(other_setting.title, "other-new")
        self.assertEqual(other_setting.email, "*****@*****.**")

        # Check that the other setting was not updated
        default_setting = TestSetting.for_site(self.default_site)
        self.assertEqual(default_setting.title, "default")
        self.assertEqual(default_setting.email, "*****@*****.**")
예제 #6
0
class TestSettingEditView(BaseTestSettingView):
    def setUp(self):
        default_site = Site.objects.get(is_default_site=True)

        self.test_setting = TestSetting()
        self.test_setting.title = 'Site title'
        self.test_setting.email = '*****@*****.**'
        self.test_setting.site = default_site
        self.test_setting.save()

        self.login()

    def test_get_edit(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)
        # there should be a menu item highlighted as active
        self.assertContains(response, "menu-active")

    def test_non_existant_model(self):
        response = self.client.get(
            reverse('wagtailsettings:edit', args=['test', 'foo', 1]))
        self.assertEqual(response.status_code, 404)

    def test_edit_invalid(self):
        response = self.post(post_data={'foo': 'bar'})
        self.assertContains(response,
                            "The setting could not be saved due to errors.")
        self.assertContains(
            response,
            """<p class="error-message"><span>This field is required.</span></p>""",
            count=2,
            html=True)
        self.assertContains(response, "This field is required", count=2)

    def test_edit(self):
        response = self.post(post_data={
            'title': 'Edited site title',
            'email': '*****@*****.**'
        })
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, 'Edited site title')
        self.assertEqual(setting.email, '*****@*****.**')

    def test_get_edit_current_site(self):
        url = reverse('wagtailsettings:edit', args=('tests', 'testsetting'))
        default_site = Site.objects.get(is_default_site=True)

        response = self.client.get(url)
        self.assertRedirects(response,
                             status_code=302,
                             expected_url='%s%s/' % (url, default_site.pk))

    def test_get_edit_current_site_invalid(self):
        Site.objects.all().delete()
        url = reverse('wagtailsettings:edit', args=('tests', 'testsetting'))
        response = self.client.get(url)
        self.assertRedirects(response, status_code=302, expected_url='/admin/')
예제 #7
0
class TestSettingEditView(BaseTestSettingView):
    def setUp(self):
        default_site = Site.objects.get(is_default_site=True)

        self.test_setting = TestSetting()
        self.test_setting.title = "Site title"
        self.test_setting.email = "*****@*****.**"
        self.test_setting.site = default_site
        self.test_setting.save()

        self.login()

    def test_get_edit(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)

    def test_non_existant_model(self):
        response = self.client.get(
            reverse("wagtailsettings:edit", args=["test", "foo", 1]))
        self.assertEqual(response.status_code, 404)

    def test_edit_invalid(self):
        response = self.post(post_data={"foo": "bar"})
        self.assertContains(response,
                            "The setting could not be saved due to errors.")
        self.assertContains(
            response,
            """<p class="error-message"><span>This field is required.</span></p>""",
            count=2,
            html=True,
        )
        self.assertContains(response, "This field is required", count=2)

    def test_edit(self):
        response = self.post(post_data={
            "title": "Edited site title",
            "email": "*****@*****.**"
        })
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, "Edited site title")
        self.assertEqual(setting.email, "*****@*****.**")

    def test_get_edit_current_site(self):
        url = reverse("wagtailsettings:edit", args=("tests", "testsetting"))
        default_site = Site.objects.get(is_default_site=True)

        response = self.client.get(url)
        self.assertRedirects(response,
                             status_code=302,
                             expected_url="%s%s/" % (url, default_site.pk))

    def test_get_edit_current_site_invalid(self):
        Site.objects.all().delete()
        url = reverse("wagtailsettings:edit", args=("tests", "testsetting"))
        response = self.client.get(url)
        self.assertRedirects(response, status_code=302, expected_url="/admin/")
예제 #8
0
    def setUp(self):
        default_site = Site.objects.get(is_default_site=True)

        self.test_setting = TestSetting()
        self.test_setting.title = 'Site title'
        self.test_setting.email = '*****@*****.**'
        self.test_setting.site = default_site
        self.test_setting.save()

        self.login()
예제 #9
0
class TestSettingEditView(BaseTestSettingView):
    def setUp(self):
        default_site = Site.objects.get(is_default_site=True)

        self.test_setting = TestSetting()
        self.test_setting.title = 'Site title'
        self.test_setting.email = '*****@*****.**'
        self.test_setting.site = default_site
        self.test_setting.save()

        self.login()

    def test_get_edit(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)
        # there should be a menu item highlighted as active
        self.assertContains(response, "menu-active")

    def test_non_existant_model(self):
        response = self.client.get(reverse('wagtailsettings:edit', args=['test', 'foo', 1]))
        self.assertEqual(response.status_code, 404)

    def test_edit_invalid(self):
        response = self.post(post_data={'foo': 'bar'})
        self.assertContains(response, "The setting could not be saved due to errors.")
        self.assertContains(response, """<p class="error-message"><span>This field is required.</span></p>""",
                            count=2, html=True)
        self.assertContains(response, "This field is required", count=2)

    def test_edit(self):
        response = self.post(post_data={'title': 'Edited site title',
                                        'email': '*****@*****.**'})
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, 'Edited site title')
        self.assertEqual(setting.email, '*****@*****.**')

    def test_get_edit_current_site(self):
        url = reverse('wagtailsettings:edit', args=('tests', 'testsetting'))
        default_site = Site.objects.get(is_default_site=True)

        response = self.client.get(url)
        self.assertRedirects(response, status_code=302, expected_url='%s%s/' % (url, default_site.pk))

    def test_get_edit_current_site_invalid(self):
        Site.objects.all().delete()
        url = reverse('wagtailsettings:edit', args=('tests', 'testsetting'))
        response = self.client.get(url)
        self.assertRedirects(response, status_code=302, expected_url='/admin/')
예제 #10
0
    def test_for_request_result_caching(self):
        # repeat test to show caching is unique per request instance,
        # even when the requests are for the same site
        for i, request in enumerate(
            [self.get_request(), self.get_request()], 1):
            with self.subTest(attempt=i):

                # force site query beforehand
                Site.find_for_request(request)

                # only the first lookup should result in a query
                with self.assertNumQueries(1):
                    for i in range(4):
                        TestSetting.for_request(request)
예제 #11
0
 def test_for_site_returns_expected_settings(self):
     for site, expected_site_settings in (
         (self.default_site, self.default_site_settings),
         (self.other_site, self.other_site_settings),
     ):
         with self.subTest(site=site):
             self.assertEqual(TestSetting.for_site(site),
                              expected_site_settings)
예제 #12
0
 def test_for_request_returns_expected_settings(self):
     default_site_request = self.get_request()
     other_site_request = self.get_request(site=self.other_site)
     for request, expected_site_settings in (
         (default_site_request, self.default_site_settings),
         (other_site_request, self.other_site_settings),
     ):
         with self.subTest(request=request):
             self.assertEqual(TestSetting.for_request(request),
                              expected_site_settings)
예제 #13
0
    def test_edit(self):
        """
        Check that editing settings in multi-site mode edits the correct
        setting, and leaves the other ones alone
        """
        TestSetting.objects.create(title="default", email="*****@*****.**", site=self.default_site)
        TestSetting.objects.create(title="other", email="*****@*****.**", site=self.other_site)
        response = self.post(
            site_pk=self.other_site.pk, post_data={"title": "other-new", "email": "*****@*****.**"}
        )
        self.assertEqual(response.status_code, 302)

        # Check that the correct setting was updated
        other_setting = TestSetting.for_site(self.other_site)
        self.assertEqual(other_setting.title, "other-new")
        self.assertEqual(other_setting.email, "*****@*****.**")

        # Check that the other setting was not updated
        default_setting = TestSetting.for_site(self.default_site)
        self.assertEqual(default_setting.title, "default")
        self.assertEqual(default_setting.email, "*****@*****.**")
예제 #14
0
class TestSettingEditView(BaseTestSettingView):
    def setUp(self):
        default_site = Site.objects.get(is_default_site=True)

        self.test_setting = TestSetting()
        self.test_setting.title = 'Site title'
        self.test_setting.email = '*****@*****.**'
        self.test_setting.site = default_site
        self.test_setting.save()

        self.login()

    def test_get_edit(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)
        # there should be a menu item highlighted as active
        self.assertContains(response, "menu-active")

    def test_non_existant_model(self):
        response = self.client.get(
            reverse('wagtailsettings:edit', args=['test', 'foo', 1]))
        self.assertEqual(response.status_code, 404)

    def test_edit_invalid(self):
        response = self.post(post_data={'foo': 'bar'})
        self.assertContains(response,
                            "The setting could not be saved due to errors.")
        self.assertContains(response, "This field is required.")

    def test_edit(self):
        response = self.post(post_data={
            'title': 'Edited site title',
            'email': '*****@*****.**'
        })
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, 'Edited site title')
        self.assertEqual(setting.email, '*****@*****.**')
예제 #15
0
파일: test_admin.py 프로젝트: DimiC/wagtail
class TestSettingEditView(BaseTestSettingView):
    def setUp(self):
        default_site = Site.objects.get(is_default_site=True)

        self.test_setting = TestSetting()
        self.test_setting.title = 'Site title'
        self.test_setting.email = '*****@*****.**'
        self.test_setting.site = default_site
        self.test_setting.save()

        self.login()

    def test_get_edit(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)
        # there should be a menu item highlighted as active
        self.assertContains(response, "menu-active")

    def test_non_existant_model(self):
        response = self.client.get(reverse('wagtailsettings:edit', args=['test', 'foo', 1]))
        self.assertEqual(response.status_code, 404)

    def test_edit_invalid(self):
        response = self.post(post_data={'foo': 'bar'})
        self.assertContains(response, "The setting could not be saved due to errors.")
        self.assertContains(response, "This field is required.")

    def test_edit(self):
        response = self.post(post_data={'title': 'Edited site title',
                                        'email': '*****@*****.**'})
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, 'Edited site title')
        self.assertEqual(setting.email, '*****@*****.**')