Fix unit tests - policy file failure

Due to this change (https://review.openstack.org/#/c/144152/) in
horizon, there is an additional policy check added to the base
wizard code.

Need to mock out the policy check in our unit tests.

Change-Id: I9b501a4a1aa9e817f9ccaa897cc93496aa4ca01c
Closes-Bug: #1599267
This commit is contained in:
Duk Loi 2016-07-05 15:10:48 -04:00
parent f628c0705e
commit bcb5d75eeb
2 changed files with 34 additions and 11 deletions

View File

@ -17,6 +17,8 @@ from django import http
from mox3.mox import IsA # noqa
import six
from openstack_auth import policy
from trove_dashboard import api
from trove_dashboard.test import helpers as test
@ -56,10 +58,12 @@ class DatabasesBackupsTests(test.TestCase):
self.assertEqual(res.status_code, 200)
self.assertMessageCount(res, error=1)
@test.create_stubs({api.trove: ('instance_list',
'backup_list',
'backup_create')})
@test.create_stubs({
api.trove: ('instance_list', 'backup_list', 'backup_create'),
policy: ('check',),
})
def test_launch_backup(self):
policy.check((), IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
api.trove.instance_list(IsA(http.HttpRequest))\
.AndReturn(self.databases.list())
api.trove.backup_list(IsA(http.HttpRequest)) \
@ -89,8 +93,12 @@ class DatabasesBackupsTests(test.TestCase):
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.trove: ('instance_list', 'backup_list')})
@test.create_stubs({
api.trove: ('instance_list', 'backup_list'),
policy: ('check',),
})
def test_launch_backup_exception(self):
policy.check((), IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
api.trove.instance_list(IsA(http.HttpRequest))\
.AndRaise(self.exceptions.trove)
api.trove.backup_list(IsA(http.HttpRequest)) \
@ -103,10 +111,12 @@ class DatabasesBackupsTests(test.TestCase):
self.assertTemplateUsed(res,
'project/database_backups/backup.html')
@test.create_stubs({api.trove: ('instance_list',
'backup_list',
'backup_create')})
@test.create_stubs({
api.trove: ('instance_list', 'backup_list', 'backup_create'),
policy: ('check',),
})
def test_launch_backup_incr(self):
policy.check((), IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
api.trove.instance_list(IsA(http.HttpRequest)) \
.AndReturn(self.databases.list())
api.trove.backup_list(IsA(http.HttpRequest)) \

View File

@ -24,6 +24,7 @@ from mox3.mox import IsA # noqa
import six
from horizon import exceptions
from openstack_auth import policy
from openstack_dashboard import api as dash_api
from troveclient import common
@ -131,8 +132,11 @@ class DatabaseTests(test.TestCase):
'datastore_list', 'datastore_version_list',
'instance_list'),
dash_api.cinder: ('volume_type_list',),
dash_api.neutron: ('network_list',)})
dash_api.neutron: ('network_list',),
policy: ('check',),
})
def test_launch_instance(self):
policy.check((), IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
api.trove.flavor_list(IsA(http.HttpRequest)).AndReturn(
self.flavors.list())
api.trove.backup_list(IsA(http.HttpRequest)).AndReturn(
@ -197,8 +201,11 @@ class DatabaseTests(test.TestCase):
'datastore_list', 'datastore_version_list',
'instance_list'),
dash_api.cinder: ('volume_type_list',),
dash_api.neutron: ('network_list',)})
dash_api.neutron: ('network_list',),
policy: ('check',),
})
def test_create_simple_instance(self):
policy.check((), IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
api.trove.flavor_list(IsA(http.HttpRequest)).AndReturn(
self.flavors.list())
@ -263,8 +270,11 @@ class DatabaseTests(test.TestCase):
'datastore_list', 'datastore_version_list',
'instance_list'),
dash_api.cinder: ('volume_type_list',),
dash_api.neutron: ('network_list',)})
dash_api.neutron: ('network_list',),
policy: ('check',),
})
def test_create_simple_instance_exception(self):
policy.check((), IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
trove_exception = self.exceptions.nova
api.trove.flavor_list(IsA(http.HttpRequest)).AndReturn(
self.flavors.list())
@ -958,8 +968,11 @@ class DatabaseTests(test.TestCase):
'datastore_list', 'datastore_version_list',
'instance_list_all', 'instance_get'),
dash_api.cinder: ('volume_type_list',),
dash_api.neutron: ('network_list',)})
dash_api.neutron: ('network_list',),
policy: ('check',),
})
def test_create_replica_instance(self):
policy.check((), IsA(http.HttpRequest)).MultipleTimes().AndReturn(True)
api.trove.flavor_list(IsA(http.HttpRequest)).AndReturn(
self.flavors.list())