Example #1
0
    def test_static_links(self):
        """Test that StaticGenerator uses files in static_links
        """
        settings = get_settings(
            STATIC_EXCLUDES=['subdir'],
            PATH=self.content_path,
            STATIC_PATHS=[],)
        context = get_context(settings)
        context['static_links'] |= {'short_page.md', 'subdir_fake_image.jpg'}

        StaticGenerator(
            context=context, settings=settings,
            path=settings['PATH'], output_path=self.temp_output,
            theme=settings['THEME']).generate_context()

        staticfiles_names = [
            os.path.basename(c.source_path) for c in context['staticfiles']]

        static_content_names = [
            os.path.basename(c) for c in context['static_content']]

        self.assertIn(
            'short_page.md', staticfiles_names,
            "StaticGenerator skipped a file that it should have included")
        self.assertIn(
            'short_page.md', static_content_names,
            "StaticGenerator skipped a file that it should have included")
        self.assertIn(
            'subdir_fake_image.jpg', staticfiles_names,
            "StaticGenerator skipped a file that it should have included")
        self.assertIn(
            'subdir_fake_image.jpg', static_content_names,
            "StaticGenerator skipped a file that it should have included")
 def test_do_not_use_folder_as_category(self):
     settings = get_settings()
     settings['DEFAULT_CATEGORY'] = 'Default'
     settings['DEFAULT_DATE'] = (1970, 1, 1)
     settings['USE_FOLDER_AS_CATEGORY'] = False
     settings['CACHE_PATH'] = self.temp_cache
     settings['READERS'] = {'asc': None}
     context = get_context(settings)
     generator = ArticlesGenerator(
         context=context, settings=settings,
         path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
     generator.generate_context()
     # test for name
     # categories are grouped by slug; if two categories have the same slug
     # but different names they will be grouped together, the first one in
     # terms of process order will define the name for that category
     categories = [cat.name for cat, _ in generator.categories]
     categories_alternatives = (
         sorted(['Default', 'Yeah', 'test', '指導書']),
         sorted(['Default', 'yeah', 'test', '指導書']),
     )
     self.assertIn(sorted(categories), categories_alternatives)
     # test for slug
     categories = [cat.slug for cat, _ in generator.categories]
     categories_expected = ['default', 'yeah', 'test', 'zhi-dao-shu']
     self.assertEqual(sorted(categories), sorted(categories_expected))
    def get_generator(self):
        category = Category("misc", self.settings)
        podcast_articles = [
            get_article(
                "podcast title",
                "podcast cocntent",
                podcast="http://example.com/audio/test.mp3",
                category=category,
                date=datetime.datetime.now(),
                length="120",
                duration="120",
            ),
            get_article(
                "podcast title",
                "podcast cocntent",
                podcast="http://example.com/audio/test.mp3",
                category=category,
                date=datetime.datetime.now(),
                length="120",
                duration="120",
            ),
        ]

        context = get_context(**self.settings)
        context["articles"] = podcast_articles

        generator = PodcastFeedGenerator(
            context=context,
            settings=self.settings,
            path=self.temp_content,
            theme="",
            output_path=self.temp_output,
        )
        generator.generate_context()
        return generator
    def test_static_links(self):
        """Test that StaticGenerator uses files in static_links
        """
        settings = get_settings(
            STATIC_EXCLUDES=['subdir'],
            PATH=self.content_path,
            STATIC_PATHS=[],)
        context = get_context(settings)
        context['static_links'] |= {'short_page.md', 'subdir_fake_image.jpg'}

        StaticGenerator(
            context=context, settings=settings,
            path=settings['PATH'], output_path=self.temp_output,
            theme=settings['THEME']).generate_context()

        staticfiles_names = [
            os.path.basename(c.source_path) for c in context['staticfiles']]

        static_content_names = [
            os.path.basename(c) for c in context['static_content']]

        self.assertIn(
            'short_page.md', staticfiles_names,
            "StaticGenerator skipped a file that it should have included")
        self.assertIn(
            'short_page.md', static_content_names,
            "StaticGenerator skipped a file that it should have included")
        self.assertIn(
            'subdir_fake_image.jpg', staticfiles_names,
            "StaticGenerator skipped a file that it should have included")
        self.assertIn(
            'subdir_fake_image.jpg', static_content_names,
            "StaticGenerator skipped a file that it should have included")
Example #5
0
 def test_do_not_use_folder_as_category(self):
     settings = get_settings()
     settings['DEFAULT_CATEGORY'] = 'Default'
     settings['DEFAULT_DATE'] = (1970, 1, 1)
     settings['USE_FOLDER_AS_CATEGORY'] = False
     settings['CACHE_PATH'] = self.temp_cache
     settings['READERS'] = {'asc': None}
     context = get_context(settings)
     generator = ArticlesGenerator(
         context=context, settings=settings,
         path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
     generator.generate_context()
     # test for name
     # categories are grouped by slug; if two categories have the same slug
     # but different names they will be grouped together, the first one in
     # terms of process order will define the name for that category
     categories = [cat.name for cat, _ in generator.categories]
     categories_alternatives = (
         sorted(['Default', 'Yeah', 'test', '指導書']),
         sorted(['Default', 'yeah', 'test', '指導書']),
     )
     self.assertIn(sorted(categories), categories_alternatives)
     # test for slug
     categories = [cat.slug for cat, _ in generator.categories]
     categories_expected = ['default', 'yeah', 'test', 'zhi-dao-shu']
     self.assertEqual(sorted(categories), sorted(categories_expected))
Example #6
0
    def test_article_object_caching(self):
        """Test Article objects caching at the generator level"""
        settings = self._get_cache_enabled_settings()
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        generator = ArticlesGenerator(
            context=context.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache'))

        generator = ArticlesGenerator(
            context=context.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        """
        6 files don't get cached because they were not valid
        - article_with_attributes_containing_double_quotes.html
        - article_with_comments.html
        - article_with_null_attributes.html
        - 2012-11-30_md_w_filename_meta#foo-bar.md
        - empty.md
        - empty_with_bom.md
        """
        self.assertEqual(generator.readers.read_file.call_count, 6)
Example #7
0
    def test_theme_static_paths_files(self):
        """Test that StaticGenerator properly copies also files mentioned in
           TEMPLATE_STATIC_PATHS, not just directories."""
        settings = get_settings(
            PATH=self.content_path,
            THEME_STATIC_PATHS=['static/css/fonts.css', 'static/fonts/'],)
        context = get_context(settings, staticfiles=[])

        StaticGenerator(
            context=context, settings=settings,
            path=settings['PATH'], output_path=self.temp_output,
            theme=settings['THEME']).generate_output(None)

        # Only the content of dirs and files listed in THEME_STATIC_PATHS are
        # put into the output, not everything from static/
        self.assertFalse(os.path.isdir(os.path.join(self.temp_output,
                                                    "theme/css/")))
        self.assertFalse(os.path.isdir(os.path.join(self.temp_output,
                                                    "theme/fonts/")))

        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.eot")))
        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.svg")))
        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.ttf")))
        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.woff")))
        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.woff2")))
        self.assertTrue(os.path.isfile(os.path.join(self.temp_output,
                                                    "theme/font.css")))
        self.assertTrue(os.path.isfile(os.path.join(self.temp_output,
                                                    "theme/fonts.css")))
    def test_theme_static_paths_files(self):
        """Test that StaticGenerator properly copies also files mentioned in
           TEMPLATE_STATIC_PATHS, not just directories."""
        settings = get_settings(
            PATH=self.content_path,
            THEME_STATIC_PATHS=['static/css/fonts.css', 'static/fonts/'],)
        context = get_context(settings, staticfiles=[])

        StaticGenerator(
            context=context, settings=settings,
            path=settings['PATH'], output_path=self.temp_output,
            theme=settings['THEME']).generate_output(None)

        # Only the content of dirs and files listed in THEME_STATIC_PATHS are
        # put into the output, not everything from static/
        self.assertFalse(os.path.isdir(os.path.join(self.temp_output,
                                                    "theme/css/")))
        self.assertFalse(os.path.isdir(os.path.join(self.temp_output,
                                                    "theme/fonts/")))

        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.eot")))
        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.svg")))
        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.ttf")))
        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.woff")))
        self.assertTrue(os.path.isfile(os.path.join(
            self.temp_output, "theme/Yanone_Kaffeesatz_400.woff2")))
        self.assertTrue(os.path.isfile(os.path.join(self.temp_output,
                                                    "theme/font.css")))
        self.assertTrue(os.path.isfile(os.path.join(self.temp_output,
                                                    "theme/fonts.css")))
Example #9
0
    def test_page_ignore_cache(self):
        """Test that all the pages are read again when not loading cache

        used in --ignore_cache or autoreload mode"""
        settings = self._get_cache_enabled_settings()
        settings['PAGE_PATHS'] = ['TestPages']
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        generator = PagesGenerator(
            context=context.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache_open'))
        orig_call_count = generator.readers.read_file.call_count

        settings['LOAD_CONTENT_CACHE'] = False
        generator = PagesGenerator(
            context=context.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        self.assertEqual(
            generator.readers.read_file.call_count,
            orig_call_count)
Example #10
0
    def test_page_ignore_cache(self):
        """Test that all the pages are read again when not loading cache

        used in --ignore_cache or autoreload mode"""
        settings = self._get_cache_enabled_settings()
        settings['PAGE_PATHS'] = ['TestPages']
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        generator = PagesGenerator(context=context.copy(),
                                   settings=settings,
                                   path=CUR_DIR,
                                   theme=settings['THEME'],
                                   output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache_open'))
        orig_call_count = generator.readers.read_file.call_count

        settings['LOAD_CONTENT_CACHE'] = False
        generator = PagesGenerator(context=context.copy(),
                                   settings=settings,
                                   path=CUR_DIR,
                                   theme=settings['THEME'],
                                   output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        self.assertEqual(generator.readers.read_file.call_count,
                         orig_call_count)
    def test_standard_metadata_in_default_metadata(self):
        settings = get_settings()
        settings['CACHE_CONTENT'] = False
        settings['DEFAULT_CATEGORY'] = 'Default'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['DEFAULT_METADATA'] = (('author', 'Blogger'),
                                        # category will be ignored in favor of
                                        # DEFAULT_CATEGORY
                                        ('category', 'Random'),
                                        ('tags', 'general, untagged'))
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()

        authors = sorted([author.name for author, _ in generator.authors])
        authors_expected = sorted(['Alexis Métaireau', 'Blogger',
                                   'Author, First', 'Author, Second',
                                   'First Author', 'Second Author'])
        self.assertEqual(authors, authors_expected)

        categories = sorted([category.name
                             for category, _ in generator.categories])
        categories_expected = [
            sorted(['Default', 'TestCategory', 'yeah', 'test', '指導書']),
            sorted(['Default', 'TestCategory', 'Yeah', 'test', '指導書'])]
        self.assertIn(categories, categories_expected)

        tags = sorted([tag.name for tag in generator.tags])
        tags_expected = sorted(['bar', 'foo', 'foobar', 'general', 'untagged',
                                'パイソン', 'マック'])
        self.assertEqual(tags, tags_expected)
Example #12
0
    def test_page_reader_content_caching(self):
        """Test raw page content caching at the reader level"""
        settings = self._get_cache_enabled_settings()
        settings['PAGE_PATHS'] = ['TestPages']
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        generator = PagesGenerator(context=context.copy(),
                                   settings=settings,
                                   path=CUR_DIR,
                                   theme=settings['THEME'],
                                   output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator.readers, '_cache'))

        generator = PagesGenerator(context=context.copy(),
                                   settings=settings,
                                   path=CUR_DIR,
                                   theme=settings['THEME'],
                                   output_path=None)
        readers = generator.readers.readers
        for reader in readers.values():
            reader.read = MagicMock()
        generator.generate_context()
        for reader in readers.values():
            self.assertEqual(reader.read.call_count, 0)
Example #13
0
    def test_page_object_caching(self):
        """Test Page objects caching at the generator level"""
        settings = self._get_cache_enabled_settings()
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['PAGE_PATHS'] = ['TestPages']
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        generator = PagesGenerator(context=context.copy(),
                                   settings=settings,
                                   path=CUR_DIR,
                                   theme=settings['THEME'],
                                   output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache'))

        generator = PagesGenerator(context=context.copy(),
                                   settings=settings,
                                   path=CUR_DIR,
                                   theme=settings['THEME'],
                                   output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        """
        1 File doesn't get cached because it was not valid
        - bad_page.rst
        """
        self.assertEqual(generator.readers.read_file.call_count, 1)
Example #14
0
    def test_article_object_caching(self):
        """Test Article objects caching at the generator level"""
        settings = self._get_cache_enabled_settings()
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        generator = ArticlesGenerator(context=context.copy(),
                                      settings=settings,
                                      path=CONTENT_DIR,
                                      theme=settings['THEME'],
                                      output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache'))

        generator = ArticlesGenerator(context=context.copy(),
                                      settings=settings,
                                      path=CONTENT_DIR,
                                      theme=settings['THEME'],
                                      output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        """
        6 files don't get cached because they were not valid
        - article_with_attributes_containing_double_quotes.html
        - article_with_comments.html
        - article_with_null_attributes.html
        - 2012-11-30_md_w_filename_meta#foo-bar.md
        - empty.md
        - empty_with_bom.md
        """
        self.assertEqual(generator.readers.read_file.call_count, 6)
Example #15
0
    def _create_generator(tmp_path):
        series.register()

        settings = get_settings()
        settings["CACHE_CONTENT"] = False
        settings["PLUGINS"] = [series]

        context = get_context(settings)

        base_path = os.path.dirname(os.path.abspath(__file__))
        test_data_path = os.path.join(base_path, data_path)

        generator = ArticlesGenerator(
            context=context,
            settings=settings,
            path=test_data_path,
            theme=settings["THEME"],
            output_path=tmp_path,
        )

        generator.generate_context()

        items = generator.articles

        if sort_key:
            items = sorted(items, key=sort_key)

        return generator, items
Example #16
0
    def test_standard_metadata_in_default_metadata(self):
        settings = get_settings()
        settings['CACHE_CONTENT'] = False
        settings['DEFAULT_CATEGORY'] = 'Default'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['DEFAULT_METADATA'] = (('author', 'Blogger'),
                                        # category will be ignored in favor of
                                        # DEFAULT_CATEGORY
                                        ('category', 'Random'),
                                        ('tags', 'general, untagged'))
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()

        authors = sorted([author.name for author, _ in generator.authors])
        authors_expected = sorted(['Alexis Métaireau', 'Blogger',
                                   'Author, First', 'Author, Second',
                                   'First Author', 'Second Author'])
        self.assertEqual(authors, authors_expected)

        categories = sorted([category.name
                             for category, _ in generator.categories])
        categories_expected = [
            sorted(['Default', 'TestCategory', 'yeah', 'test', '指導書']),
            sorted(['Default', 'TestCategory', 'Yeah', 'test', '指導書'])]
        self.assertIn(categories, categories_expected)

        tags = sorted([tag.name for tag in generator.tags])
        tags_expected = sorted(['bar', 'foo', 'foobar', 'general', 'untagged',
                                'パイソン', 'マック'])
        self.assertEqual(tags, tags_expected)
Example #17
0
 def test_nonexistent_template(self):
     """Attempt to load a non-existent template"""
     settings = get_settings()
     context = get_context(settings)
     generator = ArticlesGenerator(
         context=context, settings=settings,
         path=None, theme=settings['THEME'], output_path=None)
     self.assertRaises(Exception, generator.get_template, "not_a_template")
 def test_nonexistent_template(self):
     """Attempt to load a non-existent template"""
     settings = get_settings()
     context = get_context(settings)
     generator = ArticlesGenerator(
         context=context, settings=settings,
         path=None, theme=settings['THEME'], output_path=None)
     self.assertRaises(Exception, generator.get_template, "not_a_template")
Example #19
0
    def test_generator_caching(self):
        """Test that cached and uncached content is same in generator level"""
        settings = self._get_cache_enabled_settings()
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['PAGE_PATHS'] = ['TestPages']
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        def sorted_titles(items):
            return sorted(item.title for item in items)

        # Articles
        generator = ArticlesGenerator(context=context.copy(),
                                      settings=settings,
                                      path=CONTENT_DIR,
                                      theme=settings['THEME'],
                                      output_path=None)
        generator.generate_context()
        uncached_articles = sorted_titles(generator.articles)
        uncached_drafts = sorted_titles(generator.drafts)

        generator = ArticlesGenerator(context=context.copy(),
                                      settings=settings,
                                      path=CONTENT_DIR,
                                      theme=settings['THEME'],
                                      output_path=None)
        generator.generate_context()
        cached_articles = sorted_titles(generator.articles)
        cached_drafts = sorted_titles(generator.drafts)

        self.assertEqual(uncached_articles, cached_articles)
        self.assertEqual(uncached_drafts, cached_drafts)

        # Pages
        generator = PagesGenerator(context=context.copy(),
                                   settings=settings,
                                   path=CUR_DIR,
                                   theme=settings['THEME'],
                                   output_path=None)
        generator.generate_context()
        uncached_pages = sorted_titles(generator.pages)
        uncached_hidden_pages = sorted_titles(generator.hidden_pages)
        uncached_draft_pages = sorted_titles(generator.draft_pages)

        generator = PagesGenerator(context=context.copy(),
                                   settings=settings,
                                   path=CUR_DIR,
                                   theme=settings['THEME'],
                                   output_path=None)
        generator.generate_context()
        cached_pages = sorted_titles(generator.pages)
        cached_hidden_pages = sorted_titles(generator.hidden_pages)
        cached_draft_pages = sorted_titles(generator.draft_pages)

        self.assertEqual(uncached_pages, cached_pages)
        self.assertEqual(uncached_hidden_pages, cached_hidden_pages)
        self.assertEqual(uncached_draft_pages, cached_draft_pages)
Example #20
0
    def test_static_exclude_sources(self):
        """Test that StaticGenerator respects STATIC_EXCLUDE_SOURCES.
        """

        settings = get_settings(
            STATIC_EXCLUDE_SOURCES=True,
            PATH=self.content_path,
            PAGE_PATHS=[''],
            STATIC_PATHS=[''],
            CACHE_CONTENT=False,)
        context = get_context(settings)

        for generator_class in (PagesGenerator, StaticGenerator):
            generator_class(
                context=context, settings=settings,
                path=settings['PATH'], output_path=self.temp_output,
                theme=settings['THEME']).generate_context()

        staticnames = [os.path.basename(c.source_path)
                       for c in context['staticfiles']]

        self.assertFalse(
            any(name.endswith(".md") for name in staticnames),
            "STATIC_EXCLUDE_SOURCES=True failed to exclude a markdown file")

        settings.update(STATIC_EXCLUDE_SOURCES=False)
        context = get_context(settings)

        for generator_class in (PagesGenerator, StaticGenerator):
            generator_class(
                context=context, settings=settings,
                path=settings['PATH'], output_path=self.temp_output,
                theme=settings['THEME']).generate_context()

        staticnames = [os.path.basename(c.source_path)
                       for c in context['staticfiles']]

        self.assertTrue(
            any(name.endswith(".md") for name in staticnames),
            "STATIC_EXCLUDE_SOURCES=False failed to include a markdown file")
    def test_static_exclude_sources(self):
        """Test that StaticGenerator respects STATIC_EXCLUDE_SOURCES.
        """

        settings = get_settings(
            STATIC_EXCLUDE_SOURCES=True,
            PATH=self.content_path,
            PAGE_PATHS=[''],
            STATIC_PATHS=[''],
            CACHE_CONTENT=False,)
        context = get_context(settings)

        for generator_class in (PagesGenerator, StaticGenerator):
            generator_class(
                context=context, settings=settings,
                path=settings['PATH'], output_path=self.temp_output,
                theme=settings['THEME']).generate_context()

        staticnames = [os.path.basename(c.source_path)
                       for c in context['staticfiles']]

        self.assertFalse(
            any(name.endswith(".md") for name in staticnames),
            "STATIC_EXCLUDE_SOURCES=True failed to exclude a markdown file")

        settings.update(STATIC_EXCLUDE_SOURCES=False)
        context = get_context(settings)

        for generator_class in (PagesGenerator, StaticGenerator):
            generator_class(
                context=context, settings=settings,
                path=settings['PATH'], output_path=self.temp_output,
                theme=settings['THEME']).generate_context()

        staticnames = [os.path.basename(c.source_path)
                       for c in context['staticfiles']]

        self.assertTrue(
            any(name.endswith(".md") for name in staticnames),
            "STATIC_EXCLUDE_SOURCES=False failed to include a markdown file")
Example #22
0
    def setUpClass(cls):
        settings = get_settings()
        settings['DEFAULT_CATEGORY'] = 'Default'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['READERS'] = {'asc': None}
        settings['CACHE_CONTENT'] = False
        context = get_context(settings)

        cls.generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        cls.generator.generate_context()
        cls.articles = cls.distill_articles(cls.generator.articles)
    def setUpClass(cls):
        settings = get_settings()
        settings['DEFAULT_CATEGORY'] = 'Default'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['READERS'] = {'asc': None}
        settings['CACHE_CONTENT'] = False
        context = get_context(settings)

        cls.generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        cls.generator.generate_context()
        cls.articles = cls.distill_articles(cls.generator.articles)
Example #24
0
    def setUp(self):
        super().setUp()
        self.settings = get_settings(
            STATIC_SAVE_AS='{path}',
            STATIC_URL='{path}',
            PAGE_SAVE_AS=os.path.join('outpages', '{slug}.html'),
            PAGE_URL='outpages/{slug}.html')
        self.context = get_context(self.settings)

        self.static = Static(content=None, metadata={}, settings=self.settings,
                             source_path=posix_join('dir', 'foo.jpg'),
                             context=self.context)

        self.context['static_content'][self.static.source_path] = self.static
Example #25
0
    def test_generator_caching(self):
        """Test that cached and uncached content is same in generator level"""
        settings = self._get_cache_enabled_settings()
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['PAGE_PATHS'] = ['TestPages']
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        def sorted_titles(items):
            return sorted(item.title for item in items)

        # Articles
        generator = ArticlesGenerator(
            context=context.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        uncached_articles = sorted_titles(generator.articles)
        uncached_drafts = sorted_titles(generator.drafts)

        generator = ArticlesGenerator(
            context=context.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        cached_articles = sorted_titles(generator.articles)
        cached_drafts = sorted_titles(generator.drafts)

        self.assertEqual(uncached_articles, cached_articles)
        self.assertEqual(uncached_drafts, cached_drafts)

        # Pages
        generator = PagesGenerator(
            context=context.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        uncached_pages = sorted_titles(generator.pages)
        uncached_hidden_pages = sorted_titles(generator.hidden_pages)
        uncached_draft_pages = sorted_titles(generator.draft_pages)

        generator = PagesGenerator(
            context=context.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        cached_pages = sorted_titles(generator.pages)
        cached_hidden_pages = sorted_titles(generator.hidden_pages)
        cached_draft_pages = sorted_titles(generator.draft_pages)

        self.assertEqual(uncached_pages, cached_pages)
        self.assertEqual(uncached_hidden_pages, cached_hidden_pages)
        self.assertEqual(uncached_draft_pages, cached_draft_pages)
Example #26
0
    def setUp(self):
        super(TestStatic, self).setUp()
        self.settings = get_settings(
            STATIC_SAVE_AS='{path}',
            STATIC_URL='{path}',
            PAGE_SAVE_AS=os.path.join('outpages', '{slug}.html'),
            PAGE_URL='outpages/{slug}.html')
        self.context = get_context(self.settings)

        self.static = Static(content=None, metadata={}, settings=self.settings,
                             source_path=posix_join('dir', 'foo.jpg'),
                             context=self.context)

        self.context['static_content'][self.static.source_path] = self.static
    def setUpClass(cls):
        more_categories.register()
        settings = get_settings()
        settings['DEFAULT_CATEGORY'] = 'default'
        settings['CACHE_CONTENT'] = False
        settings['PLUGINS'] = more_categories
        context = get_context(settings)

        base_path = os.path.dirname(os.path.abspath(__file__))
        test_data_path = os.path.join(base_path, 'test_data')
        cls.generator = ArticlesGenerator(
            context=context, settings=settings,
            path=test_data_path, theme=settings['THEME'], output_path=None)
        cls.generator.generate_context()
Example #28
0
    def test_generate_context(self):
        settings = get_settings()
        settings['CACHE_PATH'] = self.temp_cache
        settings['PAGE_PATHS'] = ['TestPages']  # relative to CUR_DIR
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_pages)
        draft_pages = self.distill_pages(generator.draft_pages)

        pages_expected = [
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom'],
            ['Page with a bunch of links', 'published', 'page'],
            ['Page with static links', 'published', 'page'],
            ['A Page (Test) for sorting', 'published', 'page'],
        ]
        hidden_pages_expected = [
            ['This is a test hidden page', 'hidden', 'page'],
            ['This is a markdown test hidden page', 'hidden', 'page'],
            ['This is a test hidden page with a custom template', 'hidden',
             'custom'],
        ]
        draft_pages_expected = [
            ['This is a test draft page', 'draft', 'page'],
            ['This is a markdown test draft page', 'draft', 'page'],
            ['This is a test draft page with a custom template', 'draft',
             'custom'],
        ]

        self.assertEqual(sorted(pages_expected), sorted(pages))
        self.assertEqual(
            sorted(pages_expected),
            sorted(self.distill_pages(generator.context['pages'])))
        self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
        self.assertEqual(sorted(draft_pages_expected), sorted(draft_pages))
        self.assertEqual(
            sorted(hidden_pages_expected),
            sorted(self.distill_pages(generator.context['hidden_pages'])))
        self.assertEqual(
            sorted(draft_pages_expected),
            sorted(self.distill_pages(generator.context['draft_pages'])))
    def test_generate_context(self):
        settings = get_settings()
        settings['CACHE_PATH'] = self.temp_cache
        settings['PAGE_PATHS'] = ['TestPages']  # relative to CUR_DIR
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_pages)
        draft_pages = self.distill_pages(generator.draft_pages)

        pages_expected = [
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom'],
            ['Page with a bunch of links', 'published', 'page'],
            ['Page with static links', 'published', 'page'],
            ['A Page (Test) for sorting', 'published', 'page'],
        ]
        hidden_pages_expected = [
            ['This is a test hidden page', 'hidden', 'page'],
            ['This is a markdown test hidden page', 'hidden', 'page'],
            ['This is a test hidden page with a custom template', 'hidden',
             'custom'],
        ]
        draft_pages_expected = [
            ['This is a test draft page', 'draft', 'page'],
            ['This is a markdown test draft page', 'draft', 'page'],
            ['This is a test draft page with a custom template', 'draft',
             'custom'],
        ]

        self.assertEqual(sorted(pages_expected), sorted(pages))
        self.assertEqual(
            sorted(pages_expected),
            sorted(self.distill_pages(generator.context['pages'])))
        self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
        self.assertEqual(sorted(draft_pages_expected), sorted(draft_pages))
        self.assertEqual(
            sorted(hidden_pages_expected),
            sorted(self.distill_pages(generator.context['hidden_pages'])))
        self.assertEqual(
            sorted(draft_pages_expected),
            sorted(self.distill_pages(generator.context['draft_pages'])))
    def test_direct_templates_save_as_url_default(self):

        settings = get_settings()
        settings['CACHE_PATH'] = self.temp_cache
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=None, theme=settings['THEME'], output_path=None)
        write = MagicMock()
        generator.generate_direct_templates(write)
        write.assert_called_with("archives.html",
                                 generator.get_template("archives"), context,
                                 articles=generator.articles,
                                 dates=generator.dates, blog=True,
                                 template_name='archives',
                                 page_name='archives', url="archives.html")
Example #31
0
    def test_direct_templates_save_as_url_default(self):

        settings = get_settings()
        settings['CACHE_PATH'] = self.temp_cache
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=None, theme=settings['THEME'], output_path=None)
        write = MagicMock()
        generator.generate_direct_templates(write)
        write.assert_called_with("archives.html",
                                 generator.get_template("archives"), context,
                                 articles=generator.articles,
                                 dates=generator.dates, blog=True,
                                 template_name='archives',
                                 page_name='archives', url="archives.html")
Example #32
0
    def test_theme_static_paths_dirs(self):
        """Test that StaticGenerator properly copies also files mentioned in
           TEMPLATE_STATIC_PATHS, not just directories."""
        settings = get_settings(PATH=self.content_path)
        context = get_context(settings, staticfiles=[])

        StaticGenerator(
            context=context, settings=settings,
            path=settings['PATH'], output_path=self.temp_output,
            theme=settings['THEME']).generate_output(None)

        # The content of dirs listed in THEME_STATIC_PATHS (defaulting to
        # "static") is put into the output
        self.assertTrue(os.path.isdir(os.path.join(self.temp_output,
                                                   "theme/css/")))
        self.assertTrue(os.path.isdir(os.path.join(self.temp_output,
                                                   "theme/fonts/")))
    def test_theme_static_paths_dirs(self):
        """Test that StaticGenerator properly copies also files mentioned in
           TEMPLATE_STATIC_PATHS, not just directories."""
        settings = get_settings(PATH=self.content_path)
        context = get_context(settings, staticfiles=[])

        StaticGenerator(
            context=context, settings=settings,
            path=settings['PATH'], output_path=self.temp_output,
            theme=settings['THEME']).generate_output(None)

        # The content of dirs listed in THEME_STATIC_PATHS (defaulting to
        # "static") is put into the output
        self.assertTrue(os.path.isdir(os.path.join(self.temp_output,
                                                   "theme/css/")))
        self.assertTrue(os.path.isdir(os.path.join(self.temp_output,
                                                   "theme/fonts/")))
 def setUp(self):
     self.content_path = os.path.join(CUR_DIR, 'mixed_content')
     self.temp_content = mkdtemp(prefix='testcontent.')
     self.temp_output = mkdtemp(prefix='testoutput.')
     self.settings = get_settings()
     self.settings['PATH'] = self.temp_content
     self.settings['STATIC_PATHS'] = ["static"]
     self.settings['OUTPUT_PATH'] = self.temp_output
     os.mkdir(os.path.join(self.temp_content, "static"))
     self.startfile = os.path.join(self.temp_content,
                                   "static", "staticfile")
     self.endfile = os.path.join(self.temp_output, "static", "staticfile")
     self.generator = StaticGenerator(
         context=get_context(),
         settings=self.settings,
         path=self.temp_content,
         theme="",
         output_path=self.temp_output,
         )
Example #35
0
 def setUp(self):
     self.content_path = os.path.join(CUR_DIR, 'mixed_content')
     self.temp_content = mkdtemp(prefix='testcontent.')
     self.temp_output = mkdtemp(prefix='testoutput.')
     self.settings = get_settings()
     self.settings['PATH'] = self.temp_content
     self.settings['STATIC_PATHS'] = ["static"]
     self.settings['OUTPUT_PATH'] = self.temp_output
     os.mkdir(os.path.join(self.temp_content, "static"))
     self.startfile = os.path.join(self.temp_content,
                                   "static", "staticfile")
     self.endfile = os.path.join(self.temp_output, "static", "staticfile")
     self.generator = StaticGenerator(
         context=get_context(),
         settings=self.settings,
         path=self.temp_content,
         theme="",
         output_path=self.temp_output,
         )
Example #36
0
    def test_static_and_attach_links_on_generated_pages(self):
        """
        Test to ensure links of the form {static}filename and {attach}filename
        are included in context['static_links']
        """
        settings = get_settings()
        settings['PAGE_PATHS'] = ['TestPages/page_with_static_links.md']
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()

        self.assertIn('pelican/tests/TestPages/image0.jpg',
                      context['static_links'])
        self.assertIn('pelican/tests/TestPages/image1.jpg',
                      context['static_links'])
    def test_tag_and_category_links_on_generated_pages(self):
        """
        Test to ensure links of the form {tag}tagname and {category}catname
        are generated correctly on pages
        """
        settings = get_settings()
        settings['PAGE_PATHS'] = ['TestPages']    # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages_by_title = {p.title: p for p in generator.pages}

        test_content = pages_by_title['Page with a bunch of links'].content
        self.assertIn('<a href="/category/yeah.html">', test_content)
        self.assertIn('<a href="/tag/matsuku.html">', test_content)
    def test_static_and_attach_links_on_generated_pages(self):
        """
        Test to ensure links of the form {static}filename and {attach}filename
        are included in context['static_links']
        """
        settings = get_settings()
        settings['PAGE_PATHS'] = ['TestPages/page_with_static_links.md']
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()

        self.assertIn('pelican/tests/TestPages/image0.jpg',
                      context['static_links'])
        self.assertIn('pelican/tests/TestPages/image1.jpg',
                      context['static_links'])
Example #39
0
    def test_tag_and_category_links_on_generated_pages(self):
        """
        Test to ensure links of the form {tag}tagname and {category}catname
        are generated correctly on pages
        """
        settings = get_settings()
        settings['PAGE_PATHS'] = ['TestPages']    # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages_by_title = {p.title: p for p in generator.pages}

        test_content = pages_by_title['Page with a bunch of links'].content
        self.assertIn('<a href="/category/yeah.html">', test_content)
        self.assertIn('<a href="/tag/matsuku.html">', test_content)
Example #40
0
    def setUpClass(cls):
        cls.temp_path = mkdtemp(prefix='pelicantests.')
        more_categories.register()
        settings = get_settings()
        settings['DEFAULT_CATEGORY'] = 'default'
        settings['CACHE_CONTENT'] = False
        settings['PLUGINS'] = more_categories
        context = get_context(settings)

        base_path = os.path.dirname(os.path.abspath(__file__))
        test_data_path = os.path.join(base_path, 'test_data')
        cls.generator = ArticlesGenerator(
            context=context,
            settings=settings,
            path=test_data_path,
            theme=settings['THEME'],
            output_path=cls.temp_path,
        )
        cls.generator.generate_context()
        cls.cats = {cat.name: cat for cat, _ in cls.generator.categories}
Example #41
0
    def test_article_reader_content_caching(self):
        """Test raw article content caching at the reader level"""
        settings = self._get_cache_enabled_settings()
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        generator = ArticlesGenerator(
            context=context.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator.readers, '_cache'))

        generator = ArticlesGenerator(
            context=context.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        readers = generator.readers.readers
        for reader in readers.values():
            reader.read = MagicMock()
        generator.generate_context()
        for reader in readers.values():
            self.assertEqual(reader.read.call_count, 0)
    def test_generate_context(self):
        settings = self.settings.copy()
        settings["PODCAST_FEED_PATH"] = PODCAST_FEED_PATH

        article = get_article("title", "cocntent")
        podcast_article = get_article(
            "podcast title", "podcast cocntent", podcast="aaa.mp3"
        )

        context = get_context(settings)
        context["articles"] = [article, podcast_article]

        generator = PodcastFeedGenerator(
            settings=settings,
            context=context,
            path=None,
            theme=settings["THEME"],
            output_path=None,
        )

        generator.generate_context()
        self.assertEqual(1, len(generator.episodes))
Example #43
0
    def test_static_excludes(self):
        """Test that StaticGenerator respects STATIC_EXCLUDES.
        """
        settings = get_settings(
            STATIC_EXCLUDES=['subdir'],
            PATH=self.content_path,
            STATIC_PATHS=[''],)
        context = get_context(settings)

        StaticGenerator(
            context=context, settings=settings,
            path=settings['PATH'], output_path=self.temp_output,
            theme=settings['THEME']).generate_context()

        staticnames = [os.path.basename(c.source_path)
                       for c in context['staticfiles']]

        self.assertNotIn(
            'subdir_fake_image.jpg', staticnames,
            "StaticGenerator processed a file in a STATIC_EXCLUDES directory")
        self.assertIn(
            'fake_image.jpg', staticnames,
            "StaticGenerator skipped a file that it should have included")
    def test_static_excludes(self):
        """Test that StaticGenerator respects STATIC_EXCLUDES.
        """
        settings = get_settings(
            STATIC_EXCLUDES=['subdir'],
            PATH=self.content_path,
            STATIC_PATHS=[''],)
        context = get_context(settings)

        StaticGenerator(
            context=context, settings=settings,
            path=settings['PATH'], output_path=self.temp_output,
            theme=settings['THEME']).generate_context()

        staticnames = [os.path.basename(c.source_path)
                       for c in context['staticfiles']]

        self.assertNotIn(
            'subdir_fake_image.jpg', staticnames,
            "StaticGenerator processed a file in a STATIC_EXCLUDES directory")
        self.assertIn(
            'fake_image.jpg', staticnames,
            "StaticGenerator skipped a file that it should have included")
Example #45
0
    def test_page_object_caching(self):
        """Test Page objects caching at the generator level"""
        settings = self._get_cache_enabled_settings()
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['PAGE_PATHS'] = ['TestPages']
        settings['READERS'] = {'asc': None}
        context = get_context(settings)

        generator = PagesGenerator(
            context=context.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache'))

        generator = PagesGenerator(
            context=context.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        """
        1 File doesn't get cached because it was not valid
        - bad_page.rst
        """
        self.assertEqual(generator.readers.read_file.call_count, 1)
Example #46
0
    def test_generate_sorted(self):
        settings = get_settings()
        settings['PAGE_PATHS'] = ['TestPages']  # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        # default sort (filename)
        pages_expected_sorted_by_filename = [
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['A Page (Test) for sorting', 'published', 'page'],
            ['Page with a bunch of links', 'published', 'page'],
            ['Page with static links', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom'],
        ]
        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        self.assertEqual(pages_expected_sorted_by_filename, pages)

        # sort by title
        pages_expected_sorted_by_title = [
            ['A Page (Test) for sorting', 'published', 'page'],
            ['Page with a bunch of links', 'published', 'page'],
            ['Page with static links', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['This is a test page', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom'],
        ]
        settings['PAGE_ORDER_BY'] = 'title'
        context = get_context(settings)
        generator = PagesGenerator(
            context=context.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        self.assertEqual(pages_expected_sorted_by_title, pages)

        # sort by title reversed
        pages_expected_sorted_by_title = [
            ['This is a test page with a preset template', 'published',
             'custom'],
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['Page with static links', 'published', 'page'],
            ['Page with a bunch of links', 'published', 'page'],
            ['A Page (Test) for sorting', 'published', 'page'],
        ]
        settings['PAGE_ORDER_BY'] = 'reversed-title'
        context = get_context(settings)
        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        self.assertEqual(pages_expected_sorted_by_title, pages)
Example #47
0
    def test_period_in_timeperiod_archive(self):
        """
        Test that the context of a generated period_archive is passed
        'period' : a tuple of year, month, day according to the time period
        """
        old_locale = locale.setlocale(locale.LC_ALL)
        locale.setlocale(locale.LC_ALL, str('C'))
        settings = get_settings()

        settings['YEAR_ARCHIVE_SAVE_AS'] = 'posts/{date:%Y}/index.html'
        settings['YEAR_ARCHIVE_URL'] = 'posts/{date:%Y}/'
        settings['CACHE_PATH'] = self.temp_cache
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        write = MagicMock()
        generator.generate_period_archives(write)
        dates = [d for d in generator.dates if d.date.year == 1970]
        articles = [d for d in generator.articles if d.date.year == 1970]
        self.assertEqual(len(dates), 1)
        # among other things it must have at least been called with this
        context["period"] = (1970,)
        write.assert_called_with("posts/1970/index.html",
                                 generator.get_template("period_archives"),
                                 context, blog=True, articles=articles,
                                 dates=dates, template_name='period_archives',
                                 url="posts/1970/",
                                 all_articles=generator.articles)

        settings['MONTH_ARCHIVE_SAVE_AS'] = \
            'posts/{date:%Y}/{date:%b}/index.html'
        settings['MONTH_ARCHIVE_URL'] = \
            'posts/{date:%Y}/{date:%b}/'
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        write = MagicMock()
        generator.generate_period_archives(write)
        dates = [d for d in generator.dates
                 if d.date.year == 1970 and d.date.month == 1]
        articles = [d for d in generator.articles
                    if d.date.year == 1970 and d.date.month == 1]
        self.assertEqual(len(dates), 1)
        context["period"] = (1970, "January")
        # among other things it must have at least been called with this
        write.assert_called_with("posts/1970/Jan/index.html",
                                 generator.get_template("period_archives"),
                                 context, blog=True, articles=articles,
                                 dates=dates, template_name='period_archives',
                                 url="posts/1970/Jan/",
                                 all_articles=generator.articles)

        settings['DAY_ARCHIVE_SAVE_AS'] = \
            'posts/{date:%Y}/{date:%b}/{date:%d}/index.html'
        settings['DAY_ARCHIVE_URL'] = \
            'posts/{date:%Y}/{date:%b}/{date:%d}/'
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        write = MagicMock()
        generator.generate_period_archives(write)
        dates = [
            d for d in generator.dates if
            d.date.year == 1970 and
            d.date.month == 1 and
            d.date.day == 1
        ]
        articles = [
            d for d in generator.articles if
            d.date.year == 1970 and
            d.date.month == 1 and
            d.date.day == 1
        ]
        self.assertEqual(len(dates), 1)
        context["period"] = (1970, "January", 1)
        # among other things it must have at least been called with this
        write.assert_called_with("posts/1970/Jan/01/index.html",
                                 generator.get_template("period_archives"),
                                 context, blog=True, articles=articles,
                                 dates=dates, template_name='period_archives',
                                 url="posts/1970/Jan/01/",
                                 all_articles=generator.articles)
        locale.setlocale(locale.LC_ALL, old_locale)
Example #48
0
 def setUpClass(cls):
     webring.initialized(None)
     cls.generators = [
         NullGenerator(get_context(), get_settings(), "", "", "")
     ]
     cls.settings = cls.generators[0].settings
 def reset_settings(self):
     self.context = get_context(get_settings())
     self.context["SITEURL"] = "https://somedomain.net"
     self.context["SITENAME"] = "Test Sitename"
    def test_generate_sorted(self):
        settings = get_settings()
        settings['PAGE_PATHS'] = ['TestPages']  # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        # default sort (filename)
        pages_expected_sorted_by_filename = [
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['A Page (Test) for sorting', 'published', 'page'],
            ['Page with a bunch of links', 'published', 'page'],
            ['Page with static links', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom'],
        ]
        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        self.assertEqual(pages_expected_sorted_by_filename, pages)

        # sort by title
        pages_expected_sorted_by_title = [
            ['A Page (Test) for sorting', 'published', 'page'],
            ['Page with a bunch of links', 'published', 'page'],
            ['Page with static links', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['This is a test page', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom'],
        ]
        settings['PAGE_ORDER_BY'] = 'title'
        context = get_context(settings)
        generator = PagesGenerator(
            context=context.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        self.assertEqual(pages_expected_sorted_by_title, pages)

        # sort by title reversed
        pages_expected_sorted_by_title = [
            ['This is a test page with a preset template', 'published',
             'custom'],
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['Page with static links', 'published', 'page'],
            ['Page with a bunch of links', 'published', 'page'],
            ['A Page (Test) for sorting', 'published', 'page'],
        ]
        settings['PAGE_ORDER_BY'] = 'reversed-title'
        context = get_context(settings)
        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        self.assertEqual(pages_expected_sorted_by_title, pages)
    def test_article_order_by(self):
        settings = get_settings()
        settings['DEFAULT_CATEGORY'] = 'Default'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['ARTICLE_ORDER_BY'] = 'title'
        context = get_context(settings)

        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()

        expected = [
            'An Article With Code Block To Test Typogrify Ignore',
            'Article title',
            'Article with Nonconformant HTML meta tags',
            'Article with markdown and summary metadata multi',
            'Article with markdown and summary metadata single',
            'Article with markdown containing footnotes',
            'Article with template',
            'Metadata tags as list!',
            'Rst with filename metadata',
            'Test Markdown extensions',
            'Test markdown File',
            'Test md File',
            'Test mdown File',
            'Test metadata duplicates',
            'Test mkd File',
            'This is a super article !',
            'This is a super article !',
            'This is a super article !',
            'This is a super article !',
            'This is a super article !',
            'This is a super article !',
            'This is an article with category !',
            ('This is an article with multiple authors in lastname, '
             'firstname format!'),
            'This is an article with multiple authors in list format!',
            'This is an article with multiple authors!',
            'This is an article with multiple authors!',
            'This is an article without category !',
            'This is an article without category !',
            'マックOS X 10.8でパイソンとVirtualenvをインストールと設定']

        articles = [article.title for article in generator.articles]
        self.assertEqual(articles, expected)

        # reversed title
        settings = get_settings()
        settings['DEFAULT_CATEGORY'] = 'Default'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['ARTICLE_ORDER_BY'] = 'reversed-title'
        context = get_context(settings)

        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()

        articles = [article.title for article in generator.articles]
        self.assertEqual(articles, list(reversed(expected)))
Example #52
0
    def test_article_order_by(self):
        settings = get_settings()
        settings['DEFAULT_CATEGORY'] = 'Default'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['ARTICLE_ORDER_BY'] = 'title'
        context = get_context(settings)

        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()

        expected = [
            'An Article With Code Block To Test Typogrify Ignore',
            'Article title',
            'Article with Nonconformant HTML meta tags',
            'Article with markdown and summary metadata multi',
            'Article with markdown and summary metadata single',
            'Article with markdown containing footnotes',
            'Article with template',
            'Metadata tags as list!',
            'Rst with filename metadata',
            'Test Markdown extensions',
            'Test markdown File',
            'Test md File',
            'Test mdown File',
            'Test metadata duplicates',
            'Test mkd File',
            'This is a super article !',
            'This is a super article !',
            'This is a super article !',
            'This is a super article !',
            'This is a super article !',
            'This is a super article !',
            'This is an article with category !',
            ('This is an article with multiple authors in lastname, '
             'firstname format!'),
            'This is an article with multiple authors in list format!',
            'This is an article with multiple authors!',
            'This is an article with multiple authors!',
            'This is an article without category !',
            'This is an article without category !',
            'マックOS X 10.8でパイソンとVirtualenvをインストールと設定']

        articles = [article.title for article in generator.articles]
        self.assertEqual(articles, expected)

        # reversed title
        settings = get_settings()
        settings['DEFAULT_CATEGORY'] = 'Default'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['ARTICLE_ORDER_BY'] = 'reversed-title'
        context = get_context(settings)

        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()

        articles = [article.title for article in generator.articles]
        self.assertEqual(articles, list(reversed(expected)))
    def test_period_in_timeperiod_archive(self):
        """
        Test that the context of a generated period_archive is passed
        'period' : a tuple of year, month, day according to the time period
        """
        old_locale = locale.setlocale(locale.LC_ALL)
        locale.setlocale(locale.LC_ALL, str('C'))
        settings = get_settings()

        settings['YEAR_ARCHIVE_SAVE_AS'] = 'posts/{date:%Y}/index.html'
        settings['YEAR_ARCHIVE_URL'] = 'posts/{date:%Y}/'
        settings['CACHE_PATH'] = self.temp_cache
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        write = MagicMock()
        generator.generate_period_archives(write)
        dates = [d for d in generator.dates if d.date.year == 1970]
        articles = [d for d in generator.articles if d.date.year == 1970]
        self.assertEqual(len(dates), 1)
        # among other things it must have at least been called with this
        context["period"] = (1970,)
        write.assert_called_with("posts/1970/index.html",
                                 generator.get_template("period_archives"),
                                 context, blog=True, articles=articles,
                                 dates=dates, template_name='period_archives',
                                 url="posts/1970/")

        settings['MONTH_ARCHIVE_SAVE_AS'] = \
            'posts/{date:%Y}/{date:%b}/index.html'
        settings['MONTH_ARCHIVE_URL'] = \
            'posts/{date:%Y}/{date:%b}/'
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        write = MagicMock()
        generator.generate_period_archives(write)
        dates = [d for d in generator.dates
                 if d.date.year == 1970 and d.date.month == 1]
        articles = [d for d in generator.articles
                    if d.date.year == 1970 and d.date.month == 1]
        self.assertEqual(len(dates), 1)
        context["period"] = (1970, "January")
        # among other things it must have at least been called with this
        write.assert_called_with("posts/1970/Jan/index.html",
                                 generator.get_template("period_archives"),
                                 context, blog=True, articles=articles,
                                 dates=dates, template_name='period_archives',
                                 url="posts/1970/Jan/")

        settings['DAY_ARCHIVE_SAVE_AS'] = \
            'posts/{date:%Y}/{date:%b}/{date:%d}/index.html'
        settings['DAY_ARCHIVE_URL'] = \
            'posts/{date:%Y}/{date:%b}/{date:%d}/'
        context = get_context(settings)
        generator = ArticlesGenerator(
            context=context, settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        write = MagicMock()
        generator.generate_period_archives(write)
        dates = [
            d for d in generator.dates if
            d.date.year == 1970 and
            d.date.month == 1 and
            d.date.day == 1
        ]
        articles = [
            d for d in generator.articles if
            d.date.year == 1970 and
            d.date.month == 1 and
            d.date.day == 1
        ]
        self.assertEqual(len(dates), 1)
        context["period"] = (1970, "January", 1)
        # among other things it must have at least been called with this
        write.assert_called_with("posts/1970/Jan/01/index.html",
                                 generator.get_template("period_archives"),
                                 context, blog=True, articles=articles,
                                 dates=dates, template_name='period_archives',
                                 url="posts/1970/Jan/01/")
        locale.setlocale(locale.LC_ALL, old_locale)