Exemplo n.º 1
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)
Exemplo n.º 2
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))
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def test_get_version_for_multiple_versions(self):
     with freeze_time("2010-10-10"):
         page_content = PageContentWithVersionFactory(
             version__state=ARCHIVED)
     latest_version = PageVersionFactory(content__page=page_content.page)
     self.assertEqual(get_version(page_content.page), latest_version)
Exemplo n.º 5
0
 def test_get_version(self):
     version = PageVersionFactory()
     self.assertEqual(get_version(version.content.page), version)