Exemplo n.º 1
0
def test_publish_should_call_generate_atom_feed():
    with mock.patch('slipstream.core.generate_atom') as fake_gen_atom:
        core.publish(title='blargle',
                     content='This is a post that is for the awesome',
                     author='*****@*****.**',
                     # No tags here...
                     )
        assert fake_gen_atom.call_count == 1
Exemplo n.º 2
0
def test_if_post_is_not_tagged_then_publish_should_not_call_generate_tag_page():
    with mock.patch('slipstream.core.generate_tag_page') as fake_gen_tag_pages:
        core.publish(title='blargle',
                     content='This is a post that is for the awesome',
                     author='*****@*****.**',
                     # No tags here...
                     )
        assert fake_gen_tag_pages.call_count == 0
Exemplo n.º 3
0
def test_if_publish_webhook_is_not_truthy_webhook_should_not_be_called():
    with mock.patch('slipstream.core.publish_webhook') as fake_publish_webhook,\
            mock.patch.dict(core.config, {'PUBLISH_WEBHOOK': None}):
        core.publish(title='blargle',
                     content='This is a post that is for the awesome',
                     author='*****@*****.**',
                     # No tags here...
                     )
        assert fake_publish_webhook.call_count == 0
Exemplo n.º 4
0
def test_if_publish_webhook_is_set_then_publish_should_pass_new_post_to_call_webhook():
    with mock.patch('slipstream.core.publish_webhook') as fake_publish_webhook,\
            mock.patch.dict(core.config, {'PUBLISH_WEBHOOK': 'http://example.com'}):
        core.publish(title='blargle',
                     content='This is a post that is for the awesome',
                     author='*****@*****.**',
                     # No tags here...
                     )
        assert fake_publish_webhook.call_count == 1
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
def test_publish_should_call_generate_index_and_pass_it_config_OUTPUT_DIR_and_CONTENT_DIR():
    with tempfile.TemporaryDirectory() as output_dir, \
            tempfile.TemporaryDirectory() as content_dir, \
            mock.patch.dict(core.config, {'OUTPUT_DIR': output_dir,
                                          'CONTENT_DIR': content_dir}):
        with mock.patch('slipstream.core.generate_index') as fake_gen_index:
            core.publish(title='blargle',
                         content='This is a post that is for the awesome',
                         author='*****@*****.**',
                        )
            fake_gen_index.assert_called_with(content_dir=content_dir,
                                              output_dir=output_dir)
Exemplo n.º 7
0
def test_publish_should_call_generate_tag_page_and_pass_it_each_tag_and_OUTPUT_DIR():
    with tempfile.TemporaryDirectory() as output_dir, \
            tempfile.TemporaryDirectory() as content_dir, \
            mock.patch.dict(core.config, {'OUTPUT_DIR': output_dir,
                                          'CONTENT_DIR': content_dir}):
        with mock.patch('slipstream.core.generate_tag_page') as fake_gen_tag_pages:
            expected_tags = [tag.strip()
                             for tag in 'these, are, my tags'.split(',')
                             ]
            core.publish(title='blargle',
                         content='This is a post that is for the awesome',
                         author='*****@*****.**',
                         tags=','.join(expected_tags),
                        )
            for tag in expected_tags:
                fake_gen_tag_pages.assert_any_call(tag=tag,
                                                   content_dir=content_dir,
                                                   output_dir=output_dir)
Exemplo n.º 8
0
def test_when_publish_is_called_post_values_should_be_generated_from_saved_file():
    post_one = core.Post(textwrap.dedent('''\
                                         Title: This post has all the headers
                                         Date: 1982-06-25
                                         Updated: 2010-08-14
                                         Slug: this-is-slugtastic
                                         TaGs: do,  you, have,some,tags?
                                         AuThOr: [email protected]

                                         This is a post, that's cool because
                                         <br> it has some html and

                                         - stuff
                                         - like markdown features
                                         - [so awesome](http://asdf.com)
                                         '''))
    attrs = ('title', 'raw_content', 'publish_timestamp', 'update_timestamp',
             'author', 'tags')

    with tempfile.TemporaryDirectory() as d, \
            mock.patch.dict(core.config, {'CONTENT_DIR': d}):

        core.publish(title=post_one.title,
                     content=post_one.raw_content,
                     author=post_one.author,
                     slug=post_one.slug,
                     tags=','.join(post_one.tags),
                    )
        print(os.listdir(d))
        with open(os.path.join(d, post_one.slug+'.md')) as f:
            text = f.read()
            print(text)
            post_two = core.Post(text)

    for attr in attrs:
        assert getattr(post_one, attr) == getattr(post_one, attr)