示例#1
0
    def test_form_view_edit(self):
        """
        Plugin edition form should return a success status code and every
        expected field should be present in HTML.
        """
        # Create random values for parameters with a factory
        slider = SliderFactory()
        item = SlideItemFactory.create(slider=slider, )

        # Connect a dummy admin
        staff = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=staff.username, password="******")

        # Create dummy page
        page = create_page(
            language="en",
            title="Dummy",
            slug="dummy",
            template="pages/default.html",
        )

        # Add slider plugin to placeholder
        placeholder = page.placeholders.get(slot="content")
        model_instance = add_plugin(
            placeholder,
            SliderPlugin,
            "en",
            template=slider.template,
            title=slider.title,
        )
        model_instance.copy_relations(slider)

        # Get the edition plugin form url and open it
        url = admin_reverse('cms_page_edit_plugin', args=[model_instance.id])
        response = self.client.get(url)

        html = response.content.decode("utf-8")

        # Expected http success status
        self.assertEqual(response.status_code, 200)

        # Check expected slider fields are present
        self.assertIsNotNone(re.search((r'<select.*id="id_template".*>'),
                                       html))
        self.assertIsNotNone(
            re.search((r'<input.*type="text.*id="id_title".*>'), html))
        # Check only a single expected empty field
        self.assertIsNotNone(
            re.search((
                r'<input.*type="file.*id="id_slide_item-__prefix__-image".*>'),
                      html))
        # Check only a single expected filled field
        self.assertIsNotNone(
            re.search((r'<input.*type="file.*id="id_slide_item-0-image".*>'),
                      html))
示例#2
0
    def test_form_view_edit(self):
        """
        Plugin edition form should return a success status code and every
        expected field should be present in HTML.
        """
        # Create random values for parameters with a factory
        hero = HeroFactory(content="<p>Lorem ipsum dolore</p>")

        # Connect a dummy admin
        staff = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=staff.username, password="******")

        # Create dummy page
        page = create_page(
            language="en",
            title="Dummy",
            slug="dummy",
            template="pages/default.html",
        )

        # Add hero plugin to placeholder
        placeholder = page.placeholders.get(slot="content")
        model_instance = add_plugin(
            placeholder,
            HeroPlugin,
            "en",
            template=hero.template,
            image=hero.image,
            content=hero.content,
        )

        # Get the edition plugin form url and open it
        url = admin_reverse('cms_page_edit_plugin', args=[model_instance.id])
        response = self.client.get(url)

        html = response.content.decode("utf-8")

        # Expected http success status
        self.assertEqual(response.status_code, 200)

        # Check all expected fields are present
        self.assertIsNotNone(re.search((r'<select.*id="id_template".*>'),
                                       html))
        self.assertIsNotNone(
            re.search((r'<input.*type="file.*id="id_image".*>'), html))
        self.assertIsNotNone(
            re.search((r'<textarea.*id="id_content".*>'), html))
示例#3
0
    def test_form_view_add(self):
        """
        Plugin creation form should return a success status code and every
        expected field should be present in HTML.
        """
        # Connect a dummy admin
        staff = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=staff.username, password="******")

        # Create dummy page
        page = create_page(
            language="en",
            title="Dummy",
            slug="dummy",
            template="pages/default.html",
        )

        # Get placeholder
        placeholder = page.placeholders.get(slot="content")

        # Get the edition plugin form url and open it
        url = admin_reverse('cms_page_add_plugin')
        response = self.client.get(
            url, {
                'plugin_type': 'HeroPlugin',
                'placeholder_id': placeholder.pk,
                'target_language': 'en',
                'plugin_language': 'en',
            })

        html = response.content.decode("utf-8")

        # Expected http success status
        self.assertEqual(response.status_code, 200)

        # Check all expected fields are present
        self.assertIsNotNone(re.search((r'<select.*id="id_template".*>'),
                                       html))
        self.assertIsNotNone(
            re.search((r'<input.*type="file.*id="id_image".*>'), html))
        self.assertIsNotNone(
            re.search((r'<textarea.*id="id_content".*>'), html))