Convert identity.mappings tests into mock
blueprint mock-framework-in-unit-tests Change-Id: Id7d0a2e676ce0110b22238a5bc5713e7f12183fd
This commit is contained in:
parent
db350910e4
commit
a61bbecc72
|
@ -14,12 +14,8 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django import http
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from mox3.mox import IgnoreArg
|
|
||||||
from mox3.mox import IsA
|
|
||||||
|
|
||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
from openstack_dashboard.test import helpers as test
|
from openstack_dashboard.test import helpers as test
|
||||||
|
|
||||||
|
@ -32,31 +28,22 @@ MAPPINGS_UPDATE_URL = reverse('horizon:identity:mappings:update',
|
||||||
|
|
||||||
class MappingsViewTests(test.BaseAdminViewTests):
|
class MappingsViewTests(test.BaseAdminViewTests):
|
||||||
|
|
||||||
use_mox = True
|
@test.create_mocks({api.keystone: ('mapping_list',)})
|
||||||
|
|
||||||
@test.create_stubs({api.keystone: ('mapping_list',)})
|
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
api.keystone.mapping_list(IgnoreArg()). \
|
self.mock_mapping_list.return_value = self.idp_mappings.list()
|
||||||
AndReturn(self.idp_mappings.list())
|
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
|
|
||||||
res = self.client.get(MAPPINGS_INDEX_URL)
|
res = self.client.get(MAPPINGS_INDEX_URL)
|
||||||
|
|
||||||
self.assertTemplateUsed(res, 'horizon/common/_data_table_view.html')
|
self.assertTemplateUsed(res, 'horizon/common/_data_table_view.html')
|
||||||
self.assertItemsEqual(res.context['table'].data,
|
self.assertItemsEqual(res.context['table'].data,
|
||||||
self.idp_mappings.list())
|
self.idp_mappings.list())
|
||||||
|
self.mock_mapping_list.assert_called_once_with(test.IsHttpRequest())
|
||||||
|
|
||||||
@test.create_stubs({api.keystone: ('mapping_create', )})
|
@test.create_mocks({api.keystone: ('mapping_create', )})
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
mapping = self.idp_mappings.first()
|
mapping = self.idp_mappings.first()
|
||||||
|
|
||||||
api.keystone.mapping_create(IgnoreArg(),
|
self.mock_mapping_create.return_value = mapping
|
||||||
mapping.id,
|
|
||||||
rules=mapping.rules). \
|
|
||||||
AndReturn(mapping)
|
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
|
|
||||||
formData = {'method': 'CreateMappingForm',
|
formData = {'method': 'CreateMappingForm',
|
||||||
'id': mapping.id,
|
'id': mapping.id,
|
||||||
|
@ -66,21 +53,18 @@ class MappingsViewTests(test.BaseAdminViewTests):
|
||||||
self.assertNoFormErrors(res)
|
self.assertNoFormErrors(res)
|
||||||
self.assertMessageCount(success=1)
|
self.assertMessageCount(success=1)
|
||||||
|
|
||||||
@test.create_stubs({api.keystone: ('mapping_get',
|
self.mock_mapping_create.assert_called_once_with(test.IsHttpRequest(),
|
||||||
|
mapping.id,
|
||||||
|
rules=mapping.rules)
|
||||||
|
|
||||||
|
@test.create_mocks({api.keystone: ('mapping_get',
|
||||||
'mapping_update')})
|
'mapping_update')})
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
mapping = self.idp_mappings.first()
|
mapping = self.idp_mappings.first()
|
||||||
new_rules = [{"local": [], "remote": []}]
|
new_rules = [{"local": [], "remote": []}]
|
||||||
|
|
||||||
api.keystone.mapping_get(IsA(http.HttpRequest),
|
self.mock_mapping_get.return_value = mapping
|
||||||
mapping.id). \
|
self.mock_mapping_update.return_value = None
|
||||||
AndReturn(mapping)
|
|
||||||
api.keystone.mapping_update(IsA(http.HttpRequest),
|
|
||||||
mapping.id,
|
|
||||||
rules=new_rules). \
|
|
||||||
AndReturn(None)
|
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
|
|
||||||
formData = {'method': 'UpdateMappingForm',
|
formData = {'method': 'UpdateMappingForm',
|
||||||
'id': mapping.id,
|
'id': mapping.id,
|
||||||
|
@ -91,20 +75,25 @@ class MappingsViewTests(test.BaseAdminViewTests):
|
||||||
self.assertNoFormErrors(res)
|
self.assertNoFormErrors(res)
|
||||||
self.assertMessageCount(success=1)
|
self.assertMessageCount(success=1)
|
||||||
|
|
||||||
@test.create_stubs({api.keystone: ('mapping_list',
|
self.mock_mapping_get.assert_called_once_with(test.IsHttpRequest(),
|
||||||
|
mapping.id)
|
||||||
|
self.mock_mapping_update.assert_called_once_with(test.IsHttpRequest(),
|
||||||
|
mapping.id,
|
||||||
|
rules=new_rules)
|
||||||
|
|
||||||
|
@test.create_mocks({api.keystone: ('mapping_list',
|
||||||
'mapping_delete')})
|
'mapping_delete')})
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
mapping = self.idp_mappings.first()
|
mapping = self.idp_mappings.first()
|
||||||
|
|
||||||
api.keystone.mapping_list(IsA(http.HttpRequest)) \
|
self.mock_mapping_list.return_value = self.idp_mappings.list()
|
||||||
.AndReturn(self.idp_mappings.list())
|
self.mock_mapping_delete.return_value = None
|
||||||
api.keystone.mapping_delete(IsA(http.HttpRequest),
|
|
||||||
mapping.id) \
|
|
||||||
.AndReturn(None)
|
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
|
|
||||||
formData = {'action': 'idp_mappings__delete__%s' % mapping.id}
|
formData = {'action': 'idp_mappings__delete__%s' % mapping.id}
|
||||||
res = self.client.post(MAPPINGS_INDEX_URL, formData)
|
res = self.client.post(MAPPINGS_INDEX_URL, formData)
|
||||||
|
|
||||||
self.assertNoFormErrors(res)
|
self.assertNoFormErrors(res)
|
||||||
|
|
||||||
|
self.mock_mapping_list.assert_called_once_with(test.IsHttpRequest())
|
||||||
|
self.mock_mapping_delete.assert_called_once_with(test.IsHttpRequest(),
|
||||||
|
mapping.id)
|
||||||
|
|
Loading…
Reference in New Issue