Merge "Remove mox3 from DataProcessingImageRegistryTests"
This commit is contained in:
commit
656e265b27
|
@ -10,14 +10,13 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django import http
|
||||
from django.urls import reverse
|
||||
from mox3.mox import IsA # noqa
|
||||
|
||||
from openstack_dashboard import api as dash_api
|
||||
|
||||
from sahara_dashboard import api
|
||||
from sahara_dashboard.test import helpers as test
|
||||
from sahara_dashboard.test.helpers import IsHttpRequest
|
||||
|
||||
INDEX_URL = reverse(
|
||||
'horizon:project:data_processing.clusters:image-registry-tab')
|
||||
|
@ -28,23 +27,26 @@ SUCCESS_URL = reverse(
|
|||
|
||||
|
||||
class DataProcessingImageRegistryTests(test.TestCase):
|
||||
@test.create_stubs({api.sahara: ('cluster_template_list',
|
||||
|
||||
use_mox = False
|
||||
|
||||
@test.create_mocks({api.sahara: ('cluster_template_list',
|
||||
'image_list',
|
||||
'cluster_list',
|
||||
'nodegroup_template_list')})
|
||||
def test_index(self):
|
||||
api.sahara.image_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.images.list())
|
||||
self.mox.ReplayAll()
|
||||
self.mock_image_list.return_value = self.images.list()
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
|
||||
self.mock_image_list.assert_called_once_with(
|
||||
IsHttpRequest())
|
||||
self.assertTemplateUsed(res, 'clusters/index.html')
|
||||
self.assertContains(res, 'Image Registry')
|
||||
self.assertContains(res, 'Image')
|
||||
self.assertContains(res, 'Tags')
|
||||
|
||||
@test.create_stubs({api.sahara: ('image_get',
|
||||
@test.create_mocks({api.sahara: ('image_get',
|
||||
'image_update',
|
||||
'image_tags_update',
|
||||
'image_list'),
|
||||
|
@ -54,24 +56,12 @@ class DataProcessingImageRegistryTests(test.TestCase):
|
|||
image_id = image.id
|
||||
test_username = 'myusername'
|
||||
test_description = 'mydescription'
|
||||
api.sahara.image_get(IsA(http.HttpRequest),
|
||||
image_id).MultipleTimes().AndReturn(image)
|
||||
dash_api.glance.image_list_detailed(IsA(http.HttpRequest),
|
||||
filters={'owner': self.user.id,
|
||||
'status': 'active'}) \
|
||||
.AndReturn((self.images.list(), False, False))
|
||||
api.sahara.image_update(IsA(http.HttpRequest),
|
||||
image_id,
|
||||
test_username,
|
||||
test_description) \
|
||||
.AndReturn(True)
|
||||
api.sahara.image_tags_update(IsA(http.HttpRequest),
|
||||
image_id,
|
||||
{}) \
|
||||
.AndReturn(True)
|
||||
api.sahara.image_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn([])
|
||||
self.mox.ReplayAll()
|
||||
self.mock_image_get.return_value = image
|
||||
self.mock_image_list_detailed.return_value = (
|
||||
self.images.list(), False, False)
|
||||
self.mock_image_update.return_value = True
|
||||
self.mock_image_tags_update.return_value = True
|
||||
self.mock_image_list.return_value = []
|
||||
|
||||
res = self.client.post(
|
||||
REGISTER_URL,
|
||||
|
@ -80,43 +70,46 @@ class DataProcessingImageRegistryTests(test.TestCase):
|
|||
'description': test_description,
|
||||
'tags_list': '{}'})
|
||||
|
||||
self.mock_image_list_detailed.assert_called_once_with(
|
||||
IsHttpRequest(),
|
||||
filters={'owner': self.user.id,
|
||||
'status': 'active'})
|
||||
self.mock_image_update.assert_called_once_with(
|
||||
IsHttpRequest(), image_id, test_username, test_description)
|
||||
self.mock_image_tags_update.assert_called_once_with(
|
||||
IsHttpRequest(), image_id, {})
|
||||
self.mock_image_list.assert_called_once_with(
|
||||
IsHttpRequest())
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, SUCCESS_URL)
|
||||
self.assertMessageCount(success=1)
|
||||
|
||||
@test.create_stubs({api.sahara: ('image_list',
|
||||
@test.create_mocks({api.sahara: ('image_list',
|
||||
'image_unregister')})
|
||||
def test_unregister(self):
|
||||
image = self.images.first()
|
||||
api.sahara.image_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.images.list())
|
||||
api.sahara.image_unregister(IsA(http.HttpRequest), image.id)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_image_list.return_value = self.images.list()
|
||||
self.mock_image_unregister.return_value = None
|
||||
|
||||
form_data = {'action': 'image_registry__unregister__%s' % image.id}
|
||||
res = self.client.post(INDEX_URL, form_data)
|
||||
|
||||
self.mock_image_list.assert_called_once_with(
|
||||
IsHttpRequest())
|
||||
self.mock_image_unregister.assert_called_once_with(
|
||||
IsHttpRequest(), image.id)
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
self.assertMessageCount(success=1)
|
||||
|
||||
@test.create_stubs({api.sahara: ('image_get',
|
||||
@test.create_mocks({api.sahara: ('image_get',
|
||||
'image_update',
|
||||
'image_tags_update')})
|
||||
def test_edit_tags(self):
|
||||
image = self.registered_images.first()
|
||||
api.sahara.image_get(IsA(http.HttpRequest),
|
||||
image.id).MultipleTimes().AndReturn(image)
|
||||
api.sahara.image_update(IsA(http.HttpRequest),
|
||||
image.id,
|
||||
image.username,
|
||||
image.description) \
|
||||
.AndReturn(True)
|
||||
api.sahara.image_tags_update(IsA(http.HttpRequest),
|
||||
image.id,
|
||||
{"0": "mytag"}) \
|
||||
.AndReturn(True)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_image_get.return_value = image
|
||||
self.mock_image_update.return_value = True
|
||||
self.mock_image_tags_update.return_value = True
|
||||
|
||||
edit_tags_url = reverse(
|
||||
'horizon:project:data_processing.clusters:edit_tags',
|
||||
|
@ -128,6 +121,11 @@ class DataProcessingImageRegistryTests(test.TestCase):
|
|||
'description': image.description,
|
||||
'tags_list': '{"0": "mytag"}'})
|
||||
|
||||
self.mock_image_update.assert_called_once_with(
|
||||
IsHttpRequest(), image.id, image.username,
|
||||
image.description)
|
||||
self.mock_image_tags_update.assert_called_once_with(
|
||||
IsHttpRequest(), image.id, {"0": "mytag"})
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, SUCCESS_URL)
|
||||
self.assertMessageCount(success=1)
|
||||
|
|
Loading…
Reference in New Issue