Exemple #1
0
 def setUp(self):
     self.client = Client()
     self.user = ProfileFactory().user_object
     grant_privilege(self.user, u'Theme Editor')
     self.version = StyleVersionFactory()
     self.active_version = StyleVersionFactory(currently_live=True,
                                               currently_test=True)
     self.url = reverse(self.view_name,
                        urlconf="gbe.themes.urls",
                        args=[self.version.pk, "live"])
     self.return_url = reverse("themes_list", urlconf="gbe.themes.urls")
     self.title = "List of Themes and Versions"
 def test_special_test_style_switch(self):
     version = StyleVersionFactory()
     version.currently_test = True
     version.save()
     value = StyleValueFactory(style_version=version)
     response = self.client.get(self.url)
     self.assertContains(response, "%s {" % value.style_property.selector)
     self.assertContains(
         response,
         "    %s: %s" % (value.style_property.style_property, value.value))
     self.assertNotContains(response, ".gbe-alert-success {")
     self.assertNotContains(response,
                            "    background-color: rgba(212,237,218,1);")
 def test_image_style(self):
     version = StyleVersionFactory()
     version.currently_live = True
     version.save()
     Image.objects.all().delete()
     value = StyleValueImageFactory(
         style_version=version, image=set_image(folder_name='Backgrounds'))
     response = self.client.get(self.url)
     self.assertContains(response,
                         "%s {" % value.style_property.selector,
                         count=1)
     self.assertContains(
         response,
         "    %s: %s" % (value.style_property.style_property, value.value))
     self.assertContains(response, "url(%s)" % value.image.url)
 def test_list_all_the_things(self):
     boring_version = StyleVersionFactory()
     login_as(self.user, self)
     response = self.client.get(self.url)
     self.assertContains(response, self.version.name)
     self.assertContains(response, boring_version.name)
     self.assertContains(response,
                         '<i class="gbe-text-success fas fa-check-circle"',
                         2)
     self.assertContains(
         response,
         reverse("manage_theme",
                 urlconf="gbe.themes.urls",
                 args=[self.version.pk]))
     self.assertContains(
         response,
         reverse("manage_theme",
                 urlconf="gbe.themes.urls",
                 args=[boring_version.pk]))
     self.assertContains(
         response,
         reverse("clone_theme",
                 urlconf="gbe.themes.urls",
                 args=[self.version.pk]))
     self.assertContains(
         response,
         reverse("clone_theme",
                 urlconf="gbe.themes.urls",
                 args=[boring_version.pk]))
 def setUp(self):
     self.client = Client()
     self.user = ProfileFactory().user_object
     grant_privilege(self.user, u'Theme Editor')
     self.version = StyleVersionFactory(currently_live=True,
                                        currently_test=True)
     self.url = reverse(self.view_name, urlconf="gbe.themes.urls")
 def test_preview_persistence(self):
     version = StyleVersionFactory()
     version.currently_live = True
     version.save()
     preview_setting = UserStylePreviewFactory()
     value = StyleValueFactory(style_version=preview_setting.version)
     live_value = StyleValueFactory(style_version=version)
     login_as(preview_setting.previewer, self)
     response = self.client.get(self.url)
     self.assertContains(response, "%s {" % value.style_property.selector)
     self.assertContains(
         response,
         "    %s: %s" % (value.style_property.style_property, value.value))
     self.assertNotContains(response,
                            "%s {" % live_value.style_property.selector)
     self.assertNotContains(
         response, "    %s: %s" %
         (live_value.style_property.style_property, live_value.value))
 def test_special_live_style_switch(self):
     version = StyleVersionFactory()
     version.currently_live = True
     version.save()
     value = StyleValueFactory(style_version=version)
     response = self.client.get(self.url)
     self.assertContains(response, "%s {" % value.style_property.selector)
     self.assertContains(
         response,
         "    %s: %s" % (value.style_property.style_property, value.value))
     self.assertNotContains(response, ".gbe-alert-success {")
     self.assertNotContains(response,
                            "    background-color: rgba(212,237,218,1);")
     self.assertEquals(
         str(version), "{} - version {:.1f}".format(version.name,
                                                    version.number))
     self.assertEquals(
         str(value.style_property),
         "%s - %s" % (value.style_property.selector,
                      value.style_property.style_property))
Exemple #8
0
 def test_get_empty(self):
     empty = StyleVersionFactory()
     login_as(self.user, self)
     response = self.client.get(
         reverse(self.view_name, urlconf="gbe.themes.urls",
                 args=[empty.pk]))
     self.assertContains(
         response,
         "Manage {}, version {:.1f}".format(empty.name, empty.number))
     self.assertContains(
         response,
         reverse("theme_style", urlconf="gbe.themes.urls", args=[empty.pk]))
 def test_ondemand_switch(self):
     version = StyleVersionFactory()
     version.save()
     value = StyleValueFactory(style_version=version)
     response = self.client.get(
         reverse(self.view_name,
                 urlconf="gbe.themes.urls",
                 args=[version.pk]))
     self.assertContains(response, "%s {" % value.style_property.selector)
     self.assertContains(
         response,
         "    %s: %s" % (value.style_property.style_property, value.value))
     self.assertNotContains(response, ".gbe-alert-success {")
     self.assertNotContains(response,
                            "    background-color: rgba(212,237,218,1);")
     self.assertEquals(
         str(version), "{} - version {:.1f}".format(version.name,
                                                    version.number))
     self.assertEquals(
         str(value.style_property),
         "%s - %s" % (value.style_property.selector,
                      value.style_property.style_property))
Exemple #10
0
 def test_get_empty(self):
     empty = StyleVersionFactory()
     login_as(self.user, self)
     response = self.client.get(
         reverse(self.view_name, urlconf="gbe.themes.urls",
                 args=[empty.pk]))
     self.assertContains(
         response,
         '<input type="text" name="name" maxlength="128" required ' +
         'id="id_name">',
         html=True)
     self.assertContains(
         response,
         '<input type="number" name="number" value="1.0" min="0.1" ' +
         'step="any" required id="id_number">',
         html=True)
class TestDeleteTheme(TestCase):
    view_name = "delete_theme"
    delete_link = '<a class="gbe-detail" href="%s" title="Delete">'

    def setUp(self):
        StyleVersion.objects.all().delete()
        self.client = Client()
        self.user = ProfileFactory().user_object
        grant_privilege(self.user, u'Theme Editor')
        self.version = StyleVersionFactory()
        self.active_version = StyleVersionFactory(currently_live=True,
                                                  currently_test=True)
        self.url = reverse(
            self.view_name,
            urlconf="gbe.themes.urls",
            args=[self.version.pk])
        self.return_url = reverse("themes_list", urlconf="gbe.themes.urls")
        self.title = "List of Themes and Versions"

    def test_no_login(self):
        response = self.client.get(self.url)
        self.assertRedirects(response,
                             "/login/?next=%s" % self.url,
                             fetch_redirect_response=False)

    def test_delete_succeed(self):
        login_as(self.user, self)
        response = self.client.get(self.url, follow=True)
        self.assertRedirects(response, self.return_url)
        self.assertContains(response, self.title)
        self.assertContains(response, "Deleted Theme %s" % str(self.version))
        self.assertNotContains(
            response,
            self.delete_link % reverse(
                self.view_name,
                urlconf="gbe.themes.urls",
                args=[self.version.pk]))

    def test_delete_bad_id(self):
        login_as(self.user, self)
        response = self.client.get(reverse(
            self.view_name,
            urlconf="gbe.themes.urls",
            args=[self.active_version.pk+1]))
        self.assertEqual(404, response.status_code)

    def test_delete_active_theme(self):
        login_as(self.user, self)
        self.url = reverse(
            self.view_name,
            urlconf="gbe.themes.urls",
            args=[self.active_version.pk])
        response = self.client.get(self.url, follow=True)
        self.assertRedirects(
            response,
            "%s?error_id=%d" % (self.return_url, self.active_version.pk))
        self.assertContains(response, self.title)
        self.assertContains(
            response,
            user_messages["CURRENTLY_ACTIVE"]['description'] + "  TARGET: " +
            str(self.active_version))
        self.assertContains(
            response,
            self.delete_link % reverse(
                self.view_name,
                urlconf="gbe.themes.urls",
                args=[self.active_version.pk]))

    def test_delete_last_theme(self):
        login_as(self.user, self)
        self.active_version.delete()
        response = self.client.get(self.url, follow=True)
        self.assertRedirects(
            response,
            "%s?error_id=%d" % (self.return_url, self.version.pk))
        self.assertContains(response, self.title)
        self.assertContains(
            response,
            user_messages["LAST_THEME"]['description'] + "  TARGET: " +
            str(self.version))
        self.assertContains(
            response,
            self.delete_link % reverse(
                self.view_name,
                urlconf="gbe.themes.urls",
                args=[self.version.pk]))