Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# make sure child elements get removed
page_block = PageBlock.objects.create(page=self.page1, content='here we are')
self.page1.publish()
public = self.page1.public
page_block = PageBlock.objects.get(id=page_block.id)
page_block_public = page_block.public
self.failIf(page_block_public is None)
self.failUnlessEqual([page_block_public], list(public.pageblock_set.all()))
# now delete the page block and publish the parent
# to make sure that deletion gets copied over properly
page_block.delete()
page1 = Page.objects.get(id=self.page1.id)
page1.publish()
public = page1.public
self.failUnlessEqual([], list(public.pageblock_set.all()))
def test_only_draft_shown(self):
self.author = Author.objects.create(name='author')
self.author.publish()
self.failUnless(2, Author.objects.count())
# make sure the publishable filter spec
# gets used when we use a publishable field
class dummy_request(object):
GET = {}
spec = FieldListFilter.create(Page._meta.get_field('authors'), dummy_request, {}, Page, PublishableAdmin, None)
lookup_choices = spec.lookup_choices
self.failUnlessEqual(1, len(lookup_choices))
pk, label = lookup_choices[0]
self.failUnlessEqual(self.author.id, pk)
def test_signals_sent_for_followed(self):
pre_published = []
def pre_publish_handler(sender, instance, **kw):
pre_published.append(instance)
pre_publish.connect(pre_publish_handler, sender=Page)
published = []
def post_publish_handler(sender, instance, **kw):
published.append(instance)
post_publish.connect(post_publish_handler, sender=Page)
# publishing just children will also publish it's parent (if needed)
# which should also fire signals
self.child1.publish()
self.failUnlessEqual(set([self.page1, self.child1]), set(pre_published))
self.failUnlessEqual(set([self.page1, self.child1]), set(published))
self.page2.publish()
self.author1 = Author.objects.create(name='a1')
self.author2 = Author.objects.create(name='a2')
self.author1.publish()
self.author2.publish()
self.admin_site = AdminSite('Test Admin')
class PageBlockInline(PublishableStackedInline):
model = PageBlock
class PageAdmin(PublishableAdmin):
inlines = [PageBlockInline]
self.admin_site.register(Page, PageAdmin)
self.page_admin = PageAdmin(Page, self.admin_site)
# override urls, so reverse works
settings.ROOT_URLCONF=patterns('',
('^admin/', include(self.admin_site.urls)),
)
def test_publish_selected_confirm(self):
pages = Page.objects.exclude(id=self.fp3.id)
class dummy_request(object):
META = {}
POST = {}
class user(object):
@classmethod
def has_perm(cls, *arg):
return True
@classmethod
def get_and_delete_messages(cls):
return []
response = publish_selected(self.page_admin, dummy_request, pages)
def test_overridden_spec(self):
# make sure the publishable filter spec
# gets used when we use a publishable field
class dummy_request(object):
GET = {}
spec = FieldListFilter.create(Page._meta.get_field('authors'), dummy_request, {}, Page, PublishableAdmin, None)
self.failUnless(isinstance(spec, PublishableRelatedFieldListFilter))
self.author1 = Author.objects.create(name='a1')
self.author2 = Author.objects.create(name='a2')
self.author1.publish()
self.author2.publish()
self.admin_site = AdminSite('Test Admin')
class PageBlockInline(PublishableStackedInline):
model = PageBlock
class PageAdmin(PublishableAdmin):
inlines = [PageBlockInline]
self.admin_site.register(Page, PageAdmin)
self.page_admin = PageAdmin(Page, self.admin_site)
# override urls, so reverse works
settings.ROOT_URLCONF=patterns('',
('^admin/', include(self.admin_site.urls)),
)
def setUp(self):
super(TestUnpublishSelectedAction, self).setUp()
self.fp1 = Page.objects.create(slug='fp1', title='FP1')
self.fp2 = Page.objects.create(slug='fp2', title='FP2')
self.fp3 = Page.objects.create(slug='fp3', title='FP3')
self.fp1.save()
self.fp2.save()
self.fp3.save()
for page in Page.objects.draft():
page.publish()
self.admin_site = AdminSite('Test Admin')
self.page_admin = PublishableAdmin(Page, self.admin_site)
# override urls, so reverse works
settings.ROOT_URLCONF=patterns('',
('^admin/', include(self.admin_site.urls)),
)
ordering = ['slug']
class PublishMeta(Publishable.PublishMeta):
publish_exclude_fields = ['log']
publish_reverse_fields = ['pageblock_set']
publish_functions = { 'pub_date': update_pub_date }
def get_absolute_url(self):
if not self.parent:
return u'/%s/' % self.slug
return '%s%s/' % (self.parent.get_absolute_url(), self.slug)
class PageTagOrder(Publishable):
# note these are named in non-standard way to
# ensure we are getting correct names
tagged_page=models.ForeignKey(Page)
page_tag=models.ForeignKey(Tag)
tag_order=models.IntegerField()