-
Notifications
You must be signed in to change notification settings - Fork 44
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
Fix empty file uploads #78
Conversation
tus-js-client and tusd support uploads of empty files. In these cases, only the initial POST request needs to be performed: tus/tus-js-client#106 This was supported by 0.2.5, but the refactoring inadvertently broke this by skipping by all HTTP requests entirely.
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.
Thank you for this PR! The logic itself looks fine, I just have two questions regarding the tests
tests/test_async_uploader.py
Outdated
def test_upload_empty(self): | ||
with aioresponses() as resps: | ||
resps.post( | ||
"http://tusd.tusdemo.net/files/", status=200, |
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.
Could you use self.url
here instead of tusd.tusdemo.net directly?
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.
Not self.url
(it's hardcoded to an existing upload), but self.client.url
contains an URL to a tus upload endpoint and we can use that instead.
Since we're practically mocking all the HTTP requests in this scenario, it would probably be better to use a fake URL we know that doesn't correspond to a real service (eg. mock-tus.localdomain
), since we want the test to fail instead of contacting a real endpoint. But I'm using the same URL for consistency's sake here.
tests/test_async_uploader.py
Outdated
|
||
# Set uploader's URL to None. This corresponds to a new upload; | ||
# if the URL is set we're continuing an existing upload. | ||
self.async_uploader.url = None |
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.
Is it necessary to set url = None
here? I thought we are creating a new uploader for each test, so the url should not be initialized here. Or am I missing something?
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.
It's not actually necessary, and it's a better approach to create an uploader from the existing self.client
fixture. I've refactored the tests to do so.
It's more reliable and concise to create an uploader from the existing client fixture instead of modifying an existing uploader to resemble what we want.
I've refactored the tests in addd94a per code review comments. If that looks OK, I can squash the two test commits to make the history a bit cleaner. |
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.
Thank you very much for your work here!
tus-js-client and tusd support uploads of empty files. In
these cases, only the initial POST request needs to be performed:
tus/tus-js-client#106
This was supported by 0.2.5, but the refactoring inadvertently broke
this by skipping by all HTTP requests entirely.