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

Proposed by Scott Moser
Status: Merged
Merged at revision: 7b13279109d9eb3d1b102bb5ae8900c3d8423537
Proposed branch: ~smoser/cloud-init:bug/fix-gce-test
Merge into: cloud-init:master
Diff against target: 38 lines (+11/-9)
1 file modified
tests/unittests/test_datasource/test_gce.py (+11/-9)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Chad Smith Approve
Review via email: mp+327388@code.launchpad.net

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.

To post a comment you must log in.
Revision history for this message
Chad Smith (chad.smith) wrote :

LGTM: +1

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:7b13279109d9eb3d1b102bb5ae8900c3d8423537
https://jenkins.ubuntu.com/server/job/cloud-init-ci/39/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: CentOS 6 & 7: Build & Test
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/39/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py
2index 3e8398b..ad608be 100644
3--- a/tests/unittests/test_datasource/test_gce.py
4+++ b/tests/unittests/test_datasource/test_gce.py
5@@ -72,11 +72,11 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
6 self.ds = DataSourceGCE.DataSourceGCE(
7 settings.CFG_BUILTIN, None,
8 helpers.Paths({}))
9- self.m_platform_reports_gce = mock.patch(
10- 'cloudinit.sources.DataSourceGCE.platform_reports_gce',
11- return_value=True)
12- self.m_platform_reports_gce.start()
13- self.addCleanup(self.m_platform_reports_gce.stop)
14+ ppatch = self.m_platform_reports_gce = mock.patch(
15+ 'cloudinit.sources.DataSourceGCE.platform_reports_gce')
16+ self.m_platform_reports_gce = ppatch.start()
17+ self.m_platform_reports_gce.return_value = True
18+ self.addCleanup(ppatch.stop)
19 super(TestDataSourceGCE, self).setUp()
20
21 def test_connection(self):
22@@ -163,10 +163,12 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
23 self.assertEqual(True, r)
24 self.assertEqual('bar', self.ds.availability_zone)
25
26- @mock.patch('cloudinit.sources.DataSourceGCE.platform_reports_gce')
27- def test_get_data_returns_false_if_not_on_gce(self, m_platform_gce):
28- m_platform_gce.return_value = False
29- self.assertEqual(False, self.ds.get_data())
30+ @mock.patch("cloudinit.sources.DataSourceGCE.GoogleMetadataFetcher")
31+ def test_get_data_returns_false_if_not_on_gce(self, m_fetcher):
32+ self.m_platform_reports_gce.return_value = False
33+ ret = self.ds.get_data()
34+ self.assertEqual(False, ret)
35+ m_fetcher.assert_not_called()
36
37
38 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches