Permalink
Browse files

moving test util to test module

  • Loading branch information...
chrisclark committed Feb 19, 2014
1 parent 45253c8 commit ed9bee01a007fff9ab8e67795d866542437ed6b5
Showing with 24 additions and 23 deletions.
  1. +1 −1 explorer/tests/test_models.py
  2. +23 −0 explorer/tests/utils.py
  3. +0 −22 explorer/utils.py
@@ -1,6 +1,6 @@
from django.test import TestCase
from explorer.tests.factories import SimpleQueryFactory
-from explorer.utils import AssertMethodIsCalled
+from explorer.tests.utils import AssertMethodIsCalled
from explorer.models import MSG_FAILED_BLACKLIST
View
@@ -0,0 +1,23 @@
+## Testing helpers (from http://stackoverflow.com/a/3829849/221390
+class AssertMethodIsCalled(object):
+ def __init__(self, obj, method):
+ self.obj = obj
+ self.method = method
+
+ def called(self, *args, **kwargs):
+ self.method_called = True
+ self.orig_method(*args, **kwargs)
+
+ def __enter__(self):
+ self.orig_method = getattr(self.obj, self.method)
+ setattr(self.obj, self.method, self.called)
+ self.method_called = False
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ assert getattr(self.obj, self.method) == self.called, "method %s was modified during assertMethodIsCalled" % self.method
+
+ setattr(self.obj, self.method, self.orig_method)
+
+ # If an exception was thrown within the block, we've already failed.
+ if traceback is None:
+ assert self.method_called, "method %s of %s was not called" % (self.method, self.obj)
View
@@ -181,26 +181,4 @@ def url_get_params(request):
return get_json_from_request(request, 'params')
-## Testing helpers (from http://stackoverflow.com/a/3829849/221390
-class AssertMethodIsCalled(object):
- def __init__(self, obj, method):
- self.obj = obj
- self.method = method
- def called(self, *args, **kwargs):
- self.method_called = True
- self.orig_method(*args, **kwargs)
-
- def __enter__(self):
- self.orig_method = getattr(self.obj, self.method)
- setattr(self.obj, self.method, self.called)
- self.method_called = False
-
- def __exit__(self, exc_type, exc_value, traceback):
- assert getattr(self.obj, self.method) == self.called, "method %s was modified during assertMethodIsCalled" % self.method
-
- setattr(self.obj, self.method, self.orig_method)
-
- # If an exception was thrown within the block, we've already failed.
- if traceback is None:
- assert self.method_called, "method %s of %s was not called" % (self.method, self.obj)

0 comments on commit ed9bee0

Please sign in to comment.