Local upload testing
Test each of the four functionalities found under the new UploadJobViewSet. That is create_job
, add_file
, create_sip
and create_archive
.
I would extend the already existing UploadTests class in test_upload.py
.
create_job
: retrieve number of existing UploadJobs, create one, retrieve again and assert that it is equal to the previous plus 1. We could even go further and retrieve the latest added row to the UploadJob table using the date and time field that we will use later on for monitoring the UploadJobs with celery, and asserting that all the fields are correct (this might be too much).
add_file
: create a new empty UploadJob and add a new NamedTemporaryFile to it. Retrieve the job's TemporaryDirectory from the table and assert that the number of files is 1 (os.listdir()
comes to mind for this, returns a list of directories and files inside a directory, thus should return a list of length 1). Also, assert the names are the same. Assert this same thing retrieving the json from the associated files field from the database.
create_sip
: create a new empty UploadJob and populate it with TemporaryDirectory and NamedTemporaryFile objects. Call create_sip()
on it and assert that status=0
in the response. Moreover, assert that the number of directories in the BASE_PATH
(this is where all SIPs should be saved) increased by one (using os.listdir()
).
Thinking about this test made me question the design of this method. The way it works is by getting the url's corresponding UploadJob, retrieving its TemporaryDirectory from the table and then calling bagit_create
. Thus, this method requires a valid UploadJob object, which seems like too much. On the other hand, passing the TemporaryDirectory path in the POST request for the method to know where to call bagit_create
on did not look like a good idea. What do you think about this?
create_archive
: again, create a new UploadJob and populate it with Temporaries (same question about the design as above). Assert the response's status
is 0
and the msg
is SIP uploaded, see Archives page
. Do we want to check a new Archive got created by checking the number of Archives increased by 1?
For dealing with multiple creations of UploadJob objects and then populating them, a helper method inside the testing class that creates one, populates it with dummies, and returns it. Another one for deleting it from the table, as well as deleting all the dummies that populated it.