def test_wordpress_without_doc_config_file(): with wrap() as wrapper: wrapper.debug = False doc = Doc("hello.txt|wp", contents="hello, this is a blog post", wrapper=wrapper) wrapper.run_docs(doc) assert wrapper.state == 'error'
def test_wordpress_without_doc_config_file(): with wrap() as wrapper: wrapper.debug = False doc = Doc("hello.txt|wp", contents = "hello, this is a blog post", wrapper=wrapper ) wrapper.run_docs(doc) assert wrapper.state == 'error'
def test_wordpress(MockXmlrpclib): with wrap(): with open("wordpress.json", "wb") as f: json.dump({}, f) with open(".dexyapis", "wb") as f: json.dump({ 'wordpress' : { 'url' : 'http://example.com', 'username' : 'foo', 'password' : 'bar' }}, f) # Create new (unpublished) draft wrapper = dexy.wrapper.Wrapper() doc = mk_wp_doc(wrapper) wrapper.run_docs(doc) with open("wordpress.json", "rb") as f: result = json.load(f) assert result['postid'] == 42 assert result['publish'] == False # Update existing draft wrapper = dexy.wrapper.Wrapper() doc = mk_wp_doc(wrapper) wrapper.run_docs(doc) assert doc.output_data().json_as_dict().keys() == ['permaLink'] result['publish'] = True with open("wordpress.json", "wb") as f: json.dump(result, f) # Publish existing draft wrapper = dexy.wrapper.Wrapper() doc = mk_wp_doc(wrapper) wrapper.run_docs(doc) assert "http://example.com/blog/42" in str(doc.output_data()) # Now, separately, test an image upload. orig = os.path.join(TEST_DATA_DIR, 'color-graph.pdf') shutil.copyfile(orig, 'example.pdf') from dexy.wrapper import Wrapper wrapper = Wrapper() doc = Doc("example.pdf|wp", wrapper=wrapper) with open(".dexyapis", "wb") as f: json.dump({ 'wordpress' : { 'url' : 'http://example.com', 'username' : 'foo', 'password' : 'bar' }}, f) wrapper.run_docs(doc) assert doc.output_data().as_text() == "http://example.com/example.pdf" # test list categories with capture_stdout() as stdout: dexy.filter.Filter.create_instance("wp").docmd_list_categories() assert stdout.getvalue() == "categoryName\nfoo\nbar\n"
def test_wordpress(MockXmlrpclib): with wrap(): with open("wordpress.json", "wb") as f: json.dump({}, f) with open(".dexyapis", "wb") as f: json.dump( { 'wordpress': { 'url': 'http://example.com', 'username': '******', 'password': '******' } }, f) # Create new (unpublished) draft wrapper = dexy.wrapper.Wrapper() doc = mk_wp_doc(wrapper) wrapper.run_docs(doc) with open("wordpress.json", "rb") as f: result = json.load(f) assert result['postid'] == 42 assert result['publish'] == False # Update existing draft wrapper = dexy.wrapper.Wrapper() doc = mk_wp_doc(wrapper) wrapper.run_docs(doc) assert doc.output_data().json_as_dict().keys() == ['permaLink'] result['publish'] = True with open("wordpress.json", "wb") as f: json.dump(result, f) # Publish existing draft wrapper = dexy.wrapper.Wrapper() doc = mk_wp_doc(wrapper) wrapper.run_docs(doc) assert "http://example.com/blog/42" in str(doc.output_data()) # Now, separately, test an image upload. orig = os.path.join(TEST_DATA_DIR, 'color-graph.pdf') shutil.copyfile(orig, 'example.pdf') from dexy.wrapper import Wrapper wrapper = Wrapper() doc = Doc("example.pdf|wp", wrapper=wrapper) with open(".dexyapis", "wb") as f: json.dump( { 'wordpress': { 'url': 'http://example.com', 'username': '******', 'password': '******' } }, f) wrapper.run_docs(doc) assert doc.output_data().as_text() == "http://example.com/example.pdf" # test list categories with capture_stdout() as stdout: dexy.filter.Filter.create_instance("wp").docmd_list_categories() assert stdout.getvalue() == "categoryName\nfoo\nbar\n"