예제 #1
0
 def test_publish_records_published(self):
     all_published = NestedSet()
     self.flat_page.save()
     self.flat_page.publish(all_published=all_published)
     self.failUnlessEqual(1, len(all_published))
     self.failUnless(self.flat_page in all_published)
     self.failUnless(self.flat_page.public)
예제 #2
0
 def test_publish_dryrun(self):
     all_published = NestedSet()
     self.flat_page.save()
     self.flat_page.publish(dry_run=True, all_published=all_published)
     self.failUnlessEqual(1, len(all_published))
     self.failUnless(self.flat_page in all_published)
     self.failIf(self.flat_page.public)
     self.failUnlessEqual(Publishable.PUBLISH_CHANGED,
                          self.flat_page.publish_state)
예제 #3
0
        def test_publish_deletions_checks_all_published(self):
            # make sure publish_deletions looks at all_published arg
            # to see if we need to actually publish the deletion
            self.flat_page.save()
            self.flat_page.publish()
            public = self.flat_page.public

            self.flat_page.delete()

            self.failUnlessEqual(set([self.flat_page, public]),
                                 set(FlatPage.objects.all()))

            # this should effectively stop the deletion happening
            all_published = NestedSet()
            all_published.add(self.flat_page)

            self.flat_page.publish(all_published=all_published)
            self.failUnlessEqual(set([self.flat_page, public]),
                                 set(FlatPage.objects.all()))
    def test_publish_deletions_checks_all_published(self):
        # make sure publish_deletions looks at all_published arg
        # to see if we need to actually publish the deletion
        self.flat_page.save()
        self.flat_page.publish()
        public = self.flat_page.public

        self.flat_page.delete()

        self.failUnlessEqual(set([self.flat_page, public]),
                             set(FlatPage.objects.all()))

        # this should effectively stop the deletion happening
        all_published = NestedSet()
        all_published.add(self.flat_page)

        self.flat_page.publish(all_published=all_published)
        self.failUnlessEqual(set([self.flat_page, public]),
                             set(FlatPage.objects.all()))
    def test_convert_all_published_to_html(self):
        self.admin_site.register(Page, PublishableAdmin)

        all_published = NestedSet()

        page = Page.objects.create(slug='here', title='title')
        block = PageBlock.objects.create(page=page, content='stuff here')

        all_published.add(page)
        all_published.add(block, parent=page)

        converted = _convert_all_published_to_html(self.admin_site,
                                                   all_published)

        expected = [
            u'<a href="../../example_app/page/%d/">Page: here (Changed - '
            u'not yet published)</a>' % page.id,
            [u'Page block: PageBlock object']]

        self.failUnlessEqual(expected, converted)
예제 #6
0
        def test_publish_with_overlapping_models_published(self):
            # make sure when we publish we don't accidentally create
            # multiple published versions
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())

            all_published = NestedSet()
            Page.objects.draft().publish(all_published)

            self.failUnlessEqual(5, len(all_published))

            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(5, Page.objects.published().count())
예제 #7
0
        def test_publish_after_dry_run_handles_caching(self):
            # if we do a dry tun publish in the same queryset
            # before publishing for real, we have to make
            # sure we don't run into issues with the instance
            # caching parent's as None
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())

            draft = Page.objects.draft()

            all_published = NestedSet()
            for p in draft:
                p.publish(dry_run=True, all_published=all_published)

            # nothing published yet
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())

            # now publish (using same queryset, as this will have cached the instances)
            draft.publish()

            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(5, Page.objects.published().count())

            # now actually check the public parent's are setup right
            page1 = Page.objects.get(id=self.page1.id)
            page2 = Page.objects.get(id=self.page2.id)
            child1 = Page.objects.get(id=self.child1.id)
            child2 = Page.objects.get(id=self.child2.id)
            child3 = Page.objects.get(id=self.child3.id)

            self.failUnlessEqual(None, page1.public.parent)
            self.failUnlessEqual(None, page2.public.parent)
            self.failUnlessEqual(page1.public, child1.public.parent)
            self.failUnlessEqual(page1.public, child2.public.parent)
            self.failUnlessEqual(page2.public, child3.public.parent)
예제 #8
0
        def test_convert_all_published_to_html(self):
            self.admin_site.register(Page, PublishableAdmin)

            all_published = NestedSet()

            page = Page.objects.create(slug='here', title='title')
            block = PageBlock.objects.create(page=page, content='stuff here')

            all_published.add(page)
            all_published.add(block, parent=page)

            converted = _convert_all_published_to_html(self.admin_site,
                                                       all_published)

            expected = [
                u'<a href="../../publish/page/%d/">Page: Page object (Changed - not yet published)</a>'
                % page.id, [u'Page block: PageBlock object']
            ]

            self.failUnlessEqual(expected, converted)
예제 #9
0
 def setUp(self):
     super(TestNestedSet, self).setUp()
     self.nested = NestedSet()
예제 #10
0
    class TestNestedSet(unittest.TestCase):

        def setUp(self):
            super(TestNestedSet, self).setUp()
            self.nested = NestedSet()

        def test_len(self):
            self.failUnlessEqual(0, len(self.nested))
            self.nested.add('one')
            self.failUnlessEqual(1, len(self.nested))
            self.nested.add('two')
            self.failUnlessEqual(2, len(self.nested))
            self.nested.add('one2', parent='one')
            self.failUnlessEqual(3, len(self.nested))

        def test_contains(self):
            self.failIf('one' in self.nested)
            self.nested.add('one')
            self.failUnless('one' in self.nested)
            self.nested.add('one2', parent='one')
            self.failUnless('one2' in self.nested)

        def test_nested_items(self):
            self.failUnlessEqual([], self.nested.nested_items())
            self.nested.add('one')
            self.failUnlessEqual(['one'], self.nested.nested_items())
            self.nested.add('two')
            self.nested.add('one2', parent='one')
            self.failUnlessEqual(['one', ['one2'], 'two'], self.nested.nested_items())
            self.nested.add('one2-1', parent='one2')
            self.nested.add('one2-2', parent='one2')
            self.failUnlessEqual(['one', ['one2', ['one2-1', 'one2-2']], 'two'], self.nested.nested_items())

        def test_iter(self):
            self.failUnlessEqual(set(), set(self.nested))

            self.nested.add('one')
            self.failUnlessEqual(set(['one']), set(self.nested))

            self.nested.add('two', parent='one')
            self.failUnlessEqual(set(['one', 'two']), set(self.nested))

            items = set(['one', 'two'])

            for item in self.nested:
                self.failUnless(item in items)
                items.remove(item)

            self.failUnlessEqual(set(), items)

        def test_original(self):
            class MyObject(object):
                def __init__(self, obj):
                    self.obj = obj

                def __eq__(self, other):
                    return self.obj == other.obj

                def __hash__(self):
                    return hash(self.obj)

            # should always return an item at least
            self.failUnlessEqual(MyObject('hi there'), self.nested.original(MyObject('hi there')))

            m1 = MyObject('m1')
            self.nested.add(m1)

            self.failUnlessEqual(id(m1), id(self.nested.original(m1)))
            self.failUnlessEqual(id(m1), id(self.nested.original(MyObject('m1'))))
예제 #11
0
 def setUp(self):
     super(TestNestedSet, self).setUp()
     self.nested = NestedSet()
예제 #12
0
class TestNestedSet(TestCase):
    def setUp(self):
        super(TestNestedSet, self).setUp()
        self.nested = NestedSet()

    def test_len(self):
        self.failUnlessEqual(0, len(self.nested))
        self.nested.add('one')
        self.failUnlessEqual(1, len(self.nested))
        self.nested.add('two')
        self.failUnlessEqual(2, len(self.nested))
        self.nested.add('one2', parent='one')
        self.failUnlessEqual(3, len(self.nested))

    def test_contains(self):
        self.failIf('one' in self.nested)
        self.nested.add('one')
        self.failUnless('one' in self.nested)
        self.nested.add('one2', parent='one')
        self.failUnless('one2' in self.nested)

    def test_nested_items(self):
        self.failUnlessEqual([], self.nested.nested_items())
        self.nested.add('one')
        self.failUnlessEqual(['one'], self.nested.nested_items())
        self.nested.add('two')
        self.nested.add('one2', parent='one')
        self.failUnlessEqual(['one', ['one2'], 'two'],
                             self.nested.nested_items())
        self.nested.add('one2-1', parent='one2')
        self.nested.add('one2-2', parent='one2')
        self.failUnlessEqual(['one', ['one2', ['one2-1', 'one2-2']], 'two'],
                             self.nested.nested_items())

    def test_iter(self):
        self.failUnlessEqual(set(), set(self.nested))

        self.nested.add('one')
        self.failUnlessEqual(set(['one']), set(self.nested))

        self.nested.add('two', parent='one')
        self.failUnlessEqual(set(['one', 'two']), set(self.nested))

        items = set(['one', 'two'])

        for item in self.nested:
            self.failUnless(item in items)
            items.remove(item)

        self.failUnlessEqual(set(), items)

    def test_original(self):
        class MyObject(object):
            def __init__(self, obj):
                self.obj = obj

            def __eq__(self, other):
                return self.obj == other.obj

            def __hash__(self):
                return hash(self.obj)

        # should always return an item at least
        self.failUnlessEqual(MyObject('hi there'),
                             self.nested.original(MyObject('hi there')))

        m1 = MyObject('m1')
        self.nested.add(m1)

        self.failUnlessEqual(id(m1), id(self.nested.original(m1)))
        self.failUnlessEqual(id(m1), id(self.nested.original(MyObject('m1'))))