def test_when_publish_is_called_it_should_save_the_post_using_config_CONTENT_DIR_and_slug(): title = 'This is a title for great good' expected_filename = '{}.md'.format(core.slugify(title)) with tempfile.TemporaryDirectory() as d, \ mock.patch.dict(core.config, {'CONTENT_DIR': d}): core.publish(title=title, content='This is a post that is for the awesome', author='*****@*****.**', ) assert expected_filename in os.listdir(d)
def test_when_slug_header_is_not_provided_it_should_slugify_the_title(): title = 'This is a title of which I have 1#$%@#$98089 "Great" Proudness' expected_slug = core.slugify(title) post = core.Post(textwrap.dedent('''\ Title: {} Slugs are the sluggiest! Especially when they freelance... ''').format(title)) assert post.slug == expected_slug
def test_changing_title_should_also_change_slug(): title = 'This is a title of which I have 1#$%@#$98089 "Great" Proudness' expected_slug = core.slugify(title) post = core.Post(textwrap.dedent('''\ Title: Title of Great Good Slugs are the sluggiest! Especially when they freelance... ''').format(title)) post.title = title assert post.slug == expected_slug
def test_for_all_posts_in_content_dir_index_should_contain_those_titles(): expected_titles = ['this is some title', 'this is another title', 'blah blah blah', ] with tempfile.TemporaryDirectory() as content_dir, \ tempfile.TemporaryDirectory() as output_dir: for title in expected_titles: with open(os.path.join(content_dir, core.slugify(title)+'.md'), 'w') as f: print('Title: {}\n\nThis is a *blog* post'.format(title), file=f) core.generate_index(content_dir=content_dir, output_dir=output_dir) with open(os.path.join(output_dir, 'index.html')) as f: text = f.read() for title in expected_titles: assert title in text
def test_slugify_should_lowercase_text_and_convert_all_non_alphanumerics_to_one_hyphen(): text = 'This is \t___---+++123456789!@#$%^&*()\'""\' some title' expected_text = 'this-is-123456789-some-title' assert core.slugify(text) == expected_text