예제 #1
0
    def test_each_assignment(self):
        user1 = UserFactory(is_staff=False)
        user2 = UserFactory(is_staff=False)
        bootstrap = Mock(users={"user1": user1, "user2": user2})
        component = Pages(bootstrap)
        component.each(
            "page1",
            {
                "title": "Test page",
                "template": "INHERIT",
                "language": "en",
                "created_by": "user1",
                "assignments": [{
                    "user": "******",
                    "can_view": True
                }],
            },
        )

        self.assertIn("page1", component.data)
        page = component.data["page1"]
        version = get_version(page)
        self.assertEqual(version.content.title, "Test page")
        self.assertEqual(version.content.language, "en")
        self.assertEqual(version.created_by, user1)
        self.assertTrue(page.has_view_permission(user1))
        self.assertFalse(page.has_view_permission(user2))
예제 #2
0
    def test_each_content(self):
        user = UserFactory()
        bootstrap = Mock(users={"user1": user})
        component = Pages(bootstrap)
        component.each(
            "page1",
            {
                "title":
                "Test page",
                "template":
                "INHERIT",
                "language":
                "en",
                "created_by":
                "user1",
                "content": [{
                    "type": "TextPlugin",
                    "body": "<h1>Test content</h1>"
                }],
                "publish":
                True,
            },
        )
        self.assertIn("page1", component.data)
        version = get_version(component.data["page1"])
        response = self.client.get(version.content.get_absolute_url())

        self.assertEqual(version.content.title, "Test page")
        self.assertEqual(version.content.language, "en")
        self.assertEqual(version.created_by, user)
        self.assertEqual(version.state, PUBLISHED)
        self.assertEqual(response.status_code, 200)
        self.assertIn(b"<h1>Test content</h1>", response.content)
예제 #3
0
 def test_parse(self):
     component = Pages(Mock())
     component.raw_data = {"page1": "bar", "page2": "baz"}
     with patch.object(component, "each") as each:
         component.parse()
     each.assert_has_calls(
         [call("page1", "bar"), call("page2", "baz")], any_order=True)
예제 #4
0
 def test_add_plugin_with_children(self):
     component = Pages(Mock())
     placeholder = PlaceholderFactory()
     with patch("djangocms_fil_bootstrap.components.pages.add_plugin"
                ) as add_plugin:
         component.add_plugin(
             placeholder,
             {
                 "type": "TestPlugin",
                 "children": [{
                     "type": "TestPlugin",
                     "child_data": "bar"
                 }],
                 "plugin_data": "foo",
             },
             "en",
         )
     add_plugin.assert_has_calls(
         [
             call(placeholder,
                  "TestPlugin",
                  "en",
                  target=None,
                  plugin_data="foo"),
             call(
                 placeholder,
                 "TestPlugin",
                 "en",
                 target=add_plugin.return_value,
                 child_data="bar",
             ),
         ],
         any_order=True,
     )
예제 #5
0
 def test_add_plugin(self):
     component = Pages(Mock())
     placeholder = PlaceholderFactory()
     with patch("djangocms_fil_bootstrap.components.pages.add_plugin"
                ) as add_plugin:
         component.add_plugin(placeholder, {
             "type": "TestPlugin",
             "plugin_data": "foo"
         }, "en")
     add_plugin.assert_called_once_with(placeholder,
                                        "TestPlugin",
                                        "en",
                                        target=None,
                                        plugin_data="foo")
예제 #6
0
 def test_each(self):
     user = UserFactory()
     bootstrap = Mock(users={"user1": user})
     component = Pages(bootstrap)
     component.each(
         "page1",
         {
             "title": "Test page",
             "template": "INHERIT",
             "language": "en",
             "created_by": "user1",
         },
     )
     self.assertIn("page1", component.data)
     version = get_version(component.data["page1"])
     self.assertEqual(version.content.title, "Test page")
     self.assertEqual(version.content.language, "en")
     self.assertEqual(version.created_by, user)
     self.assertEqual(version.state, DRAFT)