From 96887209f8f4f6f83da4362bd2bde52c8a45030d Mon Sep 17 00:00:00 2001
From: licanwei
Date: Sat, 7 Apr 2018 23:31:18 -0700
Subject: [PATCH] Remove mox usage from strategy tests
This is part of mox-removal community goal in Rocky.
Change-Id: Ib4e4adfa0d907c05eb5407c36a58a791d0b679e4
Partial-Bug: #1758388
---
watcher_dashboard/content/strategies/tests.py | 42 +++++++------------
1 file changed, 14 insertions(+), 28 deletions(-)
diff --git a/watcher_dashboard/content/strategies/tests.py b/watcher_dashboard/content/strategies/tests.py
index 42e5d8f..9719a63 100644
--- a/watcher_dashboard/content/strategies/tests.py
+++ b/watcher_dashboard/content/strategies/tests.py
@@ -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
@@ -35,38 +34,28 @@ class StrategiesTest(test.BaseAdminViewTests):
'PREPARED_PLAN_OPERATION',
]
- @test.create_stubs({api.watcher.Strategy: ('list',)})
- def test_index(self):
- search_opts = {}
- api.watcher.Strategy.list(
- IsA(http.HttpRequest), **search_opts
- ).MultipleTimes().AndReturn(self.strategies.list())
- self.mox.ReplayAll()
+ @mock.patch.object(api.watcher.Strategy, 'list')
+ def test_index(self, mock_list):
+ mock_list.return_value = self.strategies.list()
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, 'infra_optim/strategies/index.html')
strategies = res.context['strategies_table'].data
self.assertItemsEqual(strategies, self.strategies.list())
- @test.create_stubs({api.watcher.Strategy: ('list',)})
- def test_strategy_list_unavailable(self):
- search_opts = {}
- api.watcher.Strategy.list(
- IsA(http.HttpRequest), **search_opts).MultipleTimes().AndRaise(
- self.exceptions.watcher)
- self.mox.ReplayAll()
+ @mock.patch.object(api.watcher.Strategy, 'list')
+ def test_strategy_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.Strategy: ('get',)})
- def test_details(self):
+ @mock.patch.object(api.watcher.Strategy, 'get')
+ def test_details(self, mock_get):
at = self.strategies.first()
at_id = at.uuid
- api.watcher.Strategy.get(
- IsA(http.HttpRequest), at_id).\
- MultipleTimes().AndReturn(at)
- self.mox.ReplayAll()
+ mock_get.return_value = at
+
DETAILS_URL = urlresolvers.reverse(DETAILS_VIEW, args=[at_id])
res = self.client.get(DETAILS_URL)
self.assertTemplateUsed(res,
@@ -74,14 +63,11 @@ class StrategiesTest(test.BaseAdminViewTests):
strategies = res.context['strategy']
self.assertItemsEqual([strategies], [at])
- @test.create_stubs({api.watcher.Strategy: ('get',)})
- def test_details_exception(self):
+ @mock.patch.object(api.watcher.Strategy, 'get')
+ def test_details_exception(self, mock_get):
at = self.strategies.first()
at_id = at.uuid
- api.watcher.Strategy.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)