-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Why is this change needed? -------------------------- Just checking to make sure one of the new options works as expected. How does it address the issue? ------------------------------ Add tests for iframes option. Any links to any relevant tickets, articles, or other resources? --------------------------------------------------------------- https://3.basecamp.com/3093825/buckets/29007795/todos/6362751178 Did you complete all of the following? -------------------------------------- - Run test suite? - Add new tests? - Consider security implications and practices?
- Loading branch information
1 parent
c7efba8
commit 6fb6401
Showing
4 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ cd "$(dirname "$0")/../.." | |
|
||
cd test | ||
|
||
apk add qpdf | ||
apk add qpdf poppler-utils | ||
|
||
pip install --upgrade ../ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import docraptor | ||
import os | ||
import platform | ||
import re | ||
|
||
doc_api = docraptor.DocApi() | ||
doc_api.api_client.configuration.username = 'YOUR_API_KEY_HERE' | ||
# doc_api.api_client.configuration.debug = True | ||
|
||
pdf_data = doc_api.create_doc({ | ||
"test": True, | ||
"document_content": """ | ||
<html><body> | ||
<p>Baseline text</p> | ||
<iframe src="https://docraptor-test-harness.herokuapp.com/public/index.html"></iframe> | ||
</body></html> | ||
""", | ||
"name": "python-sync.pdf", | ||
"document_type": "pdf", | ||
# "prince_options": { | ||
# "iframes": True, | ||
# }, | ||
}) | ||
|
||
file_path = "/app/tmp/test_output/" + os.path.basename(__file__) + "_python_" + platform.python_version() + ".pdf" | ||
|
||
with open(file_path, "wb") as f: | ||
f.write(pdf_data) | ||
|
||
stream = os.popen("qpdf --check " + file_path + " 2>&1") | ||
output = stream.read() | ||
close_value = stream.close() | ||
if close_value is not None: | ||
with open(file_path, "rb") as f: | ||
decoded_response = f.read().decode('cp437') | ||
message = "Invalid PDF expected: %PDF-1.5 recieved:\n" | ||
message += decoded_response[0:8] | ||
message += "\n\nqpdf --check:\n" + output | ||
raise ValueError(message) | ||
|
||
stream = os.popen("pdftotext " + file_path + " -") | ||
output = stream.read() | ||
if re.search("Test", output) is None: | ||
raise ValueError("Output should load iframe") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import docraptor | ||
import os | ||
import platform | ||
import re | ||
|
||
doc_api = docraptor.DocApi() | ||
doc_api.api_client.configuration.username = 'YOUR_API_KEY_HERE' | ||
# doc_api.api_client.configuration.debug = True | ||
|
||
pdf_data = doc_api.create_doc({ | ||
"test": True, | ||
"document_content": """ | ||
<html><body> | ||
<p>Baseline text</p> | ||
<iframe src="https://docraptor-test-harness.herokuapp.com/public/index.html"></iframe> | ||
</body></html> | ||
""", | ||
"name": "python-sync.pdf", | ||
"document_type": "pdf", | ||
"prince_options": { | ||
"iframes": False, | ||
}, | ||
}) | ||
|
||
file_path = "/app/tmp/test_output/" + os.path.basename(__file__) + "_python_" + platform.python_version() + ".pdf" | ||
|
||
with open(file_path, "wb") as f: | ||
f.write(pdf_data) | ||
|
||
stream = os.popen("qpdf --check " + file_path + " 2>&1") | ||
output = stream.read() | ||
close_value = stream.close() | ||
if close_value is not None: | ||
with open(file_path, "rb") as f: | ||
decoded_response = f.read().decode('cp437') | ||
message = "Invalid PDF expected: %PDF-1.5 recieved:\n" | ||
message += decoded_response[0:8] | ||
message += "\n\nqpdf --check:\n" + output | ||
raise ValueError(message) | ||
|
||
stream = os.popen("pdftotext " + file_path + " -") | ||
output = stream.read() | ||
if re.search("Test", output) is not None: | ||
raise ValueError("Output shouldn't load iframe") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import docraptor | ||
import os | ||
import platform | ||
import re | ||
|
||
doc_api = docraptor.DocApi() | ||
doc_api.api_client.configuration.username = 'YOUR_API_KEY_HERE' | ||
# doc_api.api_client.configuration.debug = True | ||
|
||
pdf_data = doc_api.create_doc({ | ||
"test": True, | ||
"document_content": """ | ||
<html><body> | ||
<p>Baseline text</p> | ||
<iframe src="https://docraptor-test-harness.herokuapp.com/public/index.html"></iframe> | ||
</body></html> | ||
""", | ||
"name": "python-sync.pdf", | ||
"document_type": "pdf", | ||
"prince_options": { | ||
"iframes": True, | ||
}, | ||
}) | ||
|
||
file_path = "/app/tmp/test_output/" + os.path.basename(__file__) + "_python_" + platform.python_version() + ".pdf" | ||
|
||
with open(file_path, "wb") as f: | ||
f.write(pdf_data) | ||
|
||
stream = os.popen("qpdf --check " + file_path + " 2>&1") | ||
output = stream.read() | ||
close_value = stream.close() | ||
if close_value is not None: | ||
with open(file_path, "rb") as f: | ||
decoded_response = f.read().decode('cp437') | ||
message = "Invalid PDF expected: %PDF-1.5 recieved:\n" | ||
message += decoded_response[0:8] | ||
message += "\n\nqpdf --check:\n" + output | ||
raise ValueError(message) | ||
|
||
stream = os.popen("pdftotext " + file_path + " -") | ||
output = stream.read() | ||
if re.search("Test", output) is None: | ||
raise ValueError("Output should load iframe") |