-
Notifications
You must be signed in to change notification settings - Fork 15
Fix 'api/' endpoint auto-fix of file transfers #360
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
Closed
BigRoy
wants to merge
1
commit into
bugfix/download-resume-integrity
from
bugfix/transfer-api-prefix-autofix
Closed
Changes from all commits
Commits
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 hidden or 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 hidden or 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,53 @@ | ||
| """Auto-fix of missing 'api/' in transfer endpoints. | ||
|
|
||
| Does not require running AYON server. | ||
| """ | ||
| import io | ||
|
|
||
| import pytest | ||
|
|
||
| from ayon_api.server_api import ServerAPI | ||
| from ayon_api.utils import RequestTypes, TransferProgress | ||
|
|
||
| from .fake_transfer import FakeResponse | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def con(monkeypatch): | ||
| monkeypatch.setattr("time.sleep", lambda *args, **kwargs: None) | ||
| return ServerAPI("http://localhost:0", create_session=False, max_retries=1) | ||
|
|
||
|
|
||
| def test_download_frontend_page_uses_api_url(con): | ||
| urls = [] | ||
|
|
||
| def get_func(url, **kwargs): | ||
| urls.append(url) | ||
| if "/api/" not in url: | ||
| # Web frontend serves 'index.html' for unknown urls | ||
| return FakeResponse(200, b"<html>", {"Content-Type": "text/html"}) | ||
| return FakeResponse(200, b"PNG", {"Content-Length": "3"}) | ||
|
|
||
| con._base_functions_mapping[RequestTypes.get] = get_func | ||
| stream = io.BytesIO() | ||
| con.download_file_to_stream("projects/p/thumbnails/1", stream) | ||
|
|
||
| assert stream.getvalue() == b"PNG" | ||
| assert urls[-1] == "http://localhost:0/api/projects/p/thumbnails/1" | ||
|
|
||
|
|
||
| def test_upload_autofix_with_single_attempt_and_progress(con): | ||
| def put_func(url, data=None, **kwargs): | ||
| list(data) | ||
| if "/api/" not in url: | ||
| return FakeResponse(404) | ||
| return FakeResponse(200) | ||
|
|
||
| con._base_functions_mapping[RequestTypes.put] = put_func | ||
| progress = TransferProgress() | ||
| response = con.upload_file_from_stream( | ||
| "upload", io.BytesIO(b"0123456789"), progress | ||
| ) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert progress.transferred_size == 10 |
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.
For me the question is if this is wrong? It has been changed so long ago that anyone using it without the
api/probably already did fix it. I would rather remove the backwards compatibility instead of adding more checks.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.
Agreed.