Ejemplo n.º 1
0
    def test_copy_page_copies_tags(self):
        # create and publish a TaggedPage under Events
        event_index = Page.objects.get(url_path='/home/events/')
        tagged_page = TaggedPage(title='My tagged page', slug='my-tagged-page')
        tagged_page.tags.add('wagtail', 'bird')
        event_index.add_child(instance=tagged_page)
        tagged_page.save_revision().publish()

        old_tagged_item_ids = [item.id for item in tagged_page.tagged_items.all()]
        # there should be two items here, with defined (truthy) IDs
        self.assertEqual(len(old_tagged_item_ids), 2)
        self.assertTrue(all(old_tagged_item_ids))

        # copy to underneath homepage
        homepage = Page.objects.get(url_path='/home/')
        new_tagged_page = tagged_page.copy(to=homepage)

        self.assertNotEqual(tagged_page.id, new_tagged_page.id)

        # new page should also have two tags
        new_tagged_item_ids = [item.id for item in new_tagged_page.tagged_items.all()]
        self.assertEqual(len(new_tagged_item_ids), 2)
        self.assertTrue(all(new_tagged_item_ids))

        # new tagged_item IDs should differ from old ones
        self.assertTrue(all([
            item_id not in old_tagged_item_ids
            for item_id in new_tagged_item_ids
        ]))
Ejemplo n.º 2
0
    def test_copy_page_copies_tags(self):
        # create and publish a TaggedPage under Events
        event_index = Page.objects.get(url_path='/home/events/')
        tagged_page = TaggedPage(title='My tagged page', slug='my-tagged-page')
        tagged_page.tags.add('wagtail', 'bird')
        event_index.add_child(instance=tagged_page)
        tagged_page.save_revision().publish()

        old_tagged_item_ids = [item.id for item in tagged_page.tagged_items.all()]
        # there should be two items here, with defined (truthy) IDs
        self.assertEqual(len(old_tagged_item_ids), 2)
        self.assertTrue(all(old_tagged_item_ids))

        # copy to underneath homepage
        homepage = Page.objects.get(url_path='/home/')
        new_tagged_page = tagged_page.copy(to=homepage)

        self.assertNotEqual(tagged_page.id, new_tagged_page.id)

        # new page should also have two tags
        new_tagged_item_ids = [item.id for item in new_tagged_page.tagged_items.all()]
        self.assertEqual(len(new_tagged_item_ids), 2)
        self.assertTrue(all(new_tagged_item_ids))

        # new tagged_item IDs should differ from old ones
        self.assertTrue(all([
            item_id not in old_tagged_item_ids
            for item_id in new_tagged_item_ids
        ]))
Ejemplo n.º 3
0
    def create_related_pages(self):
        # Create some additional pages.
        pliny = self.root_page.add_child(instance=TaggedPage(
            title   = 'Pliny the Elder',
            slug    = 'pliny-elder'
        ))

        anchor_porter = self.root_page.add_child(instance=TaggedPage(
            title   = 'Anchor Porter',
            slug    = 'anchor-porter'
        ))

        # Relate pages through tags.
        for tag in [self.beer.tag, self.ale.tag, self.ipa.tag, self.fruity]:
            self.child_page.tags.through.objects.create(
                content_object  = self.child_page,
                tag             = tag
            )
        for tag in [self.beer.tag, self.ale.tag, self.ipa.tag, self.piny]:
            pliny.tags.through.objects.create(
                content_object  = pliny,
                tag             = tag
            )
        for tag in [self.beer.tag, self.ale.tag, self.porter.tag]:
            anchor_porter.tags.through.objects.create(
                content_object  = anchor_porter,
                tag             = tag
            )

        self.pliny          = pliny
        self.anchor_porter  = anchor_porter
Ejemplo n.º 4
0
    def setUp(self):
        # Create some categories.
        self.category       = Category.add_root(name='category')
        self.sub_category   = self.category.add_child(name='sub category')

        # Get the root page.
        self.root_page = Page.objects.get(id=2)

        # Add a published page.
        self.published = self.root_page.add_child(instance=TaggedPage(
            title   = 'Published Page',
            slug    = 'published-page'
        ))

        # Add a future published page.
        self.unpublished = self.root_page.add_child(instance=TaggedPage(
            title   = 'Unpublished Page',
            slug    = 'unpublished-page'
        ))
        self.unpublished.save_revision(
            approved_go_live_at=timezone.now() + timezone.timedelta(days=3)
        )

        # Add a tag to both pages.
        for page in [self.published, self.unpublished]:
            page.tags.through.objects.create(
                content_object  = page,
                tag             = self.sub_category.tag
            )
Ejemplo n.º 5
0
    def test_has_changed(self):
        a = TaggedPage()
        a.tags.add('wagtail')
        a.tags.add('bird')

        b = TaggedPage()
        b.tags.add('wagtail')
        b.tags.add('motacilla')

        comparison = self.comparison_class(TaggedPage._meta.get_field('tags'), a, b)

        self.assertEqual(comparison.htmldiff(), 'wagtail, <span class="deletion">bird</span>, <span class="addition">motacilla</span>')
        self.assertIsInstance(comparison.htmldiff(), SafeText)
        self.assertTrue(comparison.has_changed())
Ejemplo n.º 6
0
    def test_hasnt_changed(self):
        a = TaggedPage()
        a.tags.add('wagtail')
        a.tags.add('bird')

        b = TaggedPage()
        b.tags.add('wagtail')
        b.tags.add('bird')

        comparison = self.comparison_class(TaggedPage._meta.get_field('tags'), a, b)

        self.assertTrue(comparison.is_field)
        self.assertFalse(comparison.is_child_relation)
        self.assertEqual(comparison.field_label(), "Tags")
        self.assertEqual(comparison.htmldiff(), 'wagtail, bird')
        self.assertIsInstance(comparison.htmldiff(), SafeText)
        self.assertFalse(comparison.has_changed())
Ejemplo n.º 7
0
    def setUp(self):
        # Get the root page.
        self.root_page = Page.objects.get(id=2)

        # Create a tag.
        self.tag = Tag.objects.create(name='Test')

        # Add a page.
        self.child_page = self.root_page.add_child(instance=TaggedPage(
            title   = 'Test Page',
            slug    = 'test-page'
        ))

        # Add a tag to the page.
        self.child_page.tags.through.objects.create(
            content_object  = self.child_page,
            tag             = self.tag
        )
Ejemplo n.º 8
0
    def setUp(self):
        # Create some categories.
        self.beer       = Category.add_root(name='beer')
        self.ale        = self.beer.add_child(name='ale')
        self.ipa        = self.ale.add_child(name='india pale ale')
        self.porter     = self.ale.add_child(name='porter')

        # Create some tags.
        self.spicy  = Tag.objects.create(name='spicy')
        self.fruity = Tag.objects.create(name='fruity')
        self.piny   = Tag.objects.create(name='piny')

        # Find root page.
        self.root_page = Page.objects.get(id=2)

        # Add child page.
        self.child_page = TaggedPage(title='Sculpin', slug='sculpin')
        self.root_page.add_child(instance=self.child_page)

        # Get corresponding Entity instance.
        self.entry= Entry.objects.get_for_model(self.child_page)[0]