Exemplo n.º 1
0
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]")
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
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)
Exemplo n.º 5
0
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
        )
Exemplo n.º 6
0
 def test_api_keys(self):
     docraptor = DocRaptor()
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 def test_invalid_download_raises(self):
     stub_http_response_with("invalid_download", "get", 400)
     resp = DocRaptor(self.test_key).download("test-id", True)
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 def test_bogus_arguments_none(self):
     DocRaptor(self.test_key).create(None)
Exemplo n.º 11
0
 def test_param_api_keys(self):
     docraptor = DocRaptor(self.test_key)
     assert docraptor.api_key == self.test_key
Exemplo n.º 12
0
 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
Exemplo n.º 13
0
 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})
Exemplo n.º 14
0
 def test_bogus_arguments_None(self):
     DocRaptor(self.test_key).list_docs(None)
Exemplo n.º 15
0
 def test_bogus_arguments_bool(self):
     DocRaptor(self.test_key).list_docs(True)
Exemplo n.º 16
0
 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
Exemplo n.º 17
0
 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}
     )
Exemplo n.º 18
0
 def test_env_api_key(self):
     os.environ["DOCRAPTOR_API_KEY"] = self.test_key
     docraptor = DocRaptor()
     assert docraptor.api_key == self.test_key
Exemplo n.º 19
0
    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
Exemplo n.º 20
0
 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
Exemplo n.º 21
0
 def test_bogus_arguments_bool(self):
     DocRaptor(self.test_key).create(True)
Exemplo n.º 22
0
 def test_invalid_status_raises(self):
     stub_http_response_with("invalid_status", "get", 400)
     resp = DocRaptor(self.test_key).status("test-id", True)
Exemplo n.º 23
0
 def test_no_content_empty(self):
     DocRaptor(self.test_key).create({})
Exemplo n.º 24
0
 def test_blank_url(self):
     DocRaptor(self.test_key).create({"url": ""})
Exemplo n.º 25
0
 def test_blank_content(self):
     DocRaptor(self.test_key).create({"content": ""})
Exemplo n.º 26
0
 def test_timeout(self):
     os.environ["DOCRAPTOR_TIMEOUT"] = "0.0001"
     resp = DocRaptor(self.test_key).create(
         {"document_content": "<html><body>Hey</body></html>"}
     )
Exemplo n.º 27
0
 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
Exemplo n.º 28
0
 def test_no_content_attr(self):
     DocRaptor(self.test_key).create({"herped": "the_derp"})