def test_publish_selected_logs_publication(self): self.admin_site.register(Page, PublishableAdmin) pages = Page.objects.exclude(id=self.fp3.id) dummy_request = self.build_post_request({'post': True}) publish_selected(self.page_admin, dummy_request, pages) # should have logged two publications from django.contrib.admin.models import LogEntry from django.contrib.contenttypes.models import ContentType ContentType.objects.get_for_model(self.fp1).pk self.failUnlessEqual(2, LogEntry.objects.filter().count())
def test_publish_selected_confirmed(self): pages = Page.objects.exclude(id=self.fp3.id) class dummy_request(object): POST = {'post': True} class user(object): @classmethod def is_authenticated(cls): return True @classmethod def has_perm(cls, *arg): return True 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_selected_does_not_have_permission(self): self.admin_site.register(Page, PublishableAdmin) pages = Page.objects.exclude(id=self.fp3.id) class dummy_request(object): POST = {} META = {} class user(object): @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_selected_does_not_have_related_permission(self): # check we can't publish when we don't have permission # for a related model (in this case authors) self.admin_site.register(Author, PublishableAdmin) author = Author.objects.create(name='John') self.fp1.authors.add(author) pages = Page.objects.draft() dummy_request = self.build_post_request({'post': True}) dummy_request.user = self.build_common_user() try: publish_selected(self.page_admin, dummy_request, pages) self.fail() except PermissionDenied: pass self.failIf(Page.objects.published().count() > 0)
def test_publish_selected_confirmed(self): pages = Page.objects.exclude(id=self.fp3.id) dummy_request = self.build_post_request({'post': True}) 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_selected_does_not_have_permission(self): self.admin_site.register(Page, PublishableAdmin) pages = Page.objects.exclude(id=self.fp3.id) dummy_request = self.build_post_request({}) dummy_request.user = self.build_common_user() 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_selected_logs_publication(self): self.admin_site.register(Page, PublishableAdmin) pages = Page.objects.exclude(id=self.fp3.id) class dummy_request(object): POST = {'post': True} class user(object): pk = 1 @classmethod def is_authenticated(cls): return True @classmethod def has_perm(cls, perm): return perm != 'example_app.publish_author' class message_set(object): @classmethod def create(cls, message=None): pass class _messages(object): @classmethod def add(cls, *message): pass publish_selected(self.page_admin, dummy_request, pages) # should have logged two publications from django.contrib.admin.models import LogEntry from django.contrib.contenttypes.models import ContentType ContentType.objects.get_for_model(self.fp1).pk self.failUnlessEqual(2, LogEntry.objects.filter().count())
def test_publish_selected_does_not_have_related_permission(self): # check we can't publish when we don't have permission # for a related model (in this case authors) self.admin_site.register(Author, PublishableAdmin) author = Author.objects.create(name='John') self.fp1.authors.add(author) pages = Page.objects.draft() class dummy_request(object): POST = {'post': True} class _messages(object): @classmethod def add(cls, *args): return 'message' class user(object): pk = 1 @classmethod def is_authenticated(cls): return True @classmethod def has_perm(cls, perm): return perm != 'example_app.publish_author' try: publish_selected(self.page_admin, dummy_request, pages) self.fail() except PermissionDenied: pass self.failIf(Page.objects.published().count() > 0)
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) self.failIf(Page.objects.published().count() > 0) self.failUnless(response is not None) self.failUnlessEqual(200, response.status_code)