Commit 407db0d3 by Dudás Ádám

vm: fix tests

parent e5a442ad
...@@ -175,25 +175,19 @@ class InstanceActivityTestCase(TestCase): ...@@ -175,25 +175,19 @@ class InstanceActivityTestCase(TestCase):
instance.activity_log.filter.return_value.exists.return_value = True instance.activity_log.filter.return_value.exists.return_value = True
with self.assertRaises(ActivityInProgressError): with self.assertRaises(ActivityInProgressError):
InstanceActivity.create("test", instance, concurrency_check=True) InstanceActivity.create('test', instance, concurrency_check=True)
def test_create_no_concurrency_check(self): def test_create_no_concurrency_check(self):
instance = MagicMock(spec=Instance) instance = MagicMock(spec=Instance)
instance.activity_log.filter.return_value.exists.return_value = True instance.activity_log.filter.return_value.exists.return_value = True
original_method = InstanceActivity.create.__func__ with patch.object(InstanceActivity, '__new__'):
try:
with patch('vm.models.activity.InstanceActivity') as ia, \ InstanceActivity.create('test', instance,
patch('vm.models.activity.timezone.now'): concurrency_check=False)
# ia.__init__ = MagicMock() raises AttributeError except ActivityInProgressError:
raise AssertionError("'create' method checked for concurrent "
original_method(ia, "test", instance, concurrency_check=False) "activities.")
ia.save.assert_called()
# ia.__init__.assert_called_with(activity_code='vm.Instance.test',
# instance=instance, parent=None,
# resultant_state=None, started=now,
# task_uuid=None, user=None)
def test_create_sub_concurrency_check(self): def test_create_sub_concurrency_check(self):
iaobj = MagicMock(spec=InstanceActivity) iaobj = MagicMock(spec=InstanceActivity)
...@@ -207,12 +201,13 @@ class InstanceActivityTestCase(TestCase): ...@@ -207,12 +201,13 @@ class InstanceActivityTestCase(TestCase):
iaobj.activity_code = 'test' iaobj.activity_code = 'test'
iaobj.children.filter.return_value.exists.return_value = True iaobj.children.filter.return_value.exists.return_value = True
original_method = InstanceActivity.create_sub with patch.object(InstanceActivity, '__new__'):
try:
with patch('vm.models.activity.InstanceActivity') as ia, \ InstanceActivity.create_sub(iaobj, 'test',
patch('vm.models.activity.timezone.now'): concurrency_check=False)
original_method(iaobj, "test", concurrency_check=False) except ActivityInProgressError:
ia.save.assert_called() raise AssertionError("'create_sub' method checked for "
"concurrent activities.")
def test_disable_enabled(self): def test_disable_enabled(self):
node = MagicMock(spec=Node, enabled=True) node = MagicMock(spec=Node, enabled=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment