Esempio n. 1
0
    def test_in_memory(self):
        test_path = os.path.dirname(os.path.realpath(__file__))
        output_data = generate(os.path.join(test_path, 'data-themed',
                                            'config-permalinks.yml'),
                               os.path.join(test_path, 'data-themed'),
                               in_memory=True)

        self.assertIn('index.html', output_data)
        self.assertIn('test', output_data)
        self.assertIn('index.html', output_data['test'])

        tree = ET.fromstring(_str(output_data['test']['index.html']))
        heading2 = tree.findall('./body/h2')[0]
        self.assertEqual('heres-a-heading', heading2.get('id'))
        permalink2 = tree.findall('./body/h2/a')[0]
        self.assertEqual('#heres-a-heading', permalink2.get('href'))
        self.assertEqual('permalink', permalink2.get('class'))
        self.assertEqual('Permalink to this heading', permalink2.get('title'))

        heading3 = tree.findall('./body/h3')[0]
        self.assertEqual('heres-another-sub-heading', heading3.get('id'))
        permalink3 = tree.findall('./body/h3/a')[0]
        self.assertEqual('#heres-another-sub-heading', permalink3.get('href'))
        self.assertEqual('permalink', permalink3.get('class'))
        self.assertEqual('Permalink to this heading', permalink3.get('title'))
    def test_in_memory(self):
        test_path = os.path.dirname(os.path.realpath(__file__))
        output_data = generate(os.path.join(test_path, 'data-themed',
                                            'config-custom-md-exts.yml'),
                               os.path.join(test_path, 'data-themed'),
                               in_memory=True)

        self.assertIn('index.html', output_data)
        self.assertIn('test', output_data)
        self.assertIn('test-with-code', output_data)
        self.assertIn('index.html', output_data['test'])
        self.assertIn('index.html', output_data['test-with-code'])

        tree = ET.fromstring(_str(output_data['test-with-code']['index.html']))
        self.assertEqual("Test post with some code",
                         tree.findall('./head/title')[0].text.strip())
        self.assertEqual("This should test the codehilite integration.",
                         tree.findall('./body/p')[0].text.strip())
        self.assertEqual("codehilite",
                         tree.findall('./body/pre')[0].get('class'))
        self.assertEqual("language-python",
                         tree.findall('./body/pre/code')[0].get('class'))

        self.assertEqual(
            "And now some more code, but in a different language:",
            tree.findall('./body/p')[1].text.strip())
        self.assertEqual("codehilite",
                         tree.findall('./body/pre')[1].get('class'))
        self.assertEqual("language-c",
                         tree.findall('./body/pre/code')[1].get('class'))
Esempio n. 3
0
 def assert_by_author_andrew_compiles(self, content):
     posts_by_author = ET.fromstring(_str(content))
     self.assertEqual('html', posts_by_author.findall('.')[0].tag)
     self.assertEqual('Posts by Andrew', posts_by_author.findall('./head/title')[0].text.strip())
     self.assertEqual('Posts by Andrew', posts_by_author.findall('./body/h1')[0].text.strip())
     links_by_author_els = posts_by_author.findall('.//li/a')
     links_by_author = [el.attrib['href'] for el in links_by_author_els]
     link_titles_by_author = [el.text.strip() for el in links_by_author_els]
     self.assertEqual(
         [
             '/2018/01/20/test-datetime-format/',
             '/2016/06/30/tables-test/',
             '/2016/06/25/andrew-second-post/',
             '/2016/06/12/andrew-hello-world/'
         ],
         links_by_author
     )
     self.assertEqual(
         [
             'Testing DateTime format (as per issue #59)',
             'Testing Markdown tables',
             'Andrew\'s Second Post',
             'Andrew says Hello World'
         ],
         link_titles_by_author,
     )
Esempio n. 4
0
    def assert_homepage_compiles(self, page_content):
        # Parse the home page's XHTML content
        homepage = ET.fromstring(_str(page_content))
        self.assertEqual('html', homepage.findall('.')[0].tag)
        self.assertEqual('Welcome to the test blog', homepage.findall('./head/title')[0].text.strip())
        self.assertEqual('Home page', homepage.findall('./body/h1')[0].text.strip())
        # Test the project-wide static context variables
        self.assertEqual(
            'This is some information about the unit test web site.',
            homepage.findall("./body/div[@class='site-summary']")[0].text.strip(),
        )

        # Test the ordering of links on the homepage
        homepage_link_els = homepage.findall('./body/ul/li/a')
        homepage_links = [el.attrib['href'] for el in homepage_link_els]
        homepage_link_titles = [el.text.strip() for el in homepage_link_els]
        self.assertEqual(
            [
                '/2016/06/30/tables-test/',
                '/2016/06/25/andrew-second-post/',
                '/2016/06/18/second-post/',
                '/2016/06/15/my-first-post/',
                '/2016/06/12/andrew-hello-world/'
            ],
            homepage_links,
        )
        self.assertEqual(
            [
                'Testing Markdown tables',
                'Andrew\'s Second Post',
                'Second post',
                'My first post',
                'Andrew says Hello World'
            ],
            homepage_link_titles,
        )

        # Test the project-wide dynamic context variables
        self.assertEqual("Andrew Michaels", homepage.findall("./body/div[@class='all-authors']/ul/li")[0].text.strip())
        self.assertEqual("Michael Anderson", homepage.findall("./body/div[@class='all-authors']/ul/li")[1].text.strip())
        # Test the new {% asset %} tag
        self.assertEqual("/assets/testfile.txt", homepage.findall("./body/div[@class='download']/a")[0].attrib['href'])

        # Test the Lorem Ipsum generators
        self.assertEqual(
            100,
            lipsum.count_words(homepage.findall("./body/div[@class='lorem-ipsum']/p")[0].text.strip())
        )
        self.assertEqual(
            5,
            lipsum.count_sentences(homepage.findall("./body/div[@class='lorem-ipsum']/p")[1].text.strip())
        )
        self.assertTrue(
            lipsum.count_words(homepage.findall("./body/div[@class='lorem-ipsum']/p")[2].text.strip()) > 1
        )
Esempio n. 5
0
 def assert_andrew_bio_compiles(self, content):
     bio = ET.fromstring(_str(content))
     self.assertEqual('html', bio.findall('.')[0].tag)
     self.assertEqual('Andrew Michaels', bio.findall('./head/title')[0].text.strip())
     self.assertEqual('mailto:[email protected]', bio.findall(".//div[@class='meta']/a")[0].attrib['href'])
     self.assertEqual('Contact Andrew', bio.findall(".//div[@class='meta']/a")[0].text.strip())
     bio_content = bio.findall(".//div[@class='content']/p")[0]
     bio_content_els = [el for el in bio_content]
     self.assertEqual('em', bio_content_els[0].tag)
     bio_content_text = strip_el_text(bio_content, max_depth=1)
     self.assertEqual("Here's Andrew's bio!", bio_content_text)
Esempio n. 6
0
 def assert_michael_bio_compiles(self, content):
     bio = ET.fromstring(_str(content))
     self.assertEqual('html', bio.findall('.')[0].tag)
     self.assertEqual('Michael Anderson', bio.findall('./head/title')[0].text.strip())
     self.assertEqual('mailto:[email protected]', bio.findall(".//div[@class='meta']/a")[0].attrib['href'])
     self.assertEqual('Contact Michael', bio.findall(".//div[@class='meta']/a")[0].text.strip())
     bio_content = bio.findall(".//div[@class='content']/p")[0]
     bio_content_els = [el for el in bio_content]
     self.assertEqual('strong', bio_content_els[0].tag)
     self.assertEqual('Markdown', bio_content_els[0].text.strip())
     bio_content_text = strip_el_text(bio_content, max_depth=1)
     self.assertEqual("This is Michael's bio, in Markdown format.", bio_content_text)
Esempio n. 7
0
    def test_lorem_ipsum_extension(self):
        md = Markdown(extensions=[
            MarkdownYamlMetaExtension(),
            MarkdownLoremIpsumExtension()
        ])
        html = "<html>" + md.convert(TEST_LOREM_IPSUM_CONTENT) + "</html>"
        tree = ET.fromstring(_str(html))
        p = tree.findall('./p')[0]
        self.assertEqual(100, lipsum.count_words(p.text))

        p = tree.findall('./p')[1]
        self.assertEqual(5, lipsum.count_sentences(p.text))
        self.assertEqual(3, len(tree.findall('./p')[2:]))

        html = "<html>" + md.convert(
            TEST_LOREM_IPSUM_SINGLE_INSTANCES) + "</html>"
        tree = ET.fromstring(_str(html))
        p = tree.findall('./p')[0]
        self.assertEqual(1, lipsum.count_words(p.text))

        p = tree.findall('./p')[1]
        self.assertEqual(1, lipsum.count_sentences(p.text))
        self.assertEqual(1, len(tree.findall('./p')[2:]))
Esempio n. 8
0
 def assert_andrew_bio_compiles(self, content):
     bio = ET.fromstring(_str(content))
     self.assertEqual('html', bio.findall('.')[0].tag)
     self.assertEqual('Andrew Michaels',
                      bio.findall('./head/title')[0].text.strip())
     self.assertEqual(
         'mailto:[email protected]',
         bio.findall(".//div[@class='meta']/a")[0].attrib['href'])
     self.assertEqual(
         'Contact Andrew',
         bio.findall(".//div[@class='meta']/a")[0].text.strip())
     bio_content = bio.findall(".//div[@class='content']/p")[0]
     bio_content_els = [el for el in bio_content]
     self.assertEqual('em', bio_content_els[0].tag)
     bio_content_text = strip_el_text(bio_content, max_depth=1)
     self.assertEqual("Here's Andrew's bio!", bio_content_text)
Esempio n. 9
0
 def assert_michael_bio_compiles(self, content):
     bio = ET.fromstring(_str(content))
     self.assertEqual('html', bio.findall('.')[0].tag)
     self.assertEqual('Michael Anderson',
                      bio.findall('./head/title')[0].text.strip())
     self.assertEqual(
         'mailto:[email protected]',
         bio.findall(".//div[@class='meta']/a")[0].attrib['href'])
     self.assertEqual(
         'Contact Michael',
         bio.findall(".//div[@class='meta']/a")[0].text.strip())
     bio_content = bio.findall(".//div[@class='content']/p")[0]
     bio_content_els = [el for el in bio_content]
     self.assertEqual('strong', bio_content_els[0].tag)
     self.assertEqual('Markdown', bio_content_els[0].text.strip())
     bio_content_text = strip_el_text(bio_content, max_depth=1)
     self.assertEqual("This is Michael's bio, in Markdown format.",
                      bio_content_text)
Esempio n. 10
0
    def test_permalink_extension(self):
        md = Markdown(extensions=[
            MarkdownPermalinkExtension(
                permalink_text="¶",
                permalink_class="permalink",
                permalink_title="Permalink to this headline")
        ])
        html = "<html><body>" + md.convert(
            TEST_PERMALINK_CONTENT) + "</body></html>"
        tree = ET.fromstring(_str(html))

        for tag_id in range(1, 7):
            heading = tree.findall('./body/h%d' % tag_id)[0]
            self.assertEqual('heading-%d' % tag_id, heading.get('id'))
            link = tree.findall('./body/h%d/a' % tag_id)[0]
            self.assertEqual('#heading-%d' % tag_id, link.get('href'))
            self.assertEqual('permalink', link.get('class'))
            self.assertEqual('Permalink to this headline', link.get('title'))
Esempio n. 11
0
 def assert_my_first_post_compiles(self, content):
     post = ET.fromstring(_str(content))
     self.assertEqual('html', post.findall('.')[0].tag)
     self.assertEqual('My first post', post.findall('./head/title')[0].text.strip())
     self.assertEqual('2016-06-15', post.findall(".//div[@class='published']")[0].text.strip())
     self.assertEqual('/bios/michael/', post.findall(".//div[@class='author']/a")[0].attrib['href'])
     self.assertEqual('By Michael', post.findall(".//div[@class='author']/a")[0].text.strip())
     post_content = post.findall(".//div[@class='content']/p")[0]
     post_content_els = [el for el in post_content]
     self.assertEqual('strong', post_content_els[0].tag)
     self.assertEqual('Markdown', post_content_els[0].text.strip())
     self.assertEqual('code', post_content_els[1].tag)
     self.assertEqual('HTML', post_content_els[1].text.strip())
     post_content_text = strip_el_text(post_content, max_depth=1)
     self.assertEqual(
         "This is the Markdown content of the first post, which should appropriately be translated into the " +
         "relevant HTML code.",
         post_content_text
     )
    def test_in_memory(self):
        test_path = os.path.dirname(os.path.realpath(__file__))
        output_data = generate(
            os.path.join(test_path, 'data-themed', 'config-custom-md-exts.yml'),
            os.path.join(test_path, 'data-themed'),
            in_memory=True
        )

        self.assertIn('index.html', output_data)
        self.assertIn('test', output_data)
        self.assertIn('test-with-code', output_data)
        self.assertIn('index.html', output_data['test'])
        self.assertIn('index.html', output_data['test-with-code'])

        tree = ET.fromstring(_str(output_data['test-with-code']['index.html']))
        self.assertEqual("Test post with some code", tree.findall('./head/title')[0].text.strip())
        self.assertEqual(
            "This should test the codehilite integration.",
            tree.findall('./body/p')[0].text.strip()
        )
        self.assertEqual(
            "codehilite",
            tree.findall('./body/pre')[0].get('class')
        )
        self.assertEqual(
            "language-python",
            tree.findall('./body/pre/code')[0].get('class')
        )

        self.assertEqual(
            "And now some more code, but in a different language:",
            tree.findall('./body/p')[1].text.strip()
        )
        self.assertEqual(
            "codehilite",
            tree.findall('./body/pre')[1].get('class')
        )
        self.assertEqual(
            "language-c",
            tree.findall('./body/pre/code')[1].get('class')
        )
Esempio n. 13
0
 def assert_by_author_michael_compiles(self, content):
     posts_by_author = ET.fromstring(_str(content))
     self.assertEqual('html', posts_by_author.findall('.')[0].tag)
     self.assertEqual('Posts by Michael', posts_by_author.findall('./head/title')[0].text.strip())
     self.assertEqual('Posts by Michael', posts_by_author.findall('./body/h1')[0].text.strip())
     links_by_author_els = posts_by_author.findall('.//li/a')
     links_by_author = [el.attrib['href'] for el in links_by_author_els]
     link_titles_by_author = [el.text.strip() for el in links_by_author_els]
     self.assertEqual(
         [
             '/2016/06/18/second-post/',
             '/2016/06/15/my-first-post/',
         ],
         links_by_author
     )
     self.assertEqual(
         [
             'Second post',
             'My first post',
         ],
         link_titles_by_author,
     )
Esempio n. 14
0
 def assert_by_author_michael_compiles(self, content):
     posts_by_author = ET.fromstring(_str(content))
     self.assertEqual('html', posts_by_author.findall('.')[0].tag)
     self.assertEqual(
         'Posts by Michael',
         posts_by_author.findall('./head/title')[0].text.strip())
     self.assertEqual('Posts by Michael',
                      posts_by_author.findall('./body/h1')[0].text.strip())
     links_by_author_els = posts_by_author.findall('.//li/a')
     links_by_author = [el.attrib['href'] for el in links_by_author_els]
     link_titles_by_author = [el.text.strip() for el in links_by_author_els]
     self.assertEqual([
         '/2016/06/18/second-post/',
         '/2016/06/15/my-first-post/',
     ], links_by_author)
     self.assertEqual(
         [
             'Second post',
             'My first post',
         ],
         link_titles_by_author,
     )
Esempio n. 15
0
 def assert_by_author_andrew_compiles(self, content):
     posts_by_author = ET.fromstring(_str(content))
     self.assertEqual('html', posts_by_author.findall('.')[0].tag)
     self.assertEqual(
         'Posts by Andrew',
         posts_by_author.findall('./head/title')[0].text.strip())
     self.assertEqual('Posts by Andrew',
                      posts_by_author.findall('./body/h1')[0].text.strip())
     links_by_author_els = posts_by_author.findall('.//li/a')
     links_by_author = [el.attrib['href'] for el in links_by_author_els]
     link_titles_by_author = [el.text.strip() for el in links_by_author_els]
     self.assertEqual([
         '/2018/01/20/test-datetime-format/', '/2016/06/30/tables-test/',
         '/2016/06/25/andrew-second-post/',
         '/2016/06/12/andrew-hello-world/'
     ], links_by_author)
     self.assertEqual(
         [
             'Testing DateTime format (as per issue #59)',
             'Testing Markdown tables', 'Andrew\'s Second Post',
             'Andrew says Hello World'
         ],
         link_titles_by_author,
     )
Esempio n. 16
0
 def assert_my_first_post_compiles(self, content):
     post = ET.fromstring(_str(content))
     self.assertEqual('html', post.findall('.')[0].tag)
     self.assertEqual('My first post',
                      post.findall('./head/title')[0].text.strip())
     self.assertEqual(
         '2016-06-15',
         post.findall(".//div[@class='published']")[0].text.strip())
     self.assertEqual(
         '/bios/michael/',
         post.findall(".//div[@class='author']/a")[0].attrib['href'])
     self.assertEqual(
         'By Michael',
         post.findall(".//div[@class='author']/a")[0].text.strip())
     post_content = post.findall(".//div[@class='content']/p")[0]
     post_content_els = [el for el in post_content]
     self.assertEqual('strong', post_content_els[0].tag)
     self.assertEqual('Markdown', post_content_els[0].text.strip())
     self.assertEqual('code', post_content_els[1].tag)
     self.assertEqual('HTML', post_content_els[1].text.strip())
     post_content_text = strip_el_text(post_content, max_depth=1)
     self.assertEqual(
         "This is the Markdown content of the first post, which should appropriately be translated into the "
         + "relevant HTML code.", post_content_text)
Esempio n. 17
0
    def test_in_memory(self):
        test_path = os.path.dirname(os.path.realpath(__file__))

        # Run the Statik generator on our unit test data project, put the
        # result in memory
        output_data = generate(
            os.path.join(test_path, 'data-simple'),
            in_memory=True
        )

        # Check that the home page is there
        self.assertIn('index.html', output_data)

        # Check that the generated .htaccess file is in the root of the output data
        self.assertIn('.htaccess', output_data)
        self.assertEqual(EXPECTED_HTACCESS_CONTENT, output_data['.htaccess'].strip())

        # Check that the generated posts are there
        self.assert_path_exists("2018/02/12/unicode-in-markdown-test/index.html", output_data)
        self.assert_path_exists("2018/01/20/test-datetime-format/index.html", output_data)
        self.assert_path_exists("2016/06/12/andrew-hello-world/index.html", output_data)
        self.assert_path_exists("2016/06/18/second-post/index.html", output_data)
        self.assert_path_exists("2016/06/25/andrew-second-post/index.html", output_data)
        self.assert_path_exists("2016/06/30/tables-test/index.html", output_data)
        self.assert_path_exists("tag-testing/index.html", output_data)
        self.assert_path_exists("overlap/index.html", output_data)
        self.assert_path_exists("overlap/andrew-hello-world/index.html", output_data)
        self.assert_path_exists("overlap/my-first-post/index.html", output_data)
        self.assert_path_exists("overlap/second-post/index.html", output_data)
        self.assert_path_exists("overlap/andrew-second-post/index.html", output_data)

        # Check that the paged posts exist
        self.assert_path_exists("paged-posts/1/index.html", output_data)
        self.assert_path_exists("paged-posts/2/index.html", output_data)
        self.assert_path_exists("paged-posts/3/index.html", output_data)
        self.assert_path_exists("paged-posts/4/index.html", output_data)

        # Check that the Unicode support for Markdown works as intended
        self.assert_unicode_content_compiles(output_data)

        # Check that the homepage compiles properly
        self.assert_homepage_compiles(output_data['index.html'])

        # Check that the post "my-first-post" compiles properly
        self.assert_my_first_post_compiles(self.assert_path_exists("2016/06/15/my-first-post/index.html", output_data))

        # Check that the two bios compiled properly
        self.assert_michael_bio_compiles(self.assert_path_exists("bios/michael/index.html", output_data))
        self.assert_andrew_bio_compiles(self.assert_path_exists("bios/andrew/index.html", output_data))

        # Test the for-each context rendering
        self.assert_by_author_andrew_compiles(self.assert_path_exists("by-author/andrew/index.html", output_data))
        self.assert_by_author_michael_compiles(self.assert_path_exists("by-author/michael/index.html", output_data))

        # Test the custom template tags/filters functionality
        tt = ET.fromstring(_str(output_data['tag-testing']['index.html']))
        self.assertEqual('html', tt.findall('.')[0].tag)
        para_tags = tt.findall('./body/p')
        self.assertEqual('Hello world!', para_tags[0].text.strip())
        self.assertEqual('an uppercase string', para_tags[1].text.strip())

        # Check the contents of the overlapping simple/complex views
        ov = ET.fromstring(_str(output_data['overlap']['index.html']))
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test', ov.findall('./head/title')[0].text.strip())
        self.assertEqual('Overlap Test', ov.findall('./body/h1')[0].text.strip())

        ov = ET.fromstring(output_data['overlap']['andrew-hello-world']['index.html'])
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test', ov.findall('./head/title')[0].text.strip())
        self.assertEqual('Andrew says Hello World', ov.findall('./body/h1')[0].text.strip())

        ov = ET.fromstring(output_data['overlap']['my-first-post']['index.html'])
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test', ov.findall('./head/title')[0].text.strip())
        self.assertEqual('My first post', ov.findall('./body/h1')[0].text.strip())

        ov = ET.fromstring(output_data['overlap']['second-post']['index.html'])
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test', ov.findall('./head/title')[0].text.strip())
        self.assertEqual('Second post', ov.findall('./body/h1')[0].text.strip())

        ov = ET.fromstring(output_data['overlap']['andrew-second-post']['index.html'])
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test', ov.findall('./head/title')[0].text.strip())
        self.assertEqual("Andrew's Second Post", ov.findall('./body/h1')[0].text.strip())

        # Test the Markdown table generation
        tables = ET.fromstring(output_data['2016']['06']['30']['tables-test']['index.html'])
        self.assertEqual('html', tables.findall('.')[0].tag)
        headings = tables.findall("./body/div[@class='content']/table/thead/tr/th")
        self.assertEqual(3, len(headings))
        self.assertEqual(['Heading 1', 'Heading 2', 'Heading 3'], [el.text.strip() for el in headings])

        cells = tables.findall("./body/div[@class='content']/table/tbody/tr/td")
        self.assertEqual(6, len(cells))
        self.assertEqual(
            ['One', 'Two', 'Three', 'Four', 'Five', 'Six'],
            [el.text.strip() for el in cells]
        )

        # Now test for the pagination
        pp = ET.fromstring(_str(output_data['paged-posts']['1']['index.html']))
        self.assertEqual('html', pp.findall('.')[0].tag)
        self.assertEqual('Page 1 of 4', pp.findall('./head/title')[0].text.strip())
        self.assertEqual('Page 1 of 4', pp.findall('./body/h1')[0].text.strip())
        pp_els = pp.findall('./body/ul/li/a')
        pp_links = [el.attrib['href'] for el in pp_els]
        pp_link_titles = [el.text.strip() for el in pp_els]
        self.assertEqual(
            [
                '/2018/02/12/unicode-in-markdown-test/',
                '/2018/01/20/test-datetime-format/'
            ],
            pp_links,
        )
        self.assertEqual(
            [
                'Testing Unicode θ in Markdown content (issues #50 and #63)',
                'Testing DateTime format (as per issue #59)'
            ],
            pp_link_titles,
        )

        pp = ET.fromstring(_str(output_data['paged-posts']['2']['index.html']))
        self.assertEqual('html', pp.findall('.')[0].tag)
        self.assertEqual('Page 2 of 4', pp.findall('./head/title')[0].text.strip())
        self.assertEqual('Page 2 of 4', pp.findall('./body/h1')[0].text.strip())
        pp_els = pp.findall('./body/ul/li/a')
        pp_links = [el.attrib['href'] for el in pp_els]
        pp_link_titles = [el.text.strip() for el in pp_els]
        self.assertEqual(
            [
                '/2016/06/30/tables-test/',
                '/2016/06/25/andrew-second-post/'
            ],
            pp_links,
        )
        self.assertEqual(
            [
                'Testing Markdown tables',
                'Andrew\'s Second Post'
            ],
            pp_link_titles,
        )

        pp = ET.fromstring(_str(output_data['paged-posts']['3']['index.html']))
        self.assertEqual('html', pp.findall('.')[0].tag)
        self.assertEqual('Page 3 of 4', pp.findall('./head/title')[0].text.strip())
        self.assertEqual('Page 3 of 4', pp.findall('./body/h1')[0].text.strip())
        pp_els = pp.findall('./body/ul/li/a')
        pp_links = [el.attrib['href'] for el in pp_els]
        pp_link_titles = [el.text.strip() for el in pp_els]
        self.assertEqual(
            [
                '/2016/06/18/second-post/',
                '/2016/06/15/my-first-post/'
            ],
            pp_links,
        )
        self.assertEqual(
            [
                'Second post',
                'My first post'
            ],
            pp_link_titles,
        )

        pp = ET.fromstring(_str(output_data['paged-posts']['4']['index.html']))
        self.assertEqual('html', pp.findall('.')[0].tag)
        self.assertEqual('Page 4 of 4', pp.findall('./head/title')[0].text.strip())
        self.assertEqual('Page 4 of 4', pp.findall('./body/h1')[0].text.strip())
        pp_els = pp.findall('./body/ul/li/a')
        pp_links = [el.attrib['href'] for el in pp_els]
        pp_link_titles = [el.text.strip() for el in pp_els]
        self.assertEqual(
            [
                '/2016/06/12/andrew-hello-world/'
            ],
            pp_links,
        )
        self.assertEqual(
            [
                'Andrew says Hello World'
            ],
            pp_link_titles,
        )

        self.assert_mlalchemy_complex_path_view_compiles(output_data)
        self.assert_homepage_compiles(self.assert_path_exists("mlalchemy/posts/index.html", output_data))
        self.assert_json_data_compiles(output_data)
        self.assert_generated_js_compiles(output_data)
Esempio n. 18
0
    def assert_homepage_compiles(self, page_content):
        # Parse the home page's XHTML content
        homepage = ET.fromstring(_str(page_content))
        self.assertEqual('html', homepage.findall('.')[0].tag)
        self.assertEqual('Welcome to the test blog',
                         homepage.findall('./head/title')[0].text.strip())
        self.assertEqual('Home page',
                         homepage.findall('./body/h1')[0].text.strip())
        # Test the project-wide static context variables
        self.assertEqual(
            'This is some information about the unit test web site.',
            homepage.findall("./body/div[@class='site-summary']")
            [0].text.strip(),
        )

        # Test the ordering of links on the homepage
        homepage_link_els = homepage.findall('./body/ul/li/a')
        homepage_links = [el.attrib['href'] for el in homepage_link_els]
        homepage_link_titles = [el.text.strip() for el in homepage_link_els]
        self.assertEqual(
            [
                '/2018/02/12/unicode-in-markdown-test/',
                '/2018/01/20/test-datetime-format/',
                '/2016/06/30/tables-test/', '/2016/06/25/andrew-second-post/',
                '/2016/06/18/second-post/', '/2016/06/15/my-first-post/',
                '/2016/06/12/andrew-hello-world/'
            ],
            homepage_links,
        )
        self.assertEqual(
            [
                'Testing Unicode θ in Markdown content (issues #50 and #63)',
                'Testing DateTime format (as per issue #59)',
                'Testing Markdown tables', 'Andrew\'s Second Post',
                'Second post', 'My first post', 'Andrew says Hello World'
            ],
            homepage_link_titles,
        )

        # Test the project-wide dynamic context variables
        self.assertEqual(
            "Andrew Michaels",
            homepage.findall("./body/div[@class='all-authors']/ul/li")
            [0].text.strip())
        self.assertEqual(
            "John Johnson",
            homepage.findall("./body/div[@class='all-authors']/ul/li")
            [1].text.strip())
        self.assertEqual(
            "Michael Anderson",
            homepage.findall("./body/div[@class='all-authors']/ul/li")
            [2].text.strip())
        # Test the new {% asset %} tag
        self.assertEqual(
            "/assets/testfile.txt",
            homepage.findall("./body/div[@class='download']/a")
            [0].attrib['href'])

        # Test the Lorem Ipsum generators
        self.assertEqual(
            100,
            lipsum.count_words(
                homepage.findall("./body/div[@class='lorem-ipsum']/p")
                [0].text.strip()))
        self.assertEqual(
            5,
            lipsum.count_sentences(
                homepage.findall("./body/div[@class='lorem-ipsum']/p")
                [1].text.strip()))
        self.assertTrue(
            lipsum.count_words(
                homepage.findall("./body/div[@class='lorem-ipsum']/p")
                [2].text.strip()) > 1)

        # check the generated script URL - that it has no trailing slash (issue #48)
        script = homepage.find('body/script')
        self.assertIsNotNone(script)
        self.assertEqual('/scripts/generated.js', script.attrib['src'])
Esempio n. 19
0
    def assert_homepage_compiles(self, page_content):
        # Parse the home page's XHTML content
        homepage = ET.fromstring(_str(page_content))
        self.assertEqual('html', homepage.findall('.')[0].tag)
        self.assertEqual('Welcome to the test blog',
                         homepage.findall('./head/title')[0].text.strip())
        self.assertEqual('Home page',
                         homepage.findall('./body/h1')[0].text.strip())
        # Test the project-wide static context variables
        self.assertEqual(
            'This is some information about the unit test web site.',
            homepage.findall("./body/div[@class='site-summary']")
            [0].text.strip(),
        )

        # Test the ordering of links on the homepage
        homepage_link_els = homepage.findall('./body/ul/li/a')
        homepage_links = [el.attrib['href'] for el in homepage_link_els]
        homepage_link_titles = [el.text.strip() for el in homepage_link_els]
        self.assertEqual(
            [
                '/2016/06/30/tables-test/', '/2016/06/25/andrew-second-post/',
                '/2016/06/18/second-post/', '/2016/06/15/my-first-post/',
                '/2016/06/12/andrew-hello-world/'
            ],
            homepage_links,
        )
        self.assertEqual(
            [
                'Testing Markdown tables', 'Andrew\'s Second Post',
                'Second post', 'My first post', 'Andrew says Hello World'
            ],
            homepage_link_titles,
        )

        # Test the project-wide dynamic context variables
        self.assertEqual(
            "Andrew Michaels",
            homepage.findall("./body/div[@class='all-authors']/ul/li")
            [0].text.strip())
        self.assertEqual(
            "Michael Anderson",
            homepage.findall("./body/div[@class='all-authors']/ul/li")
            [1].text.strip())
        # Test the new {% asset %} tag
        self.assertEqual(
            "/assets/testfile.txt",
            homepage.findall("./body/div[@class='download']/a")
            [0].attrib['href'])

        # Test the Lorem Ipsum generators
        self.assertEqual(
            100,
            lipsum.count_words(
                homepage.findall("./body/div[@class='lorem-ipsum']/p")
                [0].text.strip()))
        self.assertEqual(
            5,
            lipsum.count_sentences(
                homepage.findall("./body/div[@class='lorem-ipsum']/p")
                [1].text.strip()))
        self.assertTrue(
            lipsum.count_words(
                homepage.findall("./body/div[@class='lorem-ipsum']/p")
                [2].text.strip()) > 1)
Esempio n. 20
0
    def test_in_memory(self):
        test_path = os.path.dirname(os.path.realpath(__file__))

        # Run the Statik generator on our unit test data project, put the
        # result in memory
        output_data = generate(os.path.join(test_path, 'data-simple'),
                               in_memory=True)

        # Check that the home page is there
        self.assertIn('index.html', output_data)

        # Check that the generated .htaccess file is in the root of the output data
        self.assertIn('.htaccess', output_data)
        self.assertEqual(EXPECTED_HTACCESS_CONTENT,
                         output_data['.htaccess'].strip())

        # Check that the generated posts are there
        self.assert_path_exists(
            "2018/02/12/unicode-in-markdown-test/index.html", output_data)
        self.assert_path_exists("2018/01/20/test-datetime-format/index.html",
                                output_data)
        self.assert_path_exists("2016/06/12/andrew-hello-world/index.html",
                                output_data)
        self.assert_path_exists("2016/06/18/second-post/index.html",
                                output_data)
        self.assert_path_exists("2016/06/25/andrew-second-post/index.html",
                                output_data)
        self.assert_path_exists("2016/06/30/tables-test/index.html",
                                output_data)
        self.assert_path_exists("tag-testing/index.html", output_data)
        self.assert_path_exists("overlap/index.html", output_data)
        self.assert_path_exists("overlap/andrew-hello-world/index.html",
                                output_data)
        self.assert_path_exists("overlap/my-first-post/index.html",
                                output_data)
        self.assert_path_exists("overlap/second-post/index.html", output_data)
        self.assert_path_exists("overlap/andrew-second-post/index.html",
                                output_data)

        # Check that the paged posts exist
        self.assert_path_exists("paged-posts/1/index.html", output_data)
        self.assert_path_exists("paged-posts/2/index.html", output_data)
        self.assert_path_exists("paged-posts/3/index.html", output_data)
        self.assert_path_exists("paged-posts/4/index.html", output_data)

        # Check that the Unicode support for Markdown works as intended
        self.assert_unicode_content_compiles(output_data)

        # Check that the homepage compiles properly
        self.assert_homepage_compiles(output_data['index.html'])

        # Check that the post "my-first-post" compiles properly
        self.assert_my_first_post_compiles(
            self.assert_path_exists("2016/06/15/my-first-post/index.html",
                                    output_data))

        # Check that the two bios compiled properly
        self.assert_michael_bio_compiles(
            self.assert_path_exists("bios/michael/index.html", output_data))
        self.assert_andrew_bio_compiles(
            self.assert_path_exists("bios/andrew/index.html", output_data))

        # Test the for-each context rendering
        self.assert_by_author_andrew_compiles(
            self.assert_path_exists("by-author/andrew/index.html",
                                    output_data))
        self.assert_by_author_michael_compiles(
            self.assert_path_exists("by-author/michael/index.html",
                                    output_data))

        # Test the custom template tags/filters functionality
        tt = ET.fromstring(_str(output_data['tag-testing']['index.html']))
        self.assertEqual('html', tt.findall('.')[0].tag)
        para_tags = tt.findall('./body/p')
        self.assertEqual('Hello world!', para_tags[0].text.strip())
        self.assertEqual('an uppercase string', para_tags[1].text.strip())

        # Check the contents of the overlapping simple/complex views
        ov = ET.fromstring(_str(output_data['overlap']['index.html']))
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test',
                         ov.findall('./head/title')[0].text.strip())
        self.assertEqual('Overlap Test',
                         ov.findall('./body/h1')[0].text.strip())

        ov = ET.fromstring(
            output_data['overlap']['andrew-hello-world']['index.html'])
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test',
                         ov.findall('./head/title')[0].text.strip())
        self.assertEqual('Andrew says Hello World',
                         ov.findall('./body/h1')[0].text.strip())

        ov = ET.fromstring(
            output_data['overlap']['my-first-post']['index.html'])
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test',
                         ov.findall('./head/title')[0].text.strip())
        self.assertEqual('My first post',
                         ov.findall('./body/h1')[0].text.strip())

        ov = ET.fromstring(output_data['overlap']['second-post']['index.html'])
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test',
                         ov.findall('./head/title')[0].text.strip())
        self.assertEqual('Second post',
                         ov.findall('./body/h1')[0].text.strip())

        ov = ET.fromstring(
            output_data['overlap']['andrew-second-post']['index.html'])
        self.assertEqual('html', ov.findall('.')[0].tag)
        self.assertEqual('Overlap Test',
                         ov.findall('./head/title')[0].text.strip())
        self.assertEqual("Andrew's Second Post",
                         ov.findall('./body/h1')[0].text.strip())

        # Test the Markdown table generation
        tables = ET.fromstring(
            output_data['2016']['06']['30']['tables-test']['index.html'])
        self.assertEqual('html', tables.findall('.')[0].tag)
        headings = tables.findall(
            "./body/div[@class='content']/table/thead/tr/th")
        self.assertEqual(3, len(headings))
        self.assertEqual(['Heading 1', 'Heading 2', 'Heading 3'],
                         [el.text.strip() for el in headings])

        cells = tables.findall(
            "./body/div[@class='content']/table/tbody/tr/td")
        self.assertEqual(6, len(cells))
        self.assertEqual(['One', 'Two', 'Three', 'Four', 'Five', 'Six'],
                         [el.text.strip() for el in cells])

        # Now test for the pagination
        pp = ET.fromstring(_str(output_data['paged-posts']['1']['index.html']))
        self.assertEqual('html', pp.findall('.')[0].tag)
        self.assertEqual('Page 1 of 4',
                         pp.findall('./head/title')[0].text.strip())
        self.assertEqual('Page 1 of 4',
                         pp.findall('./body/h1')[0].text.strip())
        pp_els = pp.findall('./body/ul/li/a')
        pp_links = [el.attrib['href'] for el in pp_els]
        pp_link_titles = [el.text.strip() for el in pp_els]
        self.assertEqual(
            [
                '/2018/02/12/unicode-in-markdown-test/',
                '/2018/01/20/test-datetime-format/'
            ],
            pp_links,
        )
        self.assertEqual(
            [
                'Testing Unicode θ in Markdown content (issues #50 and #63)',
                'Testing DateTime format (as per issue #59)'
            ],
            pp_link_titles,
        )

        pp = ET.fromstring(_str(output_data['paged-posts']['2']['index.html']))
        self.assertEqual('html', pp.findall('.')[0].tag)
        self.assertEqual('Page 2 of 4',
                         pp.findall('./head/title')[0].text.strip())
        self.assertEqual('Page 2 of 4',
                         pp.findall('./body/h1')[0].text.strip())
        pp_els = pp.findall('./body/ul/li/a')
        pp_links = [el.attrib['href'] for el in pp_els]
        pp_link_titles = [el.text.strip() for el in pp_els]
        self.assertEqual(
            ['/2016/06/30/tables-test/', '/2016/06/25/andrew-second-post/'],
            pp_links,
        )
        self.assertEqual(
            ['Testing Markdown tables', 'Andrew\'s Second Post'],
            pp_link_titles,
        )

        pp = ET.fromstring(_str(output_data['paged-posts']['3']['index.html']))
        self.assertEqual('html', pp.findall('.')[0].tag)
        self.assertEqual('Page 3 of 4',
                         pp.findall('./head/title')[0].text.strip())
        self.assertEqual('Page 3 of 4',
                         pp.findall('./body/h1')[0].text.strip())
        pp_els = pp.findall('./body/ul/li/a')
        pp_links = [el.attrib['href'] for el in pp_els]
        pp_link_titles = [el.text.strip() for el in pp_els]
        self.assertEqual(
            ['/2016/06/18/second-post/', '/2016/06/15/my-first-post/'],
            pp_links,
        )
        self.assertEqual(
            ['Second post', 'My first post'],
            pp_link_titles,
        )

        pp = ET.fromstring(_str(output_data['paged-posts']['4']['index.html']))
        self.assertEqual('html', pp.findall('.')[0].tag)
        self.assertEqual('Page 4 of 4',
                         pp.findall('./head/title')[0].text.strip())
        self.assertEqual('Page 4 of 4',
                         pp.findall('./body/h1')[0].text.strip())
        pp_els = pp.findall('./body/ul/li/a')
        pp_links = [el.attrib['href'] for el in pp_els]
        pp_link_titles = [el.text.strip() for el in pp_els]
        self.assertEqual(
            ['/2016/06/12/andrew-hello-world/'],
            pp_links,
        )
        self.assertEqual(
            ['Andrew says Hello World'],
            pp_link_titles,
        )

        self.assert_mlalchemy_complex_path_view_compiles(output_data)
        self.assert_homepage_compiles(
            self.assert_path_exists("mlalchemy/posts/index.html", output_data))
        self.assert_json_data_compiles(output_data)
        self.assert_generated_js_compiles(output_data)
Esempio n. 21
0
    def assert_homepage_compiles(self, page_content):
        # Parse the home page's XHTML content
        homepage = ET.fromstring(_str(page_content))
        self.assertEqual('html', homepage.findall('.')[0].tag)
        self.assertEqual('Welcome to the test blog', homepage.findall('./head/title')[0].text.strip())
        self.assertEqual('Home page', homepage.findall('./body/h1')[0].text.strip())
        # Test the project-wide static context variables
        self.assertEqual(
            'This is some information about the unit test web site.',
            homepage.findall("./body/div[@class='site-summary']")[0].text.strip(),
        )

        # Test the ordering of links on the homepage
        homepage_link_els = homepage.findall('./body/ul/li/a')
        homepage_links = [el.attrib['href'] for el in homepage_link_els]
        homepage_link_titles = [el.text.strip() for el in homepage_link_els]
        self.assertEqual(
            [
                '/2018/02/12/unicode-in-markdown-test/',
                '/2018/01/20/test-datetime-format/',
                '/2016/06/30/tables-test/',
                '/2016/06/25/andrew-second-post/',
                '/2016/06/18/second-post/',
                '/2016/06/15/my-first-post/',
                '/2016/06/12/andrew-hello-world/'
            ],
            homepage_links,
        )
        self.assertEqual(
            [
                'Testing Unicode θ in Markdown content (issues #50 and #63)',
                'Testing DateTime format (as per issue #59)',
                'Testing Markdown tables',
                'Andrew\'s Second Post',
                'Second post',
                'My first post',
                'Andrew says Hello World'
            ],
            homepage_link_titles,
        )

        # Test the project-wide dynamic context variables
        self.assertEqual("Andrew Michaels", homepage.findall("./body/div[@class='all-authors']/ul/li")[0].text.strip())
        self.assertEqual("John Johnson", homepage.findall("./body/div[@class='all-authors']/ul/li")[1].text.strip())
        self.assertEqual("Michael Anderson", homepage.findall("./body/div[@class='all-authors']/ul/li")[2].text.strip())
        # Test the new {% asset %} tag
        self.assertEqual("/assets/testfile.txt", homepage.findall("./body/div[@class='download']/a")[0].attrib['href'])

        # Test the Lorem Ipsum generators
        self.assertEqual(
            100,
            lipsum.count_words(homepage.findall("./body/div[@class='lorem-ipsum']/p")[0].text.strip())
        )
        self.assertEqual(
            5,
            lipsum.count_sentences(homepage.findall("./body/div[@class='lorem-ipsum']/p")[1].text.strip())
        )
        self.assertTrue(
            lipsum.count_words(homepage.findall("./body/div[@class='lorem-ipsum']/p")[2].text.strip()) > 1
        )

        # check the generated script URL - that it has no trailing slash (issue #48)
        script = homepage.find('body/script')
        self.assertIsNotNone(script)
        self.assertEqual('/scripts/generated.js', script.attrib['src'])