Пример #1
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}

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

        generator = PagesGenerator(context=settings.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)
Пример #2
0
    def test_generate_context(self):
        settings = get_settings()
        settings['PAGE_DIR'] = 'TestPages'
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        generator = PagesGenerator(settings.copy(), settings, CUR_DIR,
                                   settings['THEME'], None, settings['MARKUP'])
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_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'
                          ]]
        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'
            ]
        ]

        self.assertItemsEqual(pages_expected, pages)
        self.assertItemsEqual(hidden_pages_expected, hidden_pages)
Пример #3
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}

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

        generator = PagesGenerator(context=settings.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)
Пример #4
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}

        generator = PagesGenerator(
            context=settings.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=settings.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)
Пример #5
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}

        generator = PagesGenerator(
            context=settings.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=settings.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)
Пример #6
0
    def test_generate_context(self):
        settings = get_settings(filenames={})
        settings['PAGE_DIR'] = 'TestPages'  # relative to CUR_DIR
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        generator = PagesGenerator(
            context=settings.copy(), 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)

        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']
        ]
        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']
        ]

        self.assertEqual(sorted(pages_expected), sorted(pages))
        self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
Пример #7
0
    def test_generate_context(self):
        settings = _DEFAULT_CONFIG.copy()

        settings['PAGE_DIR'] = 'TestPages'
        settings['DEFAULT_DATE'] = (1970, 01, 01)
        generator = PagesGenerator(settings.copy(), settings, CUR_DIR,
                                      _DEFAULT_CONFIG['THEME'], None,
                                      _DEFAULT_CONFIG['MARKUP'])
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_pages)

        pages_expected = [
            [u'This is a test page', 'published', 'page'],
            [u'This is a markdown test page', 'published', 'page'],
            [u'This is a test page with a preset template', 'published', 'custom']
        ]
        hidden_pages_expected = [
            [u'This is a test hidden page', 'hidden', 'page'],
            [u'This is a markdown test hidden page', 'hidden', 'page'],
            [u'This is a test hidden page with a custom template', 'hidden', 'custom']
        ]

        self.assertItemsEqual(pages_expected,pages)
        self.assertItemsEqual(hidden_pages_expected,hidden_pages)
Пример #8
0
    def test_generate_context(self):
        settings = get_settings(filenames={})
        settings["CACHE_PATH"] = self.temp_cache
        settings["PAGE_PATHS"] = ["TestPages"]  # relative to CUR_DIR
        settings["DEFAULT_DATE"] = (1970, 1, 1)

        generator = PagesGenerator(
            context=settings.copy(), 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)

        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"],
            ["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"],
        ]

        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(hidden_pages_expected), sorted(self.distill_pages(generator.context["hidden_pages"])))
Пример #9
0
    def test_generate_context(self):
        settings = get_settings(filenames={})
        settings['PAGE_DIR'] = 'TestPages'  # relative to CUR_DIR
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        generator = PagesGenerator(context=settings.copy(),
                                   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)

        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'
                          ]]
        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'
            ]
        ]

        self.assertEqual(sorted(pages_expected), sorted(pages))
        self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
Пример #10
0
    def test_reader_content_caching(self):
        """Test raw content caching at the reader level"""
        settings = get_settings(filenames={})
        settings['CACHE_PATH'] = self.temp_cache
        settings['READERS'] = {'asc': None}

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

        generator = PagesGenerator(context=settings.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():
            reader.read.assert_called_count == 0
Пример #11
0
    def test_generate_context(self):
        settings = get_settings()
        settings['PAGE_DIR'] = 'TestPages'
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        generator = PagesGenerator(settings.copy(), settings, CUR_DIR,
                                      settings['THEME'], None,
                                      settings['MARKUP'])
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_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']
        ]
        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']
        ]

        self.assertEqual(sorted(pages_expected), sorted(pages))
        self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
Пример #12
0
    def test_generate_context(self):
        settings = get_settings(filenames={})
        settings['CACHE_PATH'] = self.temp_cache
        settings['PAGE_PATHS'] = ['TestPages']  # relative to CUR_DIR
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        generator = PagesGenerator(context=settings.copy(),
                                   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'],
            ['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'])))
Пример #13
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'])))
Пример #14
0
    def test_generate_sorted(self):
        settings = get_settings(filenames={})
        settings['PAGE_PATHS'] = ['TestPages']  # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        # 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'],
            [
                'This is a test page with a preset template', 'published',
                'custom'
            ],
        ]
        generator = PagesGenerator(context=settings.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_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'],
            ['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'
        generator = PagesGenerator(context=settings.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)
Пример #15
0
    def test_page_object_caching(self):
        """Test Page objects caching at the generator level"""
        settings = get_settings(filenames={})
        settings['CACHE_DIRECTORY'] = self.temp_cache
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['READERS'] = {'asc': None}

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

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        generator.readers.read_file.assert_called_count == 0
Пример #16
0
    def test_content_caching(self):
        """Test that the pages are read only once when caching"""
        settings = get_settings(filenames={})
        settings['CACHE_DIRECTORY'] = 'cache_dir'   #TODO
        settings['CACHE_DIRECTORY'] = self.temp_cache
        settings['READERS'] = {'asc': None}

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

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        generator.readers.read_file.assert_called_count == 0
Пример #17
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(filenames={})
        settings['PAGE_PATHS'] = ['TestPages'] # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)

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

        test_content = pages_by_title['Page with a bunch of links']
        self.assertIn('<a href="/category/yeah.html">', test_content)
        self.assertIn('<a href="/tag/matsuku.html">', test_content)
Пример #18
0
    def test_content_caching(self):
        """Test that the pages are read only once when caching"""
        settings = get_settings(filenames={})
        settings['CACHE_DIRECTORY'] = 'cache_dir'   #TODO
        settings['CACHE_DIRECTORY'] = self.temp_cache
        settings['READERS'] = {'asc': None}

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

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        generator.readers.read_file.assert_called_count == 0
Пример #19
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(filenames={})
        settings['PAGE_PATHS'] = ['TestPages']    # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)

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

        test_content = pages_by_title['Page with a bunch of links']
        self.assertIn('<a href="/category/yeah.html">', test_content)
        self.assertIn('<a href="/tag/matsuku.html">', test_content)
Пример #20
0
    def test_page_object_caching(self):
        """Test Page objects caching at the generator level"""
        settings = get_settings(filenames={})
        settings['CACHE_PATH'] = self.temp_cache
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['READERS'] = {'asc': None}

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

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        generator.readers.read_file.assert_called_count == 0
Пример #21
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'])
Пример #22
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'])
Пример #23
0
    def test_reader_content_caching(self):
        """Test raw content caching at the reader level"""
        settings = get_settings(filenames={})
        settings['CACHE_PATH'] = self.temp_cache
        settings['READERS'] = {'asc': None}

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

        generator = PagesGenerator(
            context=settings.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():
            reader.read.assert_called_count == 0
Пример #24
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}

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

        generator = PagesGenerator(
            context=settings.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)
Пример #25
0
    def test_generate_sorted(self):
        settings = get_settings(filenames={})
        settings['PAGE_PATHS'] = ['TestPages']  # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        # 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'],
            ['This is a test page with a preset template', 'published',
             'custom'],
        ]
        generator = PagesGenerator(
            context=settings.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_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'],
            ['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'
        generator = PagesGenerator(
            context=settings.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)
Пример #26
0
    def test_generate_context(self):
        settings = get_settings()
        settings["PAGE_DIR"] = "TestPages"
        settings["DEFAULT_DATE"] = (1970, 1, 1)

        generator = PagesGenerator(settings.copy(), settings, CUR_DIR, settings["THEME"], None, settings["MARKUP"])
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_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"],
        ]
        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"],
        ]

        self.assertItemsEqual(pages_expected, pages)
        self.assertItemsEqual(hidden_pages_expected, hidden_pages)
Пример #27
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}

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

        generator = PagesGenerator(
            context=settings.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)
Пример #28
0
    def test_ignore_cache(self):
        """Test that all the pages are read again when not loading cache

        used in --ignore_cache or autoreload mode"""
        settings = get_settings(filenames={})
        settings['CACHE_DIRECTORY'] = self.temp_cache
        settings['READERS'] = {'asc': None}

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CONTENT_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=settings.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        generator.readers.read_file.assert_called_count == orig_call_count
Пример #29
0
 def gen_page_and_html_from_rst(self, rstPath):
     content, metadata = self.reader.read(rstPath)
     page = Page(content=content, metadata=metadata)
     context = self.settings.copy()
     context['generated_content'] = {}
     context['static_links'] = set()
     context['static_content'] = {}
     context['localsiteurl'] = self.settings['SITEURL']
     generator = PagesGenerator(context=context,
                                settings=self.settings,
                                path=CONTENT_DIR,
                                theme=self.settings['THEME'],
                                output_path=OUTPUT_DIR)
     generator.generate_context()
     f = lambda a: True if (a.slug == page.slug) else False
     result = list(filter(f, generator.context["pages"]))[0]
     self.writer.write_file(result.save_as,
                            generator.get_template('page'),
                            generator.context,
                            page=result)
     soup = BeautifulSoup(
         open("./" + self.writer.output_path + '/' + result.save_as),
         "html.parser")
     return (result, soup)
Пример #30
0
    def test_generate_sorted(self):
        settings = get_settings(filenames={})
        settings["PAGE_PATHS"] = ["TestPages"]  # relative to CUR_DIR
        settings["CACHE_PATH"] = self.temp_cache
        settings["DEFAULT_DATE"] = (1970, 1, 1)

        # 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"],
            ["This is a test page with a preset template", "published", "custom"],
        ]
        generator = PagesGenerator(
            context=settings.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_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"],
            ["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"
        generator = PagesGenerator(
            context=settings.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 a bunch of links", "published", "page"],
            ["A Page (Test) for sorting", "published", "page"],
        ]
        settings["PAGE_ORDER_BY"] = "reversed-title"
        generator = PagesGenerator(
            context=settings.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)
Пример #31
0
    def test_replace_delicious_tags(self):

        settings = get_settings(filenames={})
        settings['DEFAULT_CATEGORY'] = 'Default'
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        settings['READERS'] = {'asc': None}

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path="/tmp", theme=settings['THEME'], output_path=None)
        generator.generate_context()

        d = {'DELICIOUS_TEMPLATE': delicious_default_template,
             'DELICIOUS_BOOKMARKS': set([self.b1, self.b2, self.b3])}

        generator.context.update(d)

        p1 = Page("a [delicious tag1] z")
        e1 = """a <div class="delicious">

    <dl>
        <dt>Title</dt>
        <dd>desc2</dd>
        <dt>Description</dt>
        <dd>ext2</dd>
        <dt>URL</dt>
        <dd><a href="url2">url2</a></dd>
    </dl>

    <dl>
        <dt>Title</dt>
        <dd>desc1</dd>
        <dt>Description</dt>
        <dd>ext1</dd>
        <dt>URL</dt>
        <dd><a href="url1">url1</a></dd>
    </dl>

</div> z"""

        p2 = Page("a [delicious tag1 tag2] z")
        e2 = e1

        p3 = Page("a [delicious tag3] z")
        e3 = """a <div class="delicious">

    <dl>
        <dt>Title</dt>
        <dd>desc3</dd>
        <dt>Description</dt>
        <dd>ext3</dd>
        <dt>URL</dt>
        <dd><a href="url3">url3</a></dd>
    </dl>

</div> z"""
        generator.pages = [p1, p2, p3]
        replace_delicious_tags(generator)

        self.assertEqual(generator.pages[0]._content, e1)
        self.assertEqual(generator.pages[1]._content, e2)
        self.assertEqual(generator.pages[2]._content, e3)