Commit ca1da568 by Fábián János

during migration, Operation::asnyc was replaced by _async

parent a7cae3ff
......@@ -44,8 +44,6 @@ class QuerySet(list):
def all(self):
return self
class ViewUserTestCase(unittest.TestCase):
def test_404(self):
......@@ -170,14 +168,14 @@ class VmOperationViewTestCase(unittest.TestCase):
inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance"
inst.migrate = Instance._ops['migrate'](inst)
inst.migrate.async = MagicMock()
inst.migrate._async = MagicMock()
inst.has_level.return_value = True
form_kwargs.return_value = {
'default': 100, 'choices': QuerySet([node])}
go.return_value = inst
assert view.as_view()(request, pk=1234)['location']
assert not msg.error.called
inst.migrate.async.assert_called_once_with(
inst.migrate._async.assert_called_once_with(
to_node=node, live_migration=True, user=request.user)
def test_migrate_failed(self):
......@@ -191,14 +189,14 @@ class VmOperationViewTestCase(unittest.TestCase):
inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance"
inst.migrate = Instance._ops['migrate'](inst)
inst.migrate.async = MagicMock()
inst.migrate.async.side_effect = Exception
inst.migrate._async = MagicMock()
inst.migrate._async.side_effect = Exception
inst.has_level.return_value = True
form_kwargs.return_value = {
'default': 100, 'choices': QuerySet([node])}
go.return_value = inst
assert view.as_view()(request, pk=1234)['location']
assert inst.migrate.async.called
assert inst.migrate._async.called
assert msg.error.called
def test_migrate_wo_permission(self):
......@@ -211,14 +209,14 @@ class VmOperationViewTestCase(unittest.TestCase):
inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance"
inst.migrate = Instance._ops['migrate'](inst)
inst.migrate.async = MagicMock()
inst.migrate._async = MagicMock()
inst.has_level.return_value = True
form_kwargs.return_value = {
'default': 100, 'choices': QuerySet([node])}
go.return_value = inst
with self.assertRaises(PermissionDenied):
assert view.as_view()(request, pk=1234)['location']
assert not inst.migrate.async.called
assert not inst.migrate._async.called
def test_migrate_template(self):
"""check if GET dialog's template can be rendered"""
......@@ -244,7 +242,7 @@ class VmOperationViewTestCase(unittest.TestCase):
inst.name = "asd"
inst._meta.object_name = "Instance"
inst.save_as_template = Instance._ops['save_as_template'](inst)
inst.save_as_template.async = MagicMock()
inst.save_as_template._async = MagicMock()
inst.has_level.return_value = True
go.return_value = inst
assert view.as_view()(request, pk=1234)
......@@ -261,7 +259,7 @@ class VmOperationViewTestCase(unittest.TestCase):
inst.name = "asd"
inst._meta.object_name = "Instance"
inst.save_as_template = Instance._ops['save_as_template'](inst)
inst.save_as_template.async = MagicMock()
inst.save_as_template._async = MagicMock()
inst.has_level.return_value = True
go.return_value = inst
assert view.as_view()(request, pk=1234)['location']
......@@ -334,7 +332,7 @@ class VmMassOperationViewTestCase(unittest.TestCase):
inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance"
inst.migrate = Instance._ops['migrate'](inst)
inst.migrate.async = MagicMock()
inst.migrate._async = MagicMock()
inst.has_level.return_value = True
go.return_value = [inst]
assert view.as_view()(request, pk=1234)['location']
......@@ -413,13 +411,13 @@ class RenewViewTest(unittest.TestCase):
inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99)
inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock()
inst.renew._async = MagicMock()
inst.has_level.return_value = True
go.return_value = inst
assert view.as_view()(request, pk=1234)
assert not msg.error.called
assert inst.renew.async.called_with(user=request.user, lease=None)
assert inst.renew.async.return_value.get.called
assert inst.renew._async.called_with(user=request.user, lease=None)
assert inst.renew._async.return_value.get.called
# success would redirect
def test_renew_by_owner_w_param(self):
......@@ -432,7 +430,7 @@ class RenewViewTest(unittest.TestCase):
inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99)
inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock()
inst.renew._async = MagicMock()
inst.has_level.return_value = True
go.return_value = inst
assert view.as_view()(request, pk=1234)
......@@ -446,7 +444,7 @@ class RenewViewTest(unittest.TestCase):
inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance"
inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock()
inst.renew._async = MagicMock()
inst.has_level.return_value = False
go.return_value = inst
self.assertIn('login',
......@@ -460,7 +458,7 @@ class RenewViewTest(unittest.TestCase):
inst = MagicMock(spec=Instance)
inst._meta.object_name = "Instance"
inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock()
inst.renew._async = MagicMock()
inst.has_level.return_value = False
go.return_value = inst
with self.assertRaises(PermissionDenied):
......@@ -475,7 +473,7 @@ class RenewViewTest(unittest.TestCase):
inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99)
inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock()
inst.renew._async = MagicMock()
inst.has_level.return_value = False
go.return_value = inst
with self.assertRaises(PermissionDenied):
......@@ -486,8 +484,9 @@ class RenewViewTest(unittest.TestCase):
view = vm_ops['renew']
inst = MagicMock(spec=Instance, pk=11)
inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99)
inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock()
inst.renew._async = MagicMock()
key = view.get_token_url(inst, user).split('?')[1].split('=')[1]
request = FakeRequestFactory(GET={'k': key}) # other user!
......@@ -504,8 +503,9 @@ class RenewViewTest(unittest.TestCase):
view = vm_ops['renew']
inst = MagicMock(spec=Instance, pk=11)
inst._meta.object_name = "Instance"
inst.lease = MagicMock(pk=99)
inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock()
inst.renew._async = MagicMock()
inst.has_level = lambda user, level: user.is_authenticated
key = view.get_token_url(inst, user).split('?')[1].split('=')[1]
request = FakeRequestFactory(GET={'k': key}, authenticated=False)
......@@ -541,7 +541,7 @@ class RenewViewTest(unittest.TestCase):
inst = MagicMock(spec=Instance, pk=11)
inst._meta.object_name = "Instance"
inst.renew = Instance._ops['renew'](inst)
inst.renew.async = MagicMock()
inst.renew._async = MagicMock()
inst.has_level.return_value = False
key = view.get_token_url(inst, user).split('?')[1].split('=')[1]
with patch('dashboard.views.signing.loads') as loader, \
......
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