Merge "Mox removal for DatabaseConfigurationsTests"

This commit is contained in:
Zuul 2018-06-29 02:06:25 +00:00 committed by Gerrit Code Review
commit 20d176e513

View File

@ -13,13 +13,12 @@
# under the License. # under the License.
import logging import logging
import mock
import six import six
import django import django
from django.conf import settings from django.conf import settings
from django import http
from django.urls import reverse from django.urls import reverse
from mox3.mox import IsA # noqa
from trove_dashboard import api from trove_dashboard import api
from trove_dashboard.content.database_configurations \ from trove_dashboard.content.database_configurations \
@ -34,43 +33,44 @@ ADD_URL = 'horizon:project:database_configurations:add'
class DatabaseConfigurationsTests(test.TestCase): class DatabaseConfigurationsTests(test.TestCase):
@test.create_stubs({api.trove: ('configuration_list',)}) @test.create_mocks({api.trove: ('configuration_list',)})
def test_index(self): def test_index(self):
api.trove.configuration_list(IsA(http.HttpRequest)) \ self.mock_configuration_list.return_value = (
.AndReturn(self.database_configurations.list()) self.database_configurations.list())
self.mox.ReplayAll()
res = self.client.get(INDEX_URL) res = self.client.get(INDEX_URL)
self.mock_configuration_list.assert_called_once_with(
test.IsHttpRequest())
self.assertTemplateUsed(res, self.assertTemplateUsed(res,
'project/database_configurations/index.html') 'project/database_configurations/index.html')
@test.create_stubs({api.trove: ('configuration_list',)}) @test.create_mocks({api.trove: ('configuration_list',)})
def test_index_exception(self): def test_index_exception(self):
api.trove.configuration_list(IsA(http.HttpRequest)) \ self.mock_configuration_list.side_effect = self.exceptions.trove
.AndRaise(self.exceptions.trove)
self.mox.ReplayAll()
res = self.client.get(INDEX_URL) res = self.client.get(INDEX_URL)
self.mock_configuration_list.assert_called_once_with(
test.IsHttpRequest())
self.assertTemplateUsed( self.assertTemplateUsed(
res, 'project/database_configurations/index.html') res, 'project/database_configurations/index.html')
self.assertEqual(res.status_code, 200) self.assertEqual(res.status_code, 200)
self.assertMessageCount(res, error=1) self.assertMessageCount(res, error=1)
@test.create_stubs({ @test.create_mocks({
api.trove: ('datastore_list', 'datastore_version_list')}) api.trove: ('datastore_list', 'datastore_version_list')})
def test_create_configuration(self): def test_create_configuration(self):
api.trove.datastore_list(IsA(http.HttpRequest)) \ self.mock_datastore_list.return_value = self.datastores.list()
.AndReturn(self.datastores.list()) self.mock_datastore_version_list.return_value = (
api.trove.datastore_version_list(IsA(http.HttpRequest), IsA(str)) \ self.datastore_versions.list())
.MultipleTimes().AndReturn(self.datastore_versions.list())
self.mox.ReplayAll()
res = self.client.get(CREATE_URL) res = self.client.get(CREATE_URL)
self.mock_datastore_list.assert_called_once_with(test.IsHttpRequest())
self.assert_mock_multiple_calls_with_same_arguments(
self.mock_datastore_version_list, 4,
mock.call(test.IsHttpRequest(), test.IsA(str)))
self.assertTemplateUsed(res, self.assertTemplateUsed(res,
'project/database_configurations/create.html') 'project/database_configurations/create.html')
@test.create_stubs({api.trove: ('datastore_list',)}) @test.create_mocks({api.trove: ('datastore_list',)})
def test_create_configuration_exception_on_datastore(self): def test_create_configuration_exception_on_datastore(self):
api.trove.datastore_list(IsA(http.HttpRequest)) \ self.mock_datastore_list.side_effect = self.exceptions.trove
.AndRaise(self.exceptions.trove)
self.mox.ReplayAll()
toSuppress = ["trove_dashboard.content." toSuppress = ["trove_dashboard.content."
"database_configurations.forms", ] "database_configurations.forms", ]
@ -83,6 +83,8 @@ class DatabaseConfigurationsTests(test.TestCase):
try: try:
res = self.client.get(CREATE_URL) res = self.client.get(CREATE_URL)
self.mock_datastore_list.assert_called_once_with(
test.IsHttpRequest())
self.assertEqual(res.status_code, 302) self.assertEqual(res.status_code, 302)
finally: finally:
@ -90,15 +92,17 @@ class DatabaseConfigurationsTests(test.TestCase):
for (log, level) in loggers: for (log, level) in loggers:
log.setLevel(level) log.setLevel(level)
@test.create_stubs({ @test.create_mocks({
api.trove: ('datastore_list', 'datastore_version_list', api.trove: ('datastore_list', 'datastore_version_list',
'configuration_create')}) 'configuration_create')})
def _test_create_test_configuration( def _test_create_test_configuration(
self, config_description=u''): self, config_description=u''):
api.trove.datastore_list(IsA(http.HttpRequest)) \ self.mock_datastore_list.return_value = self.datastores.list()
.AndReturn(self.datastores.list()) self.mock_datastore_version_list.return_value = (
api.trove.datastore_version_list(IsA(http.HttpRequest), IsA(str)) \ self.datastore_versions.list())
.MultipleTimes().AndReturn(self.datastore_versions.list())
self.mock_configuration_create.return_value = (
self.database_configurations.first())
name = u'config1' name = u'config1'
values = "{}" values = "{}"
@ -107,16 +111,6 @@ class DatabaseConfigurationsTests(test.TestCase):
config_datastore = ds.name config_datastore = ds.name
config_datastore_version = dsv.name config_datastore_version = dsv.name
api.trove.configuration_create(
IsA(http.HttpRequest),
name,
values,
description=config_description,
datastore=config_datastore,
datastore_version=config_datastore_version) \
.AndReturn(self.database_configurations.first())
self.mox.ReplayAll()
post = { post = {
'method': 'CreateConfigurationForm', 'method': 'CreateConfigurationForm',
'name': name, 'name': name,
@ -124,6 +118,17 @@ class DatabaseConfigurationsTests(test.TestCase):
'datastore': (config_datastore + ',' + config_datastore_version)} 'datastore': (config_datastore + ',' + config_datastore_version)}
res = self.client.post(CREATE_URL, post) res = self.client.post(CREATE_URL, post)
self.mock_datastore_list.assert_called_once_with(test.IsHttpRequest())
self.assert_mock_multiple_calls_with_same_arguments(
self.mock_datastore_version_list, 4,
mock.call(test.IsHttpRequest(), test.IsA(str)))
self.mock_configuration_create.assert_called_once_with(
test.IsHttpRequest(),
name,
values,
description=config_description,
datastore=config_datastore,
datastore_version=config_datastore_version)
self.assertNoFormErrors(res) self.assertNoFormErrors(res)
self.assertMessageCount(success=1) self.assertMessageCount(success=1)
@ -133,14 +138,15 @@ class DatabaseConfigurationsTests(test.TestCase):
def test_create_test_configuration_with_no_description(self): def test_create_test_configuration_with_no_description(self):
self._test_create_test_configuration() self._test_create_test_configuration()
@test.create_stubs({ @test.create_mocks({
api.trove: ('datastore_list', 'datastore_version_list', api.trove: ('datastore_list', 'datastore_version_list',
'configuration_create')}) 'configuration_create')})
def test_create_test_configuration_exception(self): def test_create_test_configuration_exception(self):
api.trove.datastore_list(IsA(http.HttpRequest)) \ self.mock_datastore_list.return_value = self.datastores.list()
.AndReturn(self.datastores.list()) self.mock_datastore_version_list.return_value = (
api.trove.datastore_version_list(IsA(http.HttpRequest), IsA(str)) \ self.datastore_versions.list())
.MultipleTimes().AndReturn(self.datastore_versions.list())
self.mock_configuration_create.side_effect = self.exceptions.trove
name = u'config1' name = u'config1'
values = "{}" values = "{}"
@ -150,95 +156,88 @@ class DatabaseConfigurationsTests(test.TestCase):
config_datastore = ds.name config_datastore = ds.name
config_datastore_version = dsv.name config_datastore_version = dsv.name
api.trove.configuration_create(
IsA(http.HttpRequest),
name,
values,
description=config_description,
datastore=config_datastore,
datastore_version=config_datastore_version) \
.AndRaise(self.exceptions.trove)
self.mox.ReplayAll()
post = {'method': 'CreateConfigurationForm', post = {'method': 'CreateConfigurationForm',
'name': name, 'name': name,
'description': config_description, 'description': config_description,
'datastore': config_datastore + ',' + config_datastore_version} 'datastore': config_datastore + ',' + config_datastore_version}
res = self.client.post(CREATE_URL, post) res = self.client.post(CREATE_URL, post)
self.mock_datastore_list.assert_called_once_with(test.IsHttpRequest())
self.assert_mock_multiple_calls_with_same_arguments(
self.mock_datastore_version_list, 4,
mock.call(test.IsHttpRequest(), test.IsA(str)))
self.mock_configuration_create.assert_called_once_with(
test.IsHttpRequest(),
name,
values,
description=config_description,
datastore=config_datastore,
datastore_version=config_datastore_version)
self.assertRedirectsNoFollow(res, INDEX_URL) self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.trove: ('configuration_get', @test.create_mocks({api.trove: ('configuration_get',
'configuration_instances',)}) 'configuration_instances',)})
def test_details_tab(self): def test_details_tab(self):
config = self.database_configurations.first() config = self.database_configurations.first()
api.trove.configuration_get(IsA(http.HttpRequest), self.mock_configuration_get.return_value = config
config.id) \
.AndReturn(config)
self.mox.ReplayAll()
details_url = self._get_url_with_arg(DETAIL_URL, config.id) details_url = self._get_url_with_arg(DETAIL_URL, config.id)
url = details_url + '?tab=configuration_details__details' url = details_url + '?tab=configuration_details__details'
res = self.client.get(url) res = self.client.get(url)
self.mock_configuration_get.assert_called_once_with(
test.IsHttpRequest(), config.id)
self.assertTemplateUsed(res, self.assertTemplateUsed(res,
'project/database_configurations/details.html') 'project/database_configurations/details.html')
@test.create_stubs({api.trove: ('configuration_get',)}) @test.create_mocks({api.trove: ('configuration_get',)})
def test_overview_tab_exception(self): def test_overview_tab_exception(self):
config = self.database_configurations.first() config = self.database_configurations.first()
api.trove.configuration_get(IsA(http.HttpRequest), self.mock_configuration_get.side_effect = self.exceptions.trove
config.id) \
.AndRaise(self.exceptions.trove)
self.mox.ReplayAll()
details_url = self._get_url_with_arg(DETAIL_URL, config.id) details_url = self._get_url_with_arg(DETAIL_URL, config.id)
url = details_url + '?tab=configuration_details__overview' url = details_url + '?tab=configuration_details__overview'
res = self.client.get(url) res = self.client.get(url)
self.mock_configuration_get.assert_called_once_with(
test.IsHttpRequest(), config.id)
self.assertRedirectsNoFollow(res, INDEX_URL) self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({ @test.create_mocks({
api.trove: ('configuration_get', 'configuration_parameters_list',), api.trove: ('configuration_parameters_list',),
config_param_manager.ConfigParamManager: config_param_manager.ConfigParamManager:
('get_configuration', 'configuration_get',)}) ('get_configuration', 'configuration_get',)})
def test_add_parameter(self): def test_add_parameter(self):
config = config_param_manager.ConfigParamManager.get_configuration() \ config = self.database_configurations.first()
.AndReturn(self.database_configurations.first()) self.mock_get_configuration.return_value = config
config_param_manager.ConfigParamManager \ self.mock_configuration_get.return_value = config
.configuration_get(IsA(http.HttpRequest)) \
.AndReturn(config)
ds = self._get_test_datastore('mysql') ds = self._get_test_datastore('mysql')
dsv = self._get_test_datastore_version(ds.id, '5.5') dsv = self._get_test_datastore_version(ds.id, '5.5')
api.trove.configuration_parameters_list( self.mock_configuration_parameters_list.return_value = (
IsA(http.HttpRequest), self.configuration_parameters.list())
ds.name,
dsv.name) \
.AndReturn(self.configuration_parameters.list())
self.mox.ReplayAll()
res = self.client.get(self._get_url_with_arg(ADD_URL, 'id')) res = self.client.get(self._get_url_with_arg(ADD_URL, 'id'))
self.mock_get_configuration.assert_called_once()
self.mock_configuration_get.assert_called_once_with(
test.IsHttpRequest())
self.mock_configuration_parameters_list.assert_called_once_with(
test.IsHttpRequest(),
ds.name,
dsv.name)
self.assertTemplateUsed( self.assertTemplateUsed(
res, 'project/database_configurations/add_parameter.html') res, 'project/database_configurations/add_parameter.html')
@test.create_stubs({ @test.create_mocks({
api.trove: ('configuration_get', 'configuration_parameters_list',), api.trove: ('configuration_parameters_list',),
config_param_manager.ConfigParamManager: config_param_manager.ConfigParamManager:
('get_configuration', 'configuration_get',)}) ('get_configuration', 'configuration_get',)})
def test_add_parameter_exception_on_parameters(self): def test_add_parameter_exception_on_parameters(self):
try: try:
config = (config_param_manager.ConfigParamManager config = self.database_configurations.first()
.get_configuration() self.mock_get_configuration.return_value = config
.AndReturn(self.database_configurations.first()))
config_param_manager.ConfigParamManager \ self.mock_configuration_get.return_value = config
.configuration_get(IsA(http.HttpRequest)) \
.AndReturn(config)
ds = self._get_test_datastore('mysql') ds = self._get_test_datastore('mysql')
dsv = self._get_test_datastore_version(ds.id, '5.5') dsv = self._get_test_datastore_version(ds.id, '5.5')
api.trove.configuration_parameters_list( self.mock_configuration_parameters_list.side_effect = (
IsA(http.HttpRequest), self.exceptions.trove)
ds.name,
dsv.name) \
.AndRaise(self.exceptions.trove)
self.mox.ReplayAll()
toSuppress = ["trove_dashboard.content." toSuppress = ["trove_dashboard.content."
"database_configurations.forms", ] "database_configurations.forms", ]
@ -252,6 +251,14 @@ class DatabaseConfigurationsTests(test.TestCase):
try: try:
res = self.client.get( res = self.client.get(
self._get_url_with_arg(ADD_URL, config.id)) self._get_url_with_arg(ADD_URL, config.id))
self.mock_get_configuration.assert_called_once()
self.mock_configuration_get.assert_called_once_with(
test.IsHttpRequest())
(self.mock_configuration_parameters_list
.assert_called_once_with(
test.IsHttpRequest(),
ds.name,
dsv.name))
self.assertEqual(res.status_code, 302) self.assertEqual(res.status_code, 302)
finally: finally:
@ -261,34 +268,26 @@ class DatabaseConfigurationsTests(test.TestCase):
finally: finally:
config_param_manager.delete(config.id) config_param_manager.delete(config.id)
@test.create_stubs({ @test.create_mocks({
api.trove: ('configuration_get', 'configuration_parameters_list',), api.trove: ('configuration_parameters_list',),
config_param_manager.ConfigParamManager: config_param_manager.ConfigParamManager:
('get_configuration', 'add_param', 'configuration_get',)}) ('get_configuration', 'add_param', 'configuration_get',)})
def test_add_new_parameter(self): def test_add_new_parameter(self):
config = (config_param_manager.ConfigParamManager config = self.database_configurations.first()
.get_configuration() self.mock_get_configuration.return_value = config
.AndReturn(self.database_configurations.first()))
try: try:
config_param_manager.ConfigParamManager \ self.mock_configuration_get.return_value = config
.configuration_get(IsA(http.HttpRequest)) \
.AndReturn(config)
ds = self._get_test_datastore('mysql') ds = self._get_test_datastore('mysql')
dsv = self._get_test_datastore_version(ds.id, '5.5') dsv = self._get_test_datastore_version(ds.id, '5.5')
api.trove.configuration_parameters_list( self.mock_configuration_parameters_list.return_value = (
IsA(http.HttpRequest), self.configuration_parameters.list())
ds.name,
dsv.name) \
.AndReturn(self.configuration_parameters.list())
name = self.configuration_parameters.first().name name = self.configuration_parameters.first().name
value = 1 value = 1
config_param_manager.ConfigParamManager.add_param(name, value) \ self.mock_add_param.return_value = value
.AndReturn(value)
self.mox.ReplayAll()
post = { post = {
'method': 'AddParameterForm', 'method': 'AddParameterForm',
'name': name, 'name': name,
@ -296,12 +295,20 @@ class DatabaseConfigurationsTests(test.TestCase):
res = self.client.post(self._get_url_with_arg(ADD_URL, config.id), res = self.client.post(self._get_url_with_arg(ADD_URL, config.id),
post) post)
self.mock_get_configuration.assert_called_once()
self.mock_configuration_get.assert_called_once_with(
test.IsHttpRequest())
self.mock_configuration_parameters_list.assert_called_once_with(
test.IsHttpRequest(),
ds.name,
dsv.name)
self.mock_add_param.assert_called_once_with(name, value)
self.assertNoFormErrors(res) self.assertNoFormErrors(res)
self.assertMessageCount(success=1) self.assertMessageCount(success=1)
finally: finally:
config_param_manager.delete(config.id) config_param_manager.delete(config.id)
@test.create_stubs({ @test.create_mocks({
api.trove: ('configuration_get', 'configuration_parameters_list',), api.trove: ('configuration_get', 'configuration_parameters_list',),
config_param_manager: ('get',)}) config_param_manager: ('get',)})
def test_add_parameter_invalid_value(self): def test_add_parameter_invalid_value(self):
@ -315,20 +322,13 @@ class DatabaseConfigurationsTests(test.TestCase):
config_param_mgr.original_configuration_values = \ config_param_mgr.original_configuration_values = \
dict.copy(config.values) dict.copy(config.values)
(config_param_manager.get(IsA(http.HttpRequest), self.mock_get.return_value = config_param_mgr
IsA(six.string_types)) self.mock_configuration_parameters_list.return_value = (
.MultipleTimes() self.configuration_parameters.list())
.AndReturn(config_param_mgr))
(api.trove.configuration_parameters_list(IsA(http.HttpRequest),
IsA(six.string_types),
IsA(six.string_types))
.MultipleTimes()
.AndReturn(self.configuration_parameters.list()))
name = self.configuration_parameters.first().name name = self.configuration_parameters.first().name
value = "non-numeric" value = "non-numeric"
self.mox.ReplayAll()
post = { post = {
'method': 'AddParameterForm', 'method': 'AddParameterForm',
'name': name, 'name': name,
@ -336,19 +336,25 @@ class DatabaseConfigurationsTests(test.TestCase):
res = self.client.post(self._get_url_with_arg(ADD_URL, config.id), res = self.client.post(self._get_url_with_arg(ADD_URL, config.id),
post) post)
self.assert_mock_multiple_calls_with_same_arguments(
self.mock_get, 2,
mock.call(test.IsHttpRequest(), test.IsA(six.string_types)))
self.assert_mock_multiple_calls_with_same_arguments(
self.mock_configuration_parameters_list, 2,
mock.call(test.IsHttpRequest(),
test.IsA(six.string_types),
test.IsA(six.string_types)))
self.assertFormError(res, "form", 'value', self.assertFormError(res, "form", 'value',
['Value must be a number.']) ['Value must be a number.'])
finally: finally:
config_param_manager.delete(config.id) config_param_manager.delete(config.id)
@test.create_stubs({api.trove: ('configuration_get', @test.create_mocks({api.trove: ('configuration_get',
'configuration_instances',)}) 'configuration_instances',)})
def test_values_tab_discard_action(self): def test_values_tab_discard_action(self):
config = self.database_configurations.first() config = self.database_configurations.first()
api.trove.configuration_get(IsA(http.HttpRequest), config.id) \ self.mock_configuration_get.return_value = config
.MultipleTimes().AndReturn(config)
self.mox.ReplayAll()
details_url = self._get_url_with_arg(DETAIL_URL, config.id) details_url = self._get_url_with_arg(DETAIL_URL, config.id)
url = details_url + '?tab=configuration_details__value' url = details_url + '?tab=configuration_details__value'
@ -361,6 +367,8 @@ class DatabaseConfigurationsTests(test.TestCase):
.get_configuration().values) .get_configuration().values)
res = self.client.post(url, {'action': u"values__discard_changes"}) res = self.client.post(url, {'action': u"values__discard_changes"})
self.mock_configuration_get.assert_called_once_with(
test.IsHttpRequest(), config.id)
if django.VERSION >= (1, 9): if django.VERSION >= (1, 9):
url = settings.TESTSERVER + url url = settings.TESTSERVER + url
self.assertRedirectsNoFollow(res, url) self.assertRedirectsNoFollow(res, url)
@ -373,7 +381,7 @@ class DatabaseConfigurationsTests(test.TestCase):
self.assertTrue(config_param_manager.dict_has_changes( self.assertTrue(config_param_manager.dict_has_changes(
changed_configuration_values, restored_configuration_values)) changed_configuration_values, restored_configuration_values))
@test.create_stubs({api.trove: ('configuration_instances', @test.create_mocks({api.trove: ('configuration_instances',
'configuration_update',), 'configuration_update',),
config_param_manager: ('get',)}) config_param_manager: ('get',)})
def test_values_tab_apply_action(self): def test_values_tab_apply_action(self):
@ -405,15 +413,9 @@ class DatabaseConfigurationsTests(test.TestCase):
config_param_mgr.original_configuration_values = \ config_param_mgr.original_configuration_values = \
dict.copy(config.values) dict.copy(config.values)
config_param_manager.get(IsA(http.HttpRequest), config.id) \ self.mock_get.return_value = config_param_mgr
.MultipleTimes().AndReturn(config_param_mgr)
api.trove.configuration_update( self.mock_configuration_update.return_value = None
IsA(http.HttpRequest),
config.id,
config_param_mgr.to_json()) \
.AndReturn(None)
self.mox.ReplayAll()
details_url = self._get_url_with_arg(DETAIL_URL, config.id) details_url = self._get_url_with_arg(DETAIL_URL, config.id)
url = details_url + '?tab=configuration_details__value' url = details_url + '?tab=configuration_details__value'
@ -422,11 +424,17 @@ class DatabaseConfigurationsTests(test.TestCase):
# apply changes # apply changes
res = self.client.post(url, {'action': u"values__apply_changes"}) res = self.client.post(url, {'action': u"values__apply_changes"})
self.assert_mock_multiple_calls_with_same_arguments(
self.mock_get, 11, mock.call(test.IsHttpRequest(), config.id))
self.mock_configuration_update.assert_called_once_with(
test.IsHttpRequest(),
config.id,
config_param_mgr.to_json())
if django.VERSION >= (1, 9): if django.VERSION >= (1, 9):
url = settings.TESTSERVER + url url = settings.TESTSERVER + url
self.assertRedirectsNoFollow(res, url) self.assertRedirectsNoFollow(res, url)
@test.create_stubs({api.trove: ('configuration_instances', @test.create_mocks({api.trove: ('configuration_instances',
'configuration_update',), 'configuration_update',),
config_param_manager: ('get',)}) config_param_manager: ('get',)})
def test_values_tab_apply_action_exception(self): def test_values_tab_apply_action_exception(self):
@ -448,15 +456,9 @@ class DatabaseConfigurationsTests(test.TestCase):
config_param_mgr.original_configuration_values = \ config_param_mgr.original_configuration_values = \
dict.copy(config.values) dict.copy(config.values)
config_param_manager.get(IsA(http.HttpRequest), config.id) \ self.mock_get.return_value = config_param_mgr
.MultipleTimes().AndReturn(config_param_mgr)
api.trove.configuration_update( self.mock_configuration_update.side_effect = self.exceptions.trove
IsA(http.HttpRequest),
config.id,
config_param_mgr.to_json())\
.AndRaise(self.exceptions.trove)
self.mox.ReplayAll()
details_url = self._get_url_with_arg(DETAIL_URL, config.id) details_url = self._get_url_with_arg(DETAIL_URL, config.id)
url = details_url + '?tab=configuration_details__value' url = details_url + '?tab=configuration_details__value'
@ -465,6 +467,12 @@ class DatabaseConfigurationsTests(test.TestCase):
# apply changes # apply changes
res = self.client.post(url, {'action': u"values__apply_changes"}) res = self.client.post(url, {'action': u"values__apply_changes"})
self.assert_mock_multiple_calls_with_same_arguments(
self.mock_get, 11, mock.call(test.IsHttpRequest(), config.id))
self.mock_configuration_update.assert_called_once_with(
test.IsHttpRequest(),
config.id,
config_param_mgr.to_json())
if django.VERSION >= (1, 9): if django.VERSION >= (1, 9):
url = settings.TESTSERVER + url url = settings.TESTSERVER + url
self.assertRedirectsNoFollow(res, url) self.assertRedirectsNoFollow(res, url)
@ -491,7 +499,7 @@ class DatabaseConfigurationsTests(test.TestCase):
self.assertEqual((number_params - 1), new_number_params) self.assertEqual((number_params - 1), new_number_params)
@test.create_stubs({api.trove: ('configuration_instances',), @test.create_mocks({api.trove: ('configuration_instances',),
config_param_manager: ('get',)}) config_param_manager: ('get',)})
def test_instances_tab(self): def test_instances_tab(self):
try: try:
@ -504,18 +512,19 @@ class DatabaseConfigurationsTests(test.TestCase):
config_param_mgr.original_configuration_values = \ config_param_mgr.original_configuration_values = \
dict.copy(config.values) dict.copy(config.values)
config_param_manager.get(IsA(http.HttpRequest), config.id) \ self.mock_get.return_value = config_param_mgr
.MultipleTimes().AndReturn(config_param_mgr)
api.trove.configuration_instances(IsA(http.HttpRequest), self.mock_configuration_instances.return_value = (
config.id)\ self.configuration_instances.list())
.AndReturn(self.configuration_instances.list())
self.mox.ReplayAll()
details_url = self._get_url_with_arg(DETAIL_URL, config.id) details_url = self._get_url_with_arg(DETAIL_URL, config.id)
url = details_url + '?tab=configuration_details__instance' url = details_url + '?tab=configuration_details__instance'
res = self.client.get(url) res = self.client.get(url)
self.assert_mock_multiple_calls_with_same_arguments(
self.mock_get, 2, mock.call(test.IsHttpRequest(), config.id))
self.mock_configuration_instances.assert_called_once_with(
test.IsHttpRequest(), config.id)
table_data = res.context['instances_table'].data table_data = res.context['instances_table'].data
self.assertItemsEqual( self.assertItemsEqual(
self.configuration_instances.list(), table_data) self.configuration_instances.list(), table_data)
@ -524,7 +533,7 @@ class DatabaseConfigurationsTests(test.TestCase):
finally: finally:
config_param_manager.delete(config.id) config_param_manager.delete(config.id)
@test.create_stubs({api.trove: ('configuration_instances',), @test.create_mocks({api.trove: ('configuration_instances',),
config_param_manager: ('get',)}) config_param_manager: ('get',)})
def test_instances_tab_exception(self): def test_instances_tab_exception(self):
try: try:
@ -537,18 +546,19 @@ class DatabaseConfigurationsTests(test.TestCase):
config_param_mgr.original_configuration_values = \ config_param_mgr.original_configuration_values = \
dict.copy(config.values) dict.copy(config.values)
config_param_manager.get(IsA(http.HttpRequest), config.id) \ self.mock_get.return_value = config_param_mgr
.MultipleTimes().AndReturn(config_param_mgr)
api.trove.configuration_instances(IsA(http.HttpRequest), self.mock_configuration_instances.side_effect = (
config.id) \ self.exceptions.trove)
.AndRaise(self.exceptions.trove)
self.mox.ReplayAll()
details_url = self._get_url_with_arg(DETAIL_URL, config.id) details_url = self._get_url_with_arg(DETAIL_URL, config.id)
url = details_url + '?tab=configuration_details__instance' url = details_url + '?tab=configuration_details__instance'
res = self.client.get(url) res = self.client.get(url)
self.assert_mock_multiple_calls_with_same_arguments(
self.mock_get, 2, mock.call(test.IsHttpRequest(), config.id))
self.mock_configuration_instances.assert_called_once_with(
test.IsHttpRequest(), config.id)
table_data = res.context['instances_table'].data table_data = res.context['instances_table'].data
self.assertNotEqual(len(self.configuration_instances.list()), self.assertNotEqual(len(self.configuration_instances.list()),
len(table_data)) len(table_data))