]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
test_metadata_agent: don't check implementation details
authorIhar Hrachyshka <ihrachys@redhat.com>
Fri, 27 Feb 2015 12:35:22 +0000 (13:35 +0100)
committerIhar Hrachyshka <ihrachys@redhat.com>
Tue, 3 Mar 2015 16:35:13 +0000 (17:35 +0100)
TestUnixDomainMetadataProxy tests too many implementation details when
checking cases of existing and non-existing socket file. Reduce mock
checks to the minimum needed to test for expected behaviour.

Otherwise test may catch wrong isdir() calls (f.e. when policies are
initialized) and fail (I experienced it in local checkout).

Change-Id: I0f85730e5611a71290542f23f8bdcaaaadbef42c

neutron/tests/unit/test_metadata_agent.py

index fa691712049cfd275415c7da3d269f9859c86dd3..4e5fac39fdf9f4366187a94ae8f212d14b565a96 100644 (file)
@@ -571,8 +571,6 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
             with mock.patch('os.makedirs') as makedirs:
                 isdir.return_value = False
                 agent.UnixDomainMetadataProxy(mock.Mock())
-
-                isdir.assert_called_once_with('/the')
                 makedirs.assert_called_once_with('/the', 0o755)
 
     def test_init_exists(self):
@@ -580,8 +578,6 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
             with mock.patch('os.unlink') as unlink:
                 isdir.return_value = True
                 agent.UnixDomainMetadataProxy(mock.Mock())
-
-                isdir.assert_called_once_with('/the')
                 unlink.assert_called_once_with('/the/path')
 
     def test_init_exists_unlink_no_file(self):
@@ -593,10 +589,7 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
                     unlink.side_effect = OSError
 
                     agent.UnixDomainMetadataProxy(mock.Mock())
-
-                    isdir.assert_called_once_with('/the')
                     unlink.assert_called_once_with('/the/path')
-                    exists.assert_called_once_with('/the/path')
 
     def test_init_exists_unlink_fails_file_still_exists(self):
         with mock.patch('os.path.isdir') as isdir:
@@ -608,10 +601,7 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
 
                     with testtools.ExpectedException(OSError):
                         agent.UnixDomainMetadataProxy(mock.Mock())
-
-                    isdir.assert_called_once_with('/the')
                     unlink.assert_called_once_with('/the/path')
-                    exists.assert_called_once_with('/the/path')
 
     def test_run(self):
         with mock.patch.object(agent, 'MetadataProxyHandler') as handler:
@@ -623,7 +613,6 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
                         p = agent.UnixDomainMetadataProxy(self.cfg.CONF)
                         p.run()
 
-                        isdir.assert_called_once_with('/the')
                         makedirs.assert_called_once_with('/the', 0o755)
                         server.assert_has_calls([
                             mock.call('neutron-metadata-agent'),