def test_table_name_patching(self): """ This tests the plugin models patching when publishing from the command line """ User = get_user_model() User.objects.create_superuser('djangocms', '*****@*****.**', '123456') create_page("The page!", "nav_playground.html", "en", published=True) draft = Page.objects.drafts()[0] draft.reverse_id = 'a_test' # we have to change *something* draft.save() add_plugin(draft.placeholders.get(slot=u"body"), u"TextPlugin", u"en", body="Test content") draft.publish('en') add_plugin(draft.placeholders.get(slot=u"body"), u"TextPlugin", u"en", body="Test content") # Manually undoing table name patching Text._meta.db_table = 'djangocms_text_ckeditor_text' plugin_pool.patched = False with StdoutOverride(): # Now we don't expect it to raise, but we need to redirect IO com = publisher_publish.Command() com.handle_noargs() not_drafts = len(Page.objects.filter(publisher_is_draft=False)) drafts = len(Page.objects.filter(publisher_is_draft=True)) self.assertEqual(not_drafts, 1) self.assertEqual(drafts, 1)
def test_command_line_ignores_draft_page(self): # we need to create a superuser (the db is empty) get_user_model().objects.create_superuser('djangocms', '*****@*****.**', '123456') create_page("The page!", "nav_playground.html", "en", published=False) pages_from_output = 0 published_from_output = 0 with StdoutOverride() as buffer: # Now we don't expect it to raise, but we need to redirect IO com = publisher_publish.Command() com.handle_noargs() lines = buffer.getvalue().split( '\n') #NB: readlines() doesn't work for line in lines: if 'Total' in line: pages_from_output = int(line.split(':')[1]) elif 'Published' in line: published_from_output = int(line.split(':')[1]) self.assertEqual(pages_from_output, 0) self.assertEqual(published_from_output, 0) self.assertEqual(Page.objects.public().count(), 0)
def test_command_line_should_raise_without_superuser(self): raised = False try: com = publisher_publish.Command() com.handle_noargs() except CommandError: raised = True self.assertTrue(raised)
def test_command_line_should_raise_when_moderator_false(self): with SettingsOverride(CMS_MODERATOR=False): raised = False try: com = publisher_publish.Command() com.handle_noargs() except CommandError: raised = True self.assertTrue(raised)
def test_command_line_publishes_one_page(self): ''' Publisher always creates two Page objects for every CMS page, one is_draft and one is_public. The public version of the page can be either published or not. This bit of code uses sometimes manager methods and sometimes manual filters on purpose (this helps test the managers) ''' # we need to create a superuser (the db is empty) User.objects.create_superuser('djangocms', '*****@*****.**', '123456') # Now, let's create a page. That actually creates 2 Page objects create_page("The page!", "nav_playground.html", "en", published=True, in_navigation=True) draft = Page.objects.drafts()[0] draft.reverse_id = 'a_test' # we have to change *something* draft.save() pages_from_output = 0 published_from_output = 0 with StdoutOverride() as buffer: # Now we don't expect it to raise, but we need to redirect IO com = publisher_publish.Command() com.handle_noargs() lines = buffer.getvalue().split( '\n') #NB: readlines() doesn't work for line in lines: if 'Total' in line: pages_from_output = int(line.split(':')[1]) elif 'Published' in line: published_from_output = int(line.split(':')[1]) self.assertEqual(pages_from_output, 1) self.assertEqual(published_from_output, 1) # Sanity check the database (we should have one draft and one public) not_drafts = len(Page.objects.filter(publisher_is_draft=False)) drafts = len(Page.objects.filter(publisher_is_draft=True)) self.assertEquals(not_drafts, 1) self.assertEquals(drafts, 1) # Now check that the non-draft has the attribute we set to the draft. non_draft = Page.objects.public()[0] self.assertEquals(non_draft.reverse_id, 'a_test')
def test_command_line_publishes_zero_pages_on_empty_db(self): # we need to create a superuser (the db is empty) User.objects.create_superuser('djangocms', '*****@*****.**', '123456') pages_from_output = 0 published_from_output = 0 with StdoutOverride() as buffer: # Now we don't expect it to raise, but we need to redirect IO com = publisher_publish.Command() com.handle_noargs() lines = buffer.getvalue().split('\n') #NB: readlines() doesn't work for line in lines: if 'Total' in line: pages_from_output = int(line.split(':')[1]) elif 'Published' in line: published_from_output = int(line.split(':')[1]) self.assertEqual(pages_from_output,0) self.assertEqual(published_from_output,0)
def test_command_line_should_raise_without_superuser(self): with self.assertRaises(CommandError): com = publisher_publish.Command() com.handle_noargs()