Mox removal for DataProcessingDataSourceTests
Apart of the mox3 community goal for Rocky. Change-Id: Ida0570b57eaa73dbefe8ebd49809e102843758e7 Signed-off-by: Charles Short <zulcss@gmail.com>
This commit is contained in:
parent
787cc08789
commit
40567677ca
|
@ -10,13 +10,14 @@
|
|||
# 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
|
||||
import mock
|
||||
import six
|
||||
|
||||
from sahara_dashboard import api
|
||||
from sahara_dashboard.test import helpers as test
|
||||
from sahara_dashboard.test.helpers import IsA
|
||||
from sahara_dashboard.test.helpers import IsHttpRequest
|
||||
|
||||
INDEX_URL = reverse('horizon:project:data_processing.jobs:index')
|
||||
DETAILS_URL = reverse(
|
||||
|
@ -29,60 +30,54 @@ EDIT_URL = reverse(
|
|||
|
||||
|
||||
class DataProcessingDataSourceTests(test.TestCase):
|
||||
@test.create_stubs({api.sahara: ('job_execution_list',
|
||||
|
||||
use_mox = False
|
||||
|
||||
@test.create_mocks({api.sahara: ('job_execution_list',
|
||||
'plugin_list', 'job_binary_list',
|
||||
'data_source_list',
|
||||
'job_list')})
|
||||
def test_index(self):
|
||||
api.sahara.data_source_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.data_sources.list())
|
||||
self.mox.ReplayAll()
|
||||
self.mock_data_source_list.return_value = self.data_sources.list()
|
||||
res = self.client.get(INDEX_URL)
|
||||
self.mock_data_source_list.assert_called_once_with(
|
||||
IsHttpRequest())
|
||||
self.assertTemplateUsed(res, 'jobs/index.html')
|
||||
self.assertContains(res, 'Data Sources')
|
||||
self.assertContains(res, 'Name')
|
||||
self.assertContains(res, 'sampleOutput')
|
||||
self.assertContains(res, 'sampleOutput2')
|
||||
|
||||
@test.create_stubs({api.sahara: ('data_source_get',)})
|
||||
@test.create_mocks({api.sahara: ('data_source_get',)})
|
||||
def test_details(self):
|
||||
api.sahara.data_source_get(IsA(http.HttpRequest), IsA(six.text_type)) \
|
||||
.MultipleTimes().AndReturn(self.data_sources.first())
|
||||
self.mox.ReplayAll()
|
||||
self.mock_data_source_get.return_value = self.data_sources.first()
|
||||
res = self.client.get(DETAILS_URL)
|
||||
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
|
||||
self.assertContains(res, 'sampleOutput')
|
||||
|
||||
@test.create_stubs({api.sahara: ('data_source_list',
|
||||
@test.create_mocks({api.sahara: ('data_source_list',
|
||||
'data_source_delete')})
|
||||
def test_delete(self):
|
||||
data_source = self.data_sources.first()
|
||||
api.sahara.data_source_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.data_sources.list())
|
||||
api.sahara.data_source_delete(IsA(http.HttpRequest), data_source.id)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_data_source_list.return_value = self.data_sources.list()
|
||||
self.mock_data_source_delete.return_value = None
|
||||
|
||||
form_data = {'action': 'data_sources__delete__%s' % data_source.id}
|
||||
res = self.client.post(INDEX_URL, form_data)
|
||||
|
||||
self.mock_data_source_list.assert_called_once_with(
|
||||
IsHttpRequest())
|
||||
self.mock_data_source_delete.assert_called_once_with(
|
||||
IsHttpRequest(), data_source.id)
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
self.assertMessageCount(success=1)
|
||||
|
||||
@test.create_stubs({api.sahara: ('data_source_create',)})
|
||||
@test.create_mocks({api.sahara: ('data_source_create',)})
|
||||
def test_create(self):
|
||||
data_source = self.data_sources.first()
|
||||
api.sahara.data_source_create(IsA(http.HttpRequest),
|
||||
data_source.name,
|
||||
data_source.description,
|
||||
data_source.type,
|
||||
data_source.url,
|
||||
"",
|
||||
"",
|
||||
is_public=False,
|
||||
is_protected=False) \
|
||||
.AndReturn(self.data_sources.first())
|
||||
self.mox.ReplayAll()
|
||||
self.mock_data_source_create.return_value = \
|
||||
self.data_sources.first()
|
||||
form_data = {
|
||||
'data_source_url': data_source.url,
|
||||
'data_source_name': data_source.name,
|
||||
|
@ -92,11 +87,23 @@ class DataProcessingDataSourceTests(test.TestCase):
|
|||
'is_protected': False,
|
||||
}
|
||||
res = self.client.post(CREATE_URL, form_data)
|
||||
|
||||
self.mock_data_source_create.assert_called_once_with(
|
||||
IsHttpRequest(),
|
||||
data_source.name,
|
||||
data_source.description,
|
||||
data_source.type,
|
||||
data_source.url,
|
||||
"",
|
||||
"",
|
||||
is_public=False,
|
||||
is_protected=False)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
self.assertMessageCount(success=1)
|
||||
|
||||
@test.create_stubs({api.sahara: ('data_source_update',
|
||||
@test.create_mocks({api.sahara: ('data_source_update',
|
||||
'data_source_get',)})
|
||||
def test_edit(self):
|
||||
data_source = self.data_sources.first()
|
||||
|
@ -109,14 +116,8 @@ class DataProcessingDataSourceTests(test.TestCase):
|
|||
'is_public': False,
|
||||
'is_protected': False,
|
||||
}
|
||||
api.sahara.data_source_get(IsA(http.HttpRequest),
|
||||
IsA(six.text_type)) \
|
||||
.AndReturn(self.data_sources.first())
|
||||
api.sahara.data_source_update(IsA(http.HttpRequest),
|
||||
IsA(six.text_type),
|
||||
api_data) \
|
||||
.AndReturn(self.data_sources.first())
|
||||
self.mox.ReplayAll()
|
||||
self.mock_data_source_get.return_value = self.data_sources.first()
|
||||
self.mock_data_source_update.return_value = self.data_sources.first()
|
||||
|
||||
form_data = {
|
||||
'data_source_url': data_source.url,
|
||||
|
@ -126,29 +127,27 @@ class DataProcessingDataSourceTests(test.TestCase):
|
|||
}
|
||||
res = self.client.post(EDIT_URL, form_data)
|
||||
|
||||
self.mock_data_source_get.assert_called_once_with(
|
||||
IsHttpRequest(), IsA(six.text_type))
|
||||
self.mock_data_source_update.assert_called_once_with(
|
||||
IsHttpRequest(), IsA(six.text_type), api_data)
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
self.assertMessageCount(success=1)
|
||||
|
||||
@test.create_stubs({api.manila: ('share_list', ),
|
||||
@test.create_mocks({api.manila: ('share_list', ),
|
||||
api.sahara: ('data_source_create', ),
|
||||
api.sahara.base: ('is_service_enabled', )})
|
||||
def test_create_manila(self):
|
||||
share = self.mox.CreateMockAnything()
|
||||
share.id = "tuvwxy56-1234-abcd-abcd-defabcdaedcb"
|
||||
share.name = "Test Share"
|
||||
share = mock.Mock()
|
||||
share.return_value = {
|
||||
'id': 'tuvwxy56-1234-abcd-abcd-defabcdaedcb',
|
||||
'name': 'Test Share'
|
||||
}
|
||||
shares = [share]
|
||||
api.sahara.base.is_service_enabled(IsA(http.HttpRequest), IsA(str)) \
|
||||
.AndReturn(True)
|
||||
api.sahara.data_source_create(IsA(http.HttpRequest),
|
||||
IsA(six.text_type),
|
||||
IsA(six.text_type),
|
||||
IsA(six.text_type),
|
||||
IsA(str),
|
||||
"", "", is_public=False,
|
||||
is_protected=False).AndReturn(True)
|
||||
api.manila.share_list(IsA(http.HttpRequest)).AndReturn(shares)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_is_service_enabled.return_value = True
|
||||
self.mock_data_source_create.return_value = True
|
||||
self.mock_share_list.return_value = shares
|
||||
|
||||
form_data = {
|
||||
"data_source_type": "manila",
|
||||
|
@ -159,4 +158,14 @@ class DataProcessingDataSourceTests(test.TestCase):
|
|||
}
|
||||
|
||||
res = self.client.post(CREATE_URL, form_data)
|
||||
self.mock_is_service_enabled.assert_called_once_with(
|
||||
IsHttpRequest(), IsA(str))
|
||||
self.mock_data_source_create.assert_called_once_with(
|
||||
IsHttpRequest(),
|
||||
IsA(six.text_type),
|
||||
IsA(six.text_type),
|
||||
IsA(six.text_type),
|
||||
IsA(str),
|
||||
"", "", is_public=False, is_protected=False)
|
||||
self.mock_share_list.assert_called_once_with(IsHttpRequest())
|
||||
self.assertNoFormErrors(res)
|
||||
|
|
Loading…
Reference in New Issue