def setUp(self): self.factory = OTreeRequestFactory(view_name=self.view_name) self.request = self.factory.get('/my-page/') with capture_stdout(): call_command('create_session', 'simple_game', "1") self.participant = Participant.objects.first() self.player = Player.objects.first()
def test_parse_doc_configs_no_configs(): with tempdir(): with capture_stdout() as stdout: wrapper = Wrapper() wrapper.create_dexy_dirs() wrapper = Wrapper() wrapper.to_valid() wrapper.to_walked() value = stdout.getvalue() assert "didn't find any document config files" in value
def test_move_cache_dir(): with capture_stdout() as stdout: with tempdir(): os.mkdir(".cache") with open(".cache/.dexy-generated", 'w') as f: f.write("") wrapper = Wrapper() wrapper.assert_dexy_dirs_exist() assert "Moving directory '.cache'" in stdout.getvalue() assert not os.path.exists(".cache") assert os.path.exists(".dexy")
def test_old_cache_dir_with_settings(): with capture_stdout() as stdout: with tempdir(): os.mkdir(".cache") with open(".cache/.dexy-generated", 'w') as f: f.write("") wrapper = Wrapper(artifacts_dir = ".cache") wrapper.assert_dexy_dirs_exist() assert os.path.exists(".cache") assert not os.path.exists(".dexy") assert "You may have a dexy.conf file" in stdout.getvalue()
def test_old_cache_dir_with_settings(): with capture_stdout() as stdout: with tempdir(): os.mkdir(".cache") with open(".cache/.dexy-generated", 'w') as f: f.write("") wrapper = Wrapper(artifacts_dir=".cache") wrapper.assert_dexy_dirs_exist() assert os.path.exists(".cache") assert not os.path.exists(".dexy") assert "You may have a dexy.conf file" in stdout.getvalue()
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"