def main(): """Generate a PDF using the async method.""" docraptor = DocRaptor() print("Create PDF") resp = docraptor.create({ "document_content": "<h1>python-docraptor</h1><p>Async Test</p>", "test": True, "async": True, }) print("Status ID: {status_id}".format(status_id=resp["status_id"])) status_id = resp["status_id"] resp = docraptor.status(status_id) print(" {status}".format(status=resp["status"])) while resp["status"] != "completed": time.sleep(3) resp = docraptor.status(status_id) print(" {status}".format(status=resp["status"])) print("Download to test_async.pdf") with open("test_async.pdf", "wb") as pdf_file: pdf_file.write(docraptor.download(resp["download_key"]).content) print("[DONE]")
def test_status(self): stub_http_response_with("simple_status", "get") app = DocRaptor(self.test_key) resp = app.status("test-id") assert "completed" == resp["status"] key = app._get_download_key(resp["download_url"]) assert "ffffffffffd74b4a993fcae917699ed7" == key
def main(): """Generate a PDF with specified url.""" docraptor = DocRaptor() print("Create test_basic_url.pdf") with open("test_basic_url.pdf", "wb") as pdf_file: pdf_file.write( docraptor.create({ "document_url": "http://docraptor.com", "test": True }).content)
def main(): """Generate a PDF with specified content.""" docraptor = DocRaptor() print("Create test_basic_content.pdf") with open("test_basic_content.pdf", "wb") as pdf_file: pdf_file.write( docraptor.create({ "document_content": "<h1>python-docraptor</h1><p>Basic Test</p>", "test": True, }).content)
def main(): """Generate an XLS with specified content.""" table = """<table> <thead> <tr><th>First Name</th><th>Last Name</th></tr> </thead> <tbody> <tr><td>Paul</td><td>McGrath</td></tr> <tr><td>Liam</td><td>Brady</td></tr> <tr><td>John</td><td>Giles</td></tr> </tbody> </table>""" docraptor = DocRaptor() print("Create test_basic.xls") with open("test_basic.xls", "wb") as pdf_file: pdf_file.write( docraptor.create( {"document_content": table, "document_type": "xls", "test": True} ).content )
def test_api_keys(self): docraptor = DocRaptor()
def test_download(self): stub_http_response_with("simple_download", "get") resp = DocRaptor(self.test_key).download("test-id") assert FIXTURES["simple_download"] == resp.content
def test_invalid_download_raises(self): stub_http_response_with("invalid_download", "get", 400) resp = DocRaptor(self.test_key).download("test-id", True)
def test_create_with_invalid_content(self): invalid_html = "<herp" stub_http_response_with("invalid_pdf", "post", 422) resp = DocRaptor(self.test_key).create({"document_content": invalid_html}) assert FIXTURES["invalid_pdf"] == resp.content assert 422 == resp.status_code
def test_bogus_arguments_none(self): DocRaptor(self.test_key).create(None)
def test_param_api_keys(self): docraptor = DocRaptor(self.test_key) assert docraptor.api_key == self.test_key
def test_list_docs(self): stub_http_response_with("simple_list_docs", "get") resp = DocRaptor(self.test_key).list_docs({}) assert FIXTURES["simple_list_docs"] == resp.content
def test_invalid_list_docs_raises(self): stub_http_response_with("invalid_list_docs", "get", 400) resp = DocRaptor(self.test_key).list_docs({"raise_exception_on_failure": True})
def test_bogus_arguments_None(self): DocRaptor(self.test_key).list_docs(None)
def test_bogus_arguments_bool(self): DocRaptor(self.test_key).list_docs(True)
def test_create_with_valid_content(self): stub_http_response_with("simple_pdf", "post") resp = DocRaptor(self.test_key).create({"document_content": self.html_content}) assert FIXTURES["simple_pdf"] == resp.content assert 200 == resp.status_code
def test_create_with_invalid_content_raises(self): invalid_html = "<herp" stub_http_response_with("invalid_pdf", "post", 422) resp = DocRaptor(self.test_key).create( {"document_content": invalid_html, "raise_exception_on_failure": True} )
def test_env_api_key(self): os.environ["DOCRAPTOR_API_KEY"] = self.test_key docraptor = DocRaptor() assert docraptor.api_key == self.test_key
def test_no_overwrite_env_api_key(self): os.environ["DOCRAPTOR_API_KEY"] = self.test_key docraptor = DocRaptor() os.environ["DOCRAPTOR_API_KEY"] = "blah" assert docraptor.api_key == self.test_key
def test_invalid_status(self): stub_http_response_with("invalid_status", "get", 403) resp = DocRaptor(self.test_key).status("test-id") assert FIXTURES["invalid_status"] == resp.content assert 403 == resp.status_code
def test_bogus_arguments_bool(self): DocRaptor(self.test_key).create(True)
def test_invalid_status_raises(self): stub_http_response_with("invalid_status", "get", 400) resp = DocRaptor(self.test_key).status("test-id", True)
def test_no_content_empty(self): DocRaptor(self.test_key).create({})
def test_blank_url(self): DocRaptor(self.test_key).create({"url": ""})
def test_blank_content(self): DocRaptor(self.test_key).create({"content": ""})
def test_timeout(self): os.environ["DOCRAPTOR_TIMEOUT"] = "0.0001" resp = DocRaptor(self.test_key).create( {"document_content": "<html><body>Hey</body></html>"} )
def test_invalid_download(self): stub_http_response_with("invalid_download", "get", 400) resp = DocRaptor(self.test_key).download("test-id") assert FIXTURES["invalid_download"] == resp.content assert 400 == resp.status_code
def test_no_content_attr(self): DocRaptor(self.test_key).create({"herped": "the_derp"})