← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~smoser/cloud-init:bug/fix-gce-test into cloud-init:master

 

Scott Moser has proposed merging ~smoser/cloud-init:bug/fix-gce-test into cloud-init:master.

Commit message:
tests: fix usage of mock in GCE test.

The usage of mock in this test was simply invalid and only worked by
happenstance.


Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327388
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:bug/fix-gce-test into cloud-init:master.
diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py
index 3e8398b..ad608be 100644
--- a/tests/unittests/test_datasource/test_gce.py
+++ b/tests/unittests/test_datasource/test_gce.py
@@ -72,11 +72,11 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
         self.ds = DataSourceGCE.DataSourceGCE(
             settings.CFG_BUILTIN, None,
             helpers.Paths({}))
-        self.m_platform_reports_gce = mock.patch(
-            'cloudinit.sources.DataSourceGCE.platform_reports_gce',
-            return_value=True)
-        self.m_platform_reports_gce.start()
-        self.addCleanup(self.m_platform_reports_gce.stop)
+        ppatch = self.m_platform_reports_gce = mock.patch(
+            'cloudinit.sources.DataSourceGCE.platform_reports_gce')
+        self.m_platform_reports_gce = ppatch.start()
+        self.m_platform_reports_gce.return_value = True
+        self.addCleanup(ppatch.stop)
         super(TestDataSourceGCE, self).setUp()
 
     def test_connection(self):
@@ -163,10 +163,12 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
         self.assertEqual(True, r)
         self.assertEqual('bar', self.ds.availability_zone)
 
-    @mock.patch('cloudinit.sources.DataSourceGCE.platform_reports_gce')
-    def test_get_data_returns_false_if_not_on_gce(self, m_platform_gce):
-        m_platform_gce.return_value = False
-        self.assertEqual(False, self.ds.get_data())
+    @mock.patch("cloudinit.sources.DataSourceGCE.GoogleMetadataFetcher")
+    def test_get_data_returns_false_if_not_on_gce(self, m_fetcher):
+        self.m_platform_reports_gce.return_value = False
+        ret = self.ds.get_data()
+        self.assertEqual(False, ret)
+        m_fetcher.assert_not_called()
 
 
 # vi: ts=4 expandtab