summaryrefslogtreecommitdiff
path: root/taskflow/test.py
diff options
context:
space:
mode:
authorStanislav Kudriashev <skudriashev@griddynamics.com>2013-12-19 17:48:06 +0200
committerStanislav Kudriashev <skudriashev@griddynamics.com>2014-02-19 14:47:34 +0200
commit32e8c3da61b0dea2ffbbdd96f2c97c11fe8f3323 (patch)
tree813023ee1a046fe6a4bd4131c6a05aa88d780cb6 /taskflow/test.py
parent5acb0832dfac69976d492b9d4579d6723dd7907b (diff)
downloadtaskflow-32e8c3da61b0dea2ffbbdd96f2c97c11fe8f3323.tar.gz
Message-oriented worker-based flow with kombu
* Implemented Worker to be started on remote host for handling tasks request. * Implemented WorkerTaskExecutor that proxies tasks requests to remote workers. * Implemented Proxy that is used for consuming and publishing messages by Worker and Executor. * Added worker-based engine and worker task executor. * Added kombu dependency to requirements. * Added worker-based flow example. * Added unit-tests for worker-based flow components. Implements: blueprint worker-based-engine Change-Id: I8c6859ba4a1a56c2592e3d67cdfb8968b13ee99c
Diffstat (limited to 'taskflow/test.py')
-rw-r--r--taskflow/test.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/taskflow/test.py b/taskflow/test.py
index 1da10aa..f48493d 100644
--- a/taskflow/test.py
+++ b/taskflow/test.py
@@ -16,6 +16,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import mock
+
from testtools import compat
from testtools import matchers
from testtools import testcase
@@ -88,3 +90,51 @@ class TestCase(testcase.TestCase):
self.fail(msg)
else:
current_tail = current_tail[super_index + 1:]
+
+
+class MockTestCase(TestCase):
+
+ def setUp(self):
+ super(MockTestCase, self).setUp()
+ self.master_mock = mock.Mock(name='master_mock')
+
+ def _patch(self, target, autospec=True, **kwargs):
+ """Patch target and attach it to the master mock."""
+ patcher = mock.patch(target, autospec=autospec, **kwargs)
+ mocked = patcher.start()
+ self.addCleanup(patcher.stop)
+
+ attach_as = kwargs.pop('attach_as', None)
+ if attach_as is not None:
+ self.master_mock.attach_mock(mocked, attach_as)
+
+ return mocked
+
+ def _patch_class(self, module, name, autospec=True, attach_as=None):
+ """Patch class, create class instance mock and attach them to
+ the master mock.
+ """
+ if autospec:
+ instance_mock = mock.Mock(spec_set=getattr(module, name))
+ else:
+ instance_mock = mock.Mock()
+
+ patcher = mock.patch.object(module, name, autospec=autospec)
+ class_mock = patcher.start()
+ self.addCleanup(patcher.stop)
+ class_mock.return_value = instance_mock
+
+ if attach_as is None:
+ attach_class_as = name
+ attach_instance_as = name.lower()
+ else:
+ attach_class_as = attach_as + '_class'
+ attach_instance_as = attach_as
+
+ self.master_mock.attach_mock(class_mock, attach_class_as)
+ self.master_mock.attach_mock(instance_mock, attach_instance_as)
+
+ return class_mock, instance_mock
+
+ def _reset_master_mock(self):
+ self.master_mock.reset_mock()