dataverse-client-python
dataverse-client-python copied to clipboard
Add integration test to download a file by filename
I was just looking at https://github.com/IQSS/dataverse/issues/2700 and thinking, "Ideally, how would we have people programmatically download a file of interest?"
I think the answer to this question is for the user to supply the following information:
- a DOI (or Handle, or generically, a persistent identifier for the dataset)
- a filename
I was just looking at https://github.com/IQSS/dataverse-client-python/blob/d6e2199f21cddffac37d94d4e39caeaece70ee7e/dataverse/test/test_dataverse.py and I found test where "cat.jpg" is deleted by filename but I couldn't find an example of where a file is downloaded by filename. I think this would be a nice test to have, if it isn't too much trouble to add.
Basically, the DOI of the dataset would be the starting point. Then you enumerate the files in the dataset. Then you find the file that matches "cat.jpg" and download it based on its database id (or some sort of persistent identifier for files, if/when this is implemented as part of https://github.com/IQSS/dataverse/issues/2438 ).
Downloading isn't actually a function of the python client. The best it does is provide a download URL based on the file id, and it's up to the consumer of the API to do with that as they will. With the functionality we have, I think that test would be more of a test of the API itself than the python client.
I'm not especially proud of the tests I've put in because they don't do a very good job of distinguishing testing the API vs. the client. Ideally, I think, the tests should cover the internal data structures and consuming the API correctly rather than relying on the test server to behave the way we expect it to.
There's no reason we can't also have integration tests against the server, but it would make sense to keep those separate from the internal tests. So in that respect, I think a test downloading the file wouldn't provide any more information about the state of the python client than would testing that the download url is built the way we expect it to be.
Ah, I see, you provide a download URL for files here: https://github.com/IQSS/dataverse-client-python/blob/f84b980545aec73325eba88417c36a61deb79a9a/dataverse/file.py#L12 . Thanks.
Very good point about unit vs integration tests. I'll add the word "integration" to the title of this issue. I feel like I'm getting some testing of https://apitest.dataverse.org as a nice byproduct of integration tests. :)