Пример #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]")
Пример #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
Пример #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)
Пример #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
        )
Пример #6
0
 def test_api_keys(self):
     docraptor = DocRaptor()
Пример #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
Пример #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)
Пример #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
Пример #10
0
 def test_bogus_arguments_none(self):
     DocRaptor(self.test_key).create(None)
Пример #11
0
 def test_param_api_keys(self):
     docraptor = DocRaptor(self.test_key)
     assert docraptor.api_key == self.test_key
Пример #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
Пример #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})
Пример #14
0
 def test_bogus_arguments_None(self):
     DocRaptor(self.test_key).list_docs(None)
Пример #15
0
 def test_bogus_arguments_bool(self):
     DocRaptor(self.test_key).list_docs(True)
Пример #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
Пример #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}
     )
Пример #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
Пример #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
Пример #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
Пример #21
0
 def test_bogus_arguments_bool(self):
     DocRaptor(self.test_key).create(True)
Пример #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)
Пример #23
0
 def test_no_content_empty(self):
     DocRaptor(self.test_key).create({})
Пример #24
0
 def test_blank_url(self):
     DocRaptor(self.test_key).create({"url": ""})
Пример #25
0
 def test_blank_content(self):
     DocRaptor(self.test_key).create({"content": ""})
Пример #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>"}
     )
Пример #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
Пример #28
0
 def test_no_content_attr(self):
     DocRaptor(self.test_key).create({"herped": "the_derp"})