def test_show_block_with_env_var():
    b = bbase.BaseBlock()

    mock_url = "http://imgur.com/gallery/YLvFFS5/"

    with patch.dict(config.user_config, {"tmp_html_dir": mock_url, "id_precision": 10}, clear=True) as _, \
            patch("webbrowser.open_new_tab") as tab, \
            patch.object(b, "publish") as pub:
        pub.return_value = "dummy"

        b.show()

        tab.assert_called_with('dummy')
Exemple #2
0
def test_publish_block():
    b = bbase.BaseBlock()

    publish_name = "subdir/filename.html"

    with patch("os.makedirs") as md, patch.object(b, "save") as save:
        b.publish(publish_name)

        expected_path = os.path.expanduser(os.path.join(config.user_config['public_dir'], publish_name))
        expected_dir = os.path.dirname(expected_path)

        md.assert_called_with(expected_dir)
        save.assert_called_with(expected_path)
Exemple #3
0
def test_save_filename_and_extension(filename, fmt, exp_name, exp_fmt, exp_output):
    m = mock_open()
    with patch('pybloqs.block.base.open', m, create=True):
        with patch.object(bbase.BaseBlock, 'render_html', return_value='<HTML>'):
            with patch.object(bbase.BaseBlock, 'publish', return_value=''):
                with patch('pybloqs.block.base.htmlconv') as mock_conv:
                    b = bbase.BaseBlock()
                    result = b.save(filename, fmt)
    if exp_name is not None:
        assert result == exp_name
    if exp_fmt is not None:
        assert result.split('.')[-1] == exp_fmt
    if exp_output is not None:
        assert m().write.called_once_with(exp_output)
def test_publish_pass_through_extra_params():
    b = bbase.BaseBlock()

    with patch("os.makedirs"), patch.object(b, "save") as save:
        b.publish("filename.html", 1, 2, named_arg="dummy")
        save.assert_called_with(ANY, 1, 2, named_arg="dummy")