Browse files

Refactored the retrying tests.

  • Loading branch information...
1 parent d502505 commit 1f56fd1134106df8715d9e54735ef8b0f3f04fc5 @jezdez jezdez committed May 8, 2012
Showing with 25 additions and 26 deletions.
  1. +2 −0 queued_storage/tests/models.py
  2. +5 −8 queued_storage/tests/tasks.py
  3. +18 −18 queued_storage/tests/tests.py
View
2 queued_storage/tests/models.py
@@ -2,6 +2,8 @@
from queued_storage.fields import QueuedFileField
+retried = False
+
class TestModel(models.Model):
file = models.FileField(upload_to='test', null=True)
View
13 queued_storage/tests/tasks.py
@@ -1,6 +1,8 @@
from queued_storage.tasks import Transfer
from queued_storage.utils import import_attribute
+from . import models
+
def test_task(name, cache_key,
local_path, remote_path,
@@ -21,14 +23,9 @@ def transfer(self, *args, **kwargs):
return None
-retried = False
-
-
class RetryingTask(Transfer):
def transfer(self, *args, **kwargs):
- global retried
- if retried:
+ if models.retried:
return True
- else:
- retried = True
- return False
+ models.retried = True
+ return False
View
36 queued_storage/tests/tests.py
@@ -18,8 +18,7 @@
from queued_storage.backends import QueuedStorage
from queued_storage.conf import settings
-from .models import TestModel
-from queued_storage.tests import tasks as test_tasks
+from . import models
class StorageTests(TestCase):
@@ -40,6 +39,7 @@ def setUp(self):
def tearDown(self):
settings.CELERY_ALWAYS_EAGER = self.old_celery_always_eager
+ models.retried = False
def test_storage_init(self):
"""
@@ -90,10 +90,10 @@ def test_storage_simple_save(self):
remote_options=dict(location=self.remote_dir),
task='queued_storage.tests.tasks.test_task')
- field = TestModel._meta.get_field('file')
+ field = models.TestModel._meta.get_field('file')
field.storage = storage
- obj = TestModel(file=File(self.test_file))
+ obj = models.TestModel(file=File(self.test_file))
obj.save()
self.assertTrue(path.isfile(path.join(self.local_dir, obj.file.name)))
@@ -109,10 +109,10 @@ def test_storage_celery_save(self):
local_options=dict(location=self.local_dir),
remote_options=dict(location=self.remote_dir))
- field = TestModel._meta.get_field('file')
+ field = models.TestModel._meta.get_field('file')
field.storage = storage
- obj = TestModel(file=File(self.test_file))
+ obj = models.TestModel(file=File(self.test_file))
obj.save()
self.assertTrue(obj.file.storage.result.get())
@@ -161,10 +161,10 @@ def test_transfer_and_delete(self):
remote_options=dict(location=self.remote_dir),
task='queued_storage.tasks.TransferAndDelete')
- field = TestModel._meta.get_field('file')
+ field = models.TestModel._meta.get_field('file')
field.storage = storage
- obj = TestModel(file=File(self.test_file))
+ obj = models.TestModel(file=File(self.test_file))
obj.save()
obj.file.storage.result.get()
@@ -188,10 +188,10 @@ def test_transfer_returns_boolean(self):
remote_options=dict(location=self.remote_dir),
task='queued_storage.tests.tasks.NoneReturningTask')
- field = TestModel._meta.get_field('file')
+ field = models.TestModel._meta.get_field('file')
field.storage = storage
- obj = TestModel(file=File(self.test_file))
+ obj = models.TestModel(file=File(self.test_file))
obj.save()
self.assertRaises(ValueError,
@@ -207,16 +207,16 @@ def test_transfer_retried(self):
local_options=dict(location=self.local_dir),
remote_options=dict(location=self.remote_dir),
task='queued_storage.tests.tasks.RetryingTask')
- field = TestModel._meta.get_field('file')
+ field = models.TestModel._meta.get_field('file')
field.storage = storage
- self.assertFalse(test_tasks.retried)
+ self.assertFalse(models.retried)
- obj = TestModel(file=File(self.test_file))
+ obj = models.TestModel(file=File(self.test_file))
obj.save()
self.assertFalse(obj.file.storage.result.get())
- self.assertTrue(test_tasks.retried)
+ self.assertTrue(models.retried)
def test_delayed_storage(self):
storage = QueuedStorage(
@@ -226,10 +226,10 @@ def test_delayed_storage(self):
remote_options=dict(location=self.remote_dir),
delayed=True)
- field = TestModel._meta.get_field('file')
+ field = models.TestModel._meta.get_field('file')
field.storage = storage
- obj = TestModel(file=File(self.test_file))
+ obj = models.TestModel(file=File(self.test_file))
obj.save()
self.assertIsNone(getattr(obj.file.storage, 'result', None))
@@ -253,10 +253,10 @@ def test_remote_file_field(self):
remote_options=dict(location=self.remote_dir),
delayed=True)
- field = TestModel._meta.get_field('remote')
+ field = models.TestModel._meta.get_field('remote')
field.storage = storage
- obj = TestModel(remote=File(self.test_file))
+ obj = models.TestModel(remote=File(self.test_file))
obj.save()
self.assertIsNone(getattr(obj.file.storage, 'result', None))

0 comments on commit 1f56fd1

Please sign in to comment.