DDMAL / Rodan

:dragon_face: A web-based workflow engine.
https://rodan2.simssa.ca/
45 stars 13 forks source link

Image file path error during GameraTask test #325

Closed lingxiaoyang closed 10 years ago

lingxiaoyang commented 10 years ago

@rberkow GameraTask test test_to_greyscale throws a SuspiciousFileOperation exception because it cannot find the specific image file on your machine with the file path coming from fixtures. Is there a better way to test the functionality of tasks?

The error message from python manage.py test:

======================================================================
ERROR: test_to_greyscale (Rodan.rodan.test.jobs.test_GameraTask.GameraTaskTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/lyang/development/Rodan/rodan/test/jobs/test_GameraTask.py", line 24, in test_to_greyscale
    result = GameraTask.run_task(task, "04ae88f664664d3eaa68406c7c2f1211", "3d558414db10427d82efdd9b9cb985bf")
  File "/Users/lyang/development/Rodan/rodan/jobs/gamera/celery_task.py", line 40, in run_task
    page = result.resource_file.path
  File "/Users/lyang/development/Rodan/rodan_env/lib/python2.7/site-packages/django/db/models/fields/files.py", line 62, in _get_path
    return self.storage.path(self.name)
  File "/Users/lyang/development/Rodan/rodan_env/lib/python2.7/site-packages/django/core/files/storage.py", line 281, in path
    raise SuspiciousFileOperation("Attempted access to '%s' denied." % name)
SuspiciousFileOperation: Attempted access to '/Users/rberkow/Documents/code/Rodan/rodan/uploads/projects/9e1fece2beb54392990e8d21cafb0f06/resources/cd9a5c41208645f98a1cd30b00ee916f/original_file.png' denied.
rberkow commented 10 years ago

Yes I actually was aware that this would be a problem. I think the best way to go about this would be to write the test class as an APITestCase, and make the REST calls to upload resources in a setUp() method. Then the tasks would be run on only those resources that had just been uploaded, instead of from the fixtures. Anyway I will work on fixing this in the next few days.

rberkow commented 10 years ago

@lingxiaoyang did your Model Mommy solution fix this issue?

lingxiaoyang commented 10 years ago

@rberkow Model Mommy creates model objects in setUp() method, and then the tests rely on these dynamically generated objects instead of fixtures. It makes easier to manipulate the test objects.