Merge "Remove mox usage from goal tests"
This commit is contained in:
commit
b73b026e55
|
@ -14,8 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
from django.core import urlresolvers
|
||||
from django import http
|
||||
from mox3.mox import IsA # noqa
|
||||
import mock
|
||||
|
||||
from watcher_dashboard import api
|
||||
from watcher_dashboard.test import helpers as test
|
||||
|
@ -26,38 +25,28 @@ DETAILS_VIEW = 'horizon:admin:goals:detail'
|
|||
|
||||
class GoalsTest(test.BaseAdminViewTests):
|
||||
|
||||
@test.create_stubs({api.watcher.Goal: ('list',)})
|
||||
def test_index(self):
|
||||
search_opts = {}
|
||||
api.watcher.Goal.list(
|
||||
IsA(http.HttpRequest), **search_opts
|
||||
).MultipleTimes().AndReturn(self.goals.list())
|
||||
self.mox.ReplayAll()
|
||||
@mock.patch.object(api.watcher.Goal, 'list')
|
||||
def test_index(self, mock_list):
|
||||
mock_list.return_value = self.goals.list()
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
self.assertTemplateUsed(res, 'infra_optim/goals/index.html')
|
||||
goals = res.context['goals_table'].data
|
||||
self.assertItemsEqual(goals, self.goals.list())
|
||||
|
||||
@test.create_stubs({api.watcher.Goal: ('list',)})
|
||||
def test_goal_list_unavailable(self):
|
||||
search_opts = {}
|
||||
api.watcher.Goal.list(
|
||||
IsA(http.HttpRequest), **search_opts
|
||||
).MultipleTimes().AndRaise(self.exceptions.watcher)
|
||||
self.mox.ReplayAll()
|
||||
@mock.patch.object(api.watcher.Goal, 'list')
|
||||
def test_goal_list_unavailable(self, mock_list):
|
||||
mock_list.side_effect = self.exceptions.watcher
|
||||
|
||||
resp = self.client.get(INDEX_URL)
|
||||
self.assertMessageCount(resp, error=1, warning=0)
|
||||
|
||||
@test.create_stubs({api.watcher.Goal: ('get',)})
|
||||
@test.create_stubs({api.watcher.Strategy: ('list',)})
|
||||
def test_details(self):
|
||||
@mock.patch.object(api.watcher.Strategy, 'list')
|
||||
@mock.patch.object(api.watcher.Goal, 'get')
|
||||
def test_details(self, mock_get, mock_list):
|
||||
goal = self.goals.first()
|
||||
goal_id = goal.uuid
|
||||
api.watcher.Goal.get(
|
||||
IsA(http.HttpRequest), goal_id).MultipleTimes().AndReturn(goal)
|
||||
self.mox.ReplayAll()
|
||||
mock_get.return_value = goal
|
||||
|
||||
DETAILS_URL = urlresolvers.reverse(DETAILS_VIEW, args=[goal_id])
|
||||
res = self.client.get(DETAILS_URL)
|
||||
|
@ -65,14 +54,11 @@ class GoalsTest(test.BaseAdminViewTests):
|
|||
goals = res.context['goal']
|
||||
self.assertItemsEqual([goals], [goal])
|
||||
|
||||
@test.create_stubs({api.watcher.Goal: ('get',)})
|
||||
def test_details_exception(self):
|
||||
@mock.patch.object(api.watcher.Goal, 'get')
|
||||
def test_details_exception(self, mock_get):
|
||||
at = self.goals.first()
|
||||
at_id = at.uuid
|
||||
api.watcher.Goal.get(IsA(http.HttpRequest), at_id) \
|
||||
.AndRaise(self.exceptions.watcher)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
mock_get.side_effect = self.exceptions.watcher
|
||||
|
||||
DETAILS_URL = urlresolvers.reverse(DETAILS_VIEW, args=[at_id])
|
||||
res = self.client.get(DETAILS_URL)
|
||||
|
|
Loading…
Reference in New Issue