Пример #1
0
    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)
Пример #2
0
    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_publish_multiple_languages_check_count(self):
        """
        Publishing one page with multiple languages still counts
        as one page. This test case checks whether it works
        as expected.
        """
        # we need to create a superuser (the db is empty)
        get_user_model().objects.create_superuser('djangocms',
                                                  '*****@*****.**', '123456')

        # Now, let's create a page with 2 languages.
        page = create_page("en title",
                           "nav_playground.html",
                           "en",
                           published=True)
        create_title("de", "de title", page)
        page.publish("de")

        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
            call_command('cms', 'publisher-publish')
            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)
    def test_command_line_publishes_selected_language(self):
        # we need to create a superuser (the db is empty)
        get_user_model().objects.create_superuser('djangocms',
                                                  '*****@*****.**', '123456')

        page = create_page("en title", "nav_playground.html", "en")
        title = create_title('de', 'de title', page)
        title.published = True
        title.save()
        title = create_title('fr', 'fr title', page)
        title.published = True
        title.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
            call_command('cms', 'publisher-publish', language='de')
            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)

        self.assertEqual(Page.objects.public().count(), 1)
        public = Page.objects.public()[0]
        languages = sorted(public.title_set.values_list('language', flat=True))
        self.assertEqual(languages, ['de'])
Пример #5
0
    def test_command_line_publish_one_site(self):
        get_user_model().objects.create_superuser('djangocms', '*****@*****.**', '123456')

        siteA = Site.objects.create(domain='a.example.com', name='a.example.com')
        siteB = Site.objects.create(domain='b.example.com', name='b.example.com')

        #example.com
        create_page(u"example.com homepage", "nav_playground.html", "en", published=True)
        #a.example.com
        create_page(u"a.example.com homepage", "nav_playground.html", "de", site=siteA, published=True)
        #b.example.com
        create_page(u"b.example.com homepage", "nav_playground.html", "de", site=siteB, published=True)
        create_page(u"b.example.com about", "nav_playground.html", "nl", site=siteB, published=True)

        with StdoutOverride() as buffer:
            # Now we don't expect it to raise, but we need to redirect IO
            call_command('cms', 'publisher-publish', site=siteB.id)
            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, 2)
        self.assertEqual(published_from_output, 2)
Пример #6
0
 def test_collectstatic_with_cached_static_files_storage(self):
     # CachedStaticFilesStorage requires that the CSS files
     # don't contain any broken links.
     with TemporaryDirectory() as tmpdir:
         with SettingsOverride(STATIC_ROOT=tmpdir,
             STATICFILES_STORAGE='django.contrib.staticfiles.storage.CachedStaticFilesStorage'):
             with StdoutOverride() as output:
                 management.call_command('collectstatic', interactive=False)
Пример #7
0
    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')
Пример #8
0
    def test_command_line_publishes_zero_pages_on_empty_db(self):
        # we need to create a superuser (the db is empty)
        get_user_model().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
            call_command('cms', 'publisher-publish')
            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)
Пример #9
0
    def test_command_line_publish_multiple_languages(self):
        # we need to create a superuser (the db is empty)
        get_user_model().objects.create_superuser('djangocms', '*****@*****.**', '123456')

        # Create a draft page with two published titles
        page = create_page(u"The page!", "nav_playground.html", "en", published=False)
        title = create_title('de', 'ja', page)
        title.published = True
        title.save()
        title = create_title('fr', 'non', page)
        title.published = True
        title.save()

        with StdoutOverride():
            # Now we don't expect it to raise, but we need to redirect IO
            call_command('cms', 'publisher-publish')

        public = Page.objects.public()[0]
        languages = sorted(public.title_set.values_list('language', flat=True))
        self.assertEqual(languages, ['de', 'fr'])