Mox removal for DataProcessingJobTests

Apart of the mox3 community goal for Rocky.

Change-Id: I90bde341d5a1c1ede967a76633385d336f2c563f
Signed-off-by: Charles Short <zulcss@gmail.com>
This commit is contained in:
Charles Short 2018-04-19 21:58:41 -04:00
parent 70f665b9f7
commit 787cc08789
2 changed files with 27 additions and 16 deletions

View File

@ -10,13 +10,11 @@
# 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 six
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.jobs:index')
@ -25,15 +23,20 @@ DETAILS_URL = reverse(
class DataProcessingJobTests(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.job_execution_list(IsA(http.HttpRequest), {}) \
.AndReturn(self.job_executions.list())
self.mox.ReplayAll()
self.mock_job_execution_list.return_value = \
self.job_executions.list()
res = self.client.get(INDEX_URL)
self.mock_job_execution_list.assert_called_once_with(
IsHttpRequest(), {})
self.assertEqual(
"cluster-1",
(res.context_data["tab_group"]._tabs["jobs_tab"].
@ -45,28 +48,30 @@ class DataProcessingJobTests(test.TestCase):
self.assertTemplateUsed(res, 'jobs/index.html')
self.assertContains(res, 'Jobs')
@test.create_stubs({api.sahara: ('job_execution_get',
@test.create_mocks({api.sahara: ('job_execution_get',
'cluster_get', 'job_get',
'data_source_get')})
def test_details(self):
api.sahara.job_execution_get(IsA(http.HttpRequest), IsA(six.text_type)) \
.MultipleTimes().AndReturn(self.job_executions.first())
self.mox.ReplayAll()
self.mock_job_execution_get.return_value = (
self.job_executions.first())
res = self.client.get(DETAILS_URL)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
self.assertContains(res, 'RUNNING')
@test.create_stubs({api.sahara: ('job_execution_list',
@test.create_mocks({api.sahara: ('job_execution_list',
'job_execution_delete')})
def test_delete(self):
job_exec = self.job_executions.first()
api.sahara.job_execution_list(IsA(http.HttpRequest), {}) \
.AndReturn(self.job_executions.list())
api.sahara.job_execution_delete(IsA(http.HttpRequest), job_exec.id)
self.mox.ReplayAll()
self.mock_job_execution_list.return_value = self.job_executions.list()
self.mock_job_execution_delete.return_value = None
form_data = {'action': 'jobs__delete__%s' % job_exec.id}
res = self.client.post(INDEX_URL, form_data)
self.mock_job_execution_list.assert_called_once_with(
IsHttpRequest(), {})
self.mock_job_execution_delete.assert_called_once_with(
IsHttpRequest(), job_exec.id)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)

View File

@ -20,6 +20,12 @@ from openstack_dashboard.test import helpers
from sahara_dashboard import api
from sahara_dashboard.test.test_data import utils
# Shortcuts to avoid importing openstack_dashboard.test.helper and
# for backwards compatibility.
create_mocks = helpers.create_mocks
IsA = helpers.IsA
IsHttpRequest = helpers.IsHttpRequest
def create_stubs(stubs_to_create={}):
return helpers.create_stubs(stubs_to_create)