From 2b3ab46440947099cbbf828da0ef75fe74e0c710 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 2 Dec 2019 14:03:33 +0000 Subject: [PATCH] Remove errant references to mox There is still a single user of mox but all other references to this can be removed. Do just that. Change-Id: I611573a41c47e99e41a54bf53cea55322a493de1 Signed-off-by: Stephen Finucane --- doc/source/contributor/topics/testing.rst | 39 ------------------- .../dashboards/admin/instances/tests.py | 18 ++++----- 2 files changed, 9 insertions(+), 48 deletions(-) diff --git a/doc/source/contributor/topics/testing.rst b/doc/source/contributor/topics/testing.rst index 81d84cb860..593ca12db0 100644 --- a/doc/source/contributor/topics/testing.rst +++ b/doc/source/contributor/topics/testing.rst @@ -315,46 +315,7 @@ Some common things to look for: the ``index`` view for a panel that got combined (such as instances & volumes). -#. Make sure your mock calls are in order before calling ``mox.ReplayAll``. - The order matters. - #. Make sure you repeat any stubbed out method calls that happen more than once. They don't automatically repeat, you have to explicitly define them. While this is a nuisance, it makes you acutely aware of how many API calls are involved in a particular function. - -Understanding the output from ``mox`` -------------------------------------- - -Horizon uses ``mox`` as its mocking framework of choice, and while it -offers many nice features, its output when a test fails can be quite -mysterious. - -Unexpected Method Call -~~~~~~~~~~~~~~~~~~~~~~ - -This occurs when you stubbed out a piece of code, and it was subsequently -called in a way that you didn't specify it would be. There are two reasons -this tends to come up: - -#. You defined the expected call, but a subtle difference crept in. This - may be a string versus integer difference, a string versus unicode - difference, a slightly off date/time, or passing a name instead of an id. - -#. The method is actually being called *multiple times*. Since mox uses - a call stack internally, it simply pops off the expected method calls to - verify them. That means once a call is used once, it's gone. An easy way - to see if this is the case is simply to copy and paste your method call a - second time to see if the error changes. If it does, that means your method - is being called more times than you think it is. - -Expected Method Never Called -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -This one is the opposite of the unexpected method call. This one means you -told mox to expect a call and it didn't happen. This is almost always the -result of an error in the conditions of the test. Using the -:meth:`~openstack_dashboard.test.helpers.TestCase.assertNoFormErrors` and -:meth:`~horizon.test.helpers.TestCase.assertMessageCount` will make it readily -apparent what the problem is in the majority of cases. If not, then use ``pdb`` -and start interrupting the code flow to see where things are getting off track. diff --git a/openstack_dashboard/dashboards/admin/instances/tests.py b/openstack_dashboard/dashboards/admin/instances/tests.py index fc4d035373..4f331093e4 100644 --- a/openstack_dashboard/dashboards/admin/instances/tests.py +++ b/openstack_dashboard/dashboards/admin/instances/tests.py @@ -549,10 +549,10 @@ class InstanceViewTest(test.BaseAdminViewTests): @override_settings(API_RESULT_PAGE_SIZE=1) def test_severs_index_paginated(self): size = settings.API_RESULT_PAGE_SIZE - mox_servers = self.servers.list() + mock_servers = self.servers.list() # get first page - expected_servers = mox_servers[:size] + expected_servers = mock_servers[:size] res = self._test_servers_paginate_do( marker=None, servers=expected_servers, @@ -562,7 +562,7 @@ class InstanceViewTest(test.BaseAdminViewTests): self.assertCountEqual(servers, expected_servers) # get second page - expected_servers = mox_servers[size:2 * size] + expected_servers = mock_servers[size:2 * size] marker = expected_servers[0].id res = self._test_servers_paginate_do( marker=marker, @@ -573,7 +573,7 @@ class InstanceViewTest(test.BaseAdminViewTests): self.assertCountEqual(servers, expected_servers) # get last page - expected_servers = mox_servers[-size:] + expected_servers = mock_servers[-size:] marker = expected_servers[0].id res = self._test_servers_paginate_do( marker=marker, @@ -586,11 +586,11 @@ class InstanceViewTest(test.BaseAdminViewTests): @override_settings(API_RESULT_PAGE_SIZE=1) def test_servers_index_paginated_prev(self): size = settings.API_RESULT_PAGE_SIZE - mox_servers = self.servers.list() + mock_servers = self.servers.list() # prev from some page - expected_servers = mox_servers[size:2 * size] - marker = mox_servers[0].id + expected_servers = mock_servers[size:2 * size] + marker = mock_servers[0].id res = self._test_servers_paginate_do( marker=marker, @@ -601,8 +601,8 @@ class InstanceViewTest(test.BaseAdminViewTests): self.assertCountEqual(servers, expected_servers) # back to first page - expected_servers = mox_servers[:size] - marker = mox_servers[0].id + expected_servers = mock_servers[:size] + marker = mock_servers[0].id res = self._test_servers_paginate_do( marker=marker, servers=expected_servers,