Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_publish_with_overlapping_models(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())
Page.objects.draft().publish()
self.failUnlessEqual(5, Page.objects.draft().count())
self.failUnlessEqual(5, Page.objects.published().count())
class message_set(object):
@classmethod
def create(cls, message=None):
self._message = message
class _messages(object):
@classmethod
def add(cls, *message):
self._message = message
response = publish_selected(self.page_admin, dummy_request, pages)
self.failUnlessEqual(2, Page.objects.published().count())
self.failUnless( getattr(self, '_message', None) is not None )
self.failUnless( response is None )
def test_publish_deletions(self):
self.page1.publish()
self.page2.publish()
self.page2.delete()
self.failUnlessEqual([self.page2], list(Page.objects.deleted()))
self.page2.publish()
self.failUnlessEqual([self.page1.public], list(Page.objects.published()))
self.failUnlessEqual([], list(Page.objects.deleted()))
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())
@classmethod
def has_perm(cls, *arg):
return False
@classmethod
def get_and_delete_messages(cls):
return []
response = publish_selected(self.page_admin, dummy_request, pages)
self.failIf(response is None)
# publish button should not be in response
self.failIf('value="publish_selected"' in response.content)
self.failIf('value="Yes, Publish"' in response.content)
self.failIf('form' in response.content)
self.failIf(Page.objects.published().count() > 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())
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)
self.failIf(Page.objects.published().count() > 0)
self.failUnless(response is not None)
self.failUnlessEqual(200, response.status_code)
@classmethod
def is_authenticated(cls):
return True
@classmethod
def has_perm(cls, perm):
return perm != 'publish.publish_author'
try:
publish_selected(self.page_admin, dummy_request, pages)
self.fail()
except PermissionDenied:
pass
self.failIf(Page.objects.published().count() > 0)