Skip to content
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

Merged
merged 3 commits into from
Jun 20, 2023
Merged

Fix empty file uploads #78

merged 3 commits into from
Jun 20, 2023

Conversation

Matoking
Copy link
Contributor

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.

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.
Copy link
Member

@Acconut Acconut left a 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

def test_upload_empty(self):
with aioresponses() as resps:
resps.post(
"http://tusd.tusdemo.net/files/", status=200,
Copy link
Member

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?

Copy link
Contributor Author

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.


# 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
Copy link
Member

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?

Copy link
Contributor Author

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.
@Matoking
Copy link
Contributor Author

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.

Copy link
Member

@Acconut Acconut left a 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!

@Acconut Acconut merged commit 3bc58e5 into tus:main Jun 20, 2023
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants