Exemplo n.º 1
0
    def test_explicit_draft(self):
        """.from_file raises DraftError given a file with 'draft' in meta

        'draft' should appear (without quotes) on a line by itself
        """
        with self.assertRaises(majestic.DraftError):
            Post.from_file(
                file=self.posts_path.joinpath('test_explicit_draft.md'),
                settings=self.settings)
Exemplo n.º 2
0
    def test_parse_known_good_slug(self):
        """.from_file does not normalise known good slug"""
        known_good_file = self.posts_path.joinpath('test_good_slug.md')
        known_good_slug = 'valid%20slug'

        post = Post.from_file(known_good_file, settings=self.settings)
        self.assertTrue(post.slug, known_good_slug)
Exemplo n.º 3
0
    def test_parse_known_bad_slug(self):
        """.from_file detects and normalises invalid slugs

        When given a file containing an invalid value for the slug,
        .from_file should return a content object where the slug
        has been normalised.
        """
        known_bad_file = self.posts_path.joinpath('test_invalid_slug.md')
        good_chars = set(string.ascii_lowercase + string.digits + '-')

        post = Post.from_file(known_bad_file, settings=self.settings)
        self.assertLess(set(post.slug), good_chars)  # Subset test
Exemplo n.º 4
0
    def test_posts_general(self):
        """Posts returned with file's contents correctly stored

        This test tests the five liberation day posts, starting:
            1917-11-07
            1949-10-01
            1959-01-01
            1975-04-30
            1979-07-19

        The parsing rules should differentiate between the metadata and
        body. The metadata is all the lines between the start of the file
        and a blank line. The body is everything following the blank line.

        Of the metadata in the header, the title, slug and date should
        be available as attributes. The date should be a datetime object
        corresponding to the textual date in the metadata header.

        All other metadata should be available in a dictionary stored
        on the post as the meta attribute. The keys in that dictionary
        should be lower-case and stripped of leading and trailing
        whitespace. The values should be stripped only.

        The body should be stripped of leading and trailing newlines only.
        """
        date_format = self.settings['dates']['format']

        for file in self.lib_posts:
            with file.open() as f:
                meta, body = f.read().split('\n\n', maxsplit=1)
            meta = [line.split(':', maxsplit=1) for line in meta.splitlines()]
            meta = {key.lower().strip(): value.strip() for key, value in meta}

            file_dict = meta
            file_dict['body'] = body.strip('\n')
            file_dict['source_path'] = file

            post = Post.from_file(file, settings=self.settings)
            post_dict = post.meta.copy()
            post_dict['title'] = post.title
            post_dict['slug'] = post.slug
            post_dict['date'] = post.date.strftime(date_format)
            post_dict['body'] = post.body
            post_dict['source_path'] = post.source_path

            self.assertEqual(file_dict, post_dict)
Exemplo n.º 5
0
 def test_parse_bad_percent_encoding(self):
     """.from_file normalises slugs containing invalid percent encoding"""
     bad_percent_file = self.posts_path.joinpath('test_bad_percent.md')
     bad_percent_slug = 'this-is-not-100%-valid'
     post = Post.from_file(bad_percent_file, settings=self.settings)
     self.assertNotEqual(post.slug, bad_percent_slug)