-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render entire PDFs instead of single pages #840
Merged
Merged
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
b7d9678
Adding anchors
pamelafox 99ea466
Merge branch 'main' of https://github.com/pamelafox/azure-search-open…
pamelafox a3c0023
Merge branch 'main' of https://github.com/pamelafox/azure-search-open…
pamelafox cd2706c
Merge branch 'main' of https://github.com/pamelafox/azure-search-open…
pamelafox 6910e05
Merge branch 'main' of https://github.com/pamelafox/azure-search-open…
pamelafox f63398a
Merge branch 'main' of https://github.com/pamelafox/azure-search-open…
pamelafox eaef837
Merge branch 'main' of https://github.com/pamelafox/azure-search-open…
pamelafox 3c4fe71
Show whole file
pamelafox 60e07cc
Show whole file
pamelafox cf46813
Merge branch 'main' of https://github.com/pamelafox/azure-search-open…
pamelafox 5e745a9
Merge branch 'main' of https://github.com/pamelafox/azure-search-open…
pamelafox 1bec0b3
Merge branch 'main' of https://github.com/pamelafox/azure-search-open…
pamelafox f8f300f
Page number support
pamelafox 820e4b6
Merge branch 'main' into wholefile
pamelafox 4395e39
More experiments with whole file
pamelafox e0b036b
Merge branch 'main' into wholefile
pamelafox 9d138a3
Revert unintentional changes
pamelafox 47f9a17
Add tests
pamelafox 786e5eb
Remove random num
pamelafox 4d62561
Add retry_total=0 to avoid unnecessary network requests
pamelafox 0de7037
Add comment to explain retry_total
pamelafox ee51b9e
Merge branch 'main' into wholefile
pamelafox ae1d95f
Bring back deleted file
pamelafox 78448e9
Merge branch 'wholefile' of https://github.com/pamelafox/azure-search…
pamelafox f1cd17a
Merge branch 'main' into wholefile
pamelafox d4d9db0
Blob manager refactor after merge
pamelafox 23e6aba
Update coverage amount
pamelafox 3acccb8
Make mypy happy with explicit check of path
pamelafox 17fd596
Add debug for 3.9
pamelafox 5f11ce6
Skip in 3.9 since its silly
pamelafox b8202fd
Reduce fail under percentage due to 3.9
pamelafox de97cff
Merge branch 'main' into wholefile
pamelafox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
pamelafox marked this conversation as resolved.
Show resolved
Hide resolved
|
Binary file not shown.
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
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
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,99 @@ | ||
import os | ||
from collections import namedtuple | ||
|
||
import aiohttp | ||
import pytest | ||
from azure.core.exceptions import ResourceNotFoundError | ||
from azure.core.pipeline.transport import ( | ||
AioHttpTransportResponse, | ||
AsyncHttpTransport, | ||
HttpRequest, | ||
) | ||
from azure.storage.blob.aio import BlobServiceClient | ||
|
||
import app | ||
|
||
MockToken = namedtuple("MockToken", ["token", "expires_on"]) | ||
|
||
|
||
class MockAzureCredential: | ||
async def get_token(self, uri): | ||
return MockToken("mock_token", 9999999999) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_content_file(monkeypatch, mock_env): | ||
class MockAiohttpClientResponse404(aiohttp.ClientResponse): | ||
def __init__(self, url, body_bytes, headers=None): | ||
self._body = body_bytes | ||
self._headers = headers | ||
self._cache = {} | ||
self.status = 404 | ||
self.reason = "Not Found" | ||
self._url = url | ||
|
||
class MockAiohttpClientResponse(aiohttp.ClientResponse): | ||
def __init__(self, url, body_bytes, headers=None): | ||
self._body = body_bytes | ||
self._headers = headers | ||
self._cache = {} | ||
self.status = 200 | ||
self.reason = "OK" | ||
self._url = url | ||
|
||
class MockTransport(AsyncHttpTransport): | ||
async def send(self, request: HttpRequest, **kwargs) -> AioHttpTransportResponse: | ||
if request.url.endswith("notfound.pdf"): | ||
raise ResourceNotFoundError(MockAiohttpClientResponse404(request.url, b"")) | ||
else: | ||
return AioHttpTransportResponse( | ||
request, | ||
MockAiohttpClientResponse( | ||
request.url, | ||
b"test content", | ||
{ | ||
"Content-Type": "application/octet-stream", | ||
"Content-Range": "bytes 0-27/28", | ||
"Content-Length": "28", | ||
}, | ||
), | ||
) | ||
|
||
async def __aenter__(self): | ||
return self | ||
|
||
async def __aexit__(self, *args): | ||
pass | ||
|
||
async def open(self): | ||
pass | ||
|
||
async def close(self): | ||
pass | ||
|
||
# Then we can plug this into any SDK via kwargs: | ||
blob_client = BlobServiceClient( | ||
f"https://{os.environ['AZURE_STORAGE_ACCOUNT']}.blob.core.windows.net", | ||
credential=MockAzureCredential(), | ||
transport=MockTransport(), | ||
retry_total=0, # Necessary to avoid unnecessary network requests during tests | ||
) | ||
blob_container_client = blob_client.get_container_client(os.environ["AZURE_STORAGE_CONTAINER"]) | ||
|
||
quart_app = app.create_app() | ||
async with quart_app.test_app() as test_app: | ||
quart_app.config.update({"blob_container_client": blob_container_client}) | ||
|
||
client = test_app.test_client() | ||
response = await client.get("/content/notfound.pdf") | ||
assert response.status_code == 404 | ||
|
||
response = await client.get("/content/role_library.pdf") | ||
assert response.status_code == 200 | ||
assert response.headers["Content-Type"] == "application/pdf" | ||
assert await response.get_data() == b"test content" | ||
|
||
response = await client.get("/content/role_library.pdf#page=10") | ||
assert response.status_code == 200 | ||
assert response.headers["Content-Type"] == "application/pdf" | ||
assert await response.get_data() == b"test content" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this will still work with folks who didn't re-run prepdocs after this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! I just did another manual test to make sure, its working with an old env with individual pages.