Fix misuse of assert statements

Replace 'called_once_with' with 'assert_called_once_with'.
Replace 'called_once' with 'assert_called_once_with'.

Change-Id: I1d3c444c3e01b862a1a2571cf13d054dfd2fb463
Closes-Bug: 1989267
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
This commit is contained in:
Takashi Natsume 2022-09-11 11:32:39 +09:00
parent 27206b2c04
commit 40f2f5d285
2 changed files with 13 additions and 11 deletions

View File

@ -35,7 +35,8 @@ class UtilsTestCase(tests.TestCase):
self.utils = utils
self.flask = flask
self.rest = self.patch(self.utils, "Rest")
self.rest = utils.Rest('v1_0', __name__)
self.patch(self.rest, "_mroute")
self.response = self.patch(self.flask, "Response")
self.abort = self.patch(self.flask, "abort")
self.request = self.patch(self.flask, "request")
@ -44,19 +45,20 @@ class UtilsTestCase(tests.TestCase):
def test_get(self):
self.rest.get('rule', status_code=200)
self.rest._mroute.called_once_with('GET', 'rule', 200)
self.rest._mroute.assert_called_once_with('GET', 'rule', 200,
query=False)
def test_post(self):
self.rest.post('rule', status_code=201)
self.rest._mroute.called_once_with('POST', 'rule', 201)
self.rest._mroute.assert_called_once_with('POST', 'rule', 201)
def test_put(self):
self.rest.put('rule', status_code=200)
self.rest._mroute.called_once_with('PUT', 'rule', 200)
self.rest._mroute.assert_called_once_with('PUT', 'rule', 200)
def test_delete(self):
self.rest.delete('rule', status_code=204)
self.rest._mroute.called_once_with('DELETE', 'rule', 204)
self.rest._mroute.assert_called_once_with('DELETE', 'rule', 204)
def test_route_ok(self):
pass
@ -104,7 +106,7 @@ class UtilsTestCase(tests.TestCase):
def test_abort_and_log(self):
self.utils.abort_and_log(400, "Funny error")
self.abort.called_once_with(400, description="Funny error")
self.abort.assert_called_once_with(400, description="Funny error")
def test_render_error_message(self):
render = self.patch(self.utils, 'render')

View File

@ -39,7 +39,7 @@ class NotifierTestCase(tests.TestCase):
self.fake_notifier.return_value = FakeNotifier()
self.fake_transport = self.patch(
messaging,
'get_notification_transport').return_value
'get_notification_transport')
self.info_method = self.patch(FakeNotifier, 'info')
@ -64,14 +64,14 @@ class NotifierTestCase(tests.TestCase):
def test_cleanup(self):
notification.cleanup()
self.fake_transport.cleanup.assert_called_once_with()
self.fake_transport.return_value.cleanup.assert_called_once_with()
self.assertIsNone(notification.NOTIFIER)
self.assertIsNone(notification.TRANSPORT)
def test_init(self):
self.fake_transport.called_once
self.fake_notifier.called_once_with(self.fake_transport,
publisher_id='lease-service')
self.fake_transport.assert_called_once_with(notification.CONF)
self.fake_notifier.assert_called_once_with(
self.fake_transport.return_value, publisher_id='lease-service')
def test_init_called_twice_returns_same_instance(self):
prev_notifier = notification.NOTIFIER