~james-page/charm-helpers/misc-https-fixes

« back to all changes in this revision

Viewing changes to tests/fetch/test_fetch.py

  • Committer: Denis Buliga
  • Date: 2016-08-11 15:47:44 UTC
  • mto: This revision was merged to the branch mainline in revision 620.
  • Revision ID: dbuliga@cloudbasesolutions.com-20160811154744-pubbvmkbtl91nr3j
Implemented changes. Addressed review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
                MockPackage('vim')
91
91
            }
92
92
        }
93
 
        yumBase.return_value = yum_dict
 
93
        import yum
 
94
        yum.YumBase.return_value.doPackageLists.return_value = yum_dict
94
95
        result = fetch.filter_installed_packages(['vim', 'emacs'])
95
96
        self.assertEquals(result, ['emacs'])
96
97
 
106
107
        self.assertEquals(result, [])
107
108
 
108
109
    @patch("charmhelpers.fetch.centos.log")
109
 
    @patch('yum.YumBase.doPackageLists')
110
110
    @patch.object(osplatform, 'get_platform')
111
 
    def test_filter_packages_none_missing_centos(self, platform, yumBase, log):
 
111
    def test_filter_packages_none_missing_centos(self, platform, log):
112
112
        platform.return_value = 'centos'
113
113
        imp.reload(fetch)
114
114
 
124
124
                MockPackage('vim')
125
125
            }
126
126
        }
127
 
        yumBase.return_value = yum_dict
 
127
        import yum
 
128
        yum.yumBase.return_value.doPackageLists.return_value = yum_dict
128
129
        result = fetch.filter_installed_packages(['vim'])
129
130
        self.assertEquals(result, [])
130
131
 
156
157
        yum_dict = {
157
158
            'installed': {
158
159
                MockPackage('vim')
159
 
            },
160
 
            'available': {
161
 
                MockPackage('vim')
162
160
            }
163
161
        }
164
 
        yumBase.return_value = yum_dict
 
162
        import yum
 
163
        yum.YumBase.return_value.doPackageLists.return_value = yum_dict
165
164
 
166
165
        result = fetch.filter_installed_packages(['vim', 'joe'])
167
166
        self.assertEquals(result, ['joe'])
168
 
        log.assert_called_with('Package joe has no installation candidate.',
169
 
                               level='WARNING')
170
167
 
171
168
    @patch.object(osplatform, 'get_platform')
172
169
    @patch('charmhelpers.fetch.ubuntu.log')
558
555
        ]
559
556
        self.assertRaises(fetch.SourceConfigError, fetch.configure_sources)
560
557
 
561
 
    @patch.object(fetch, 'update')
 
558
    @patch.object(osplatform, 'get_platform')
 
559
    @patch('charmhelpers.fetch.ubuntu.update')
562
560
    @patch.object(fetch, 'config')
563
561
    @patch.object(fetch, 'add_source')
564
 
    def test_configure_sources_apt_update_called(self, add_source, config,
565
 
                                                 update):
 
562
    def test_configure_sources_update_called_ubuntu(self, add_source, config,
 
563
                                                    update, platform):
566
564
        config.side_effect = ['source', 'key']
567
565
        fetch.configure_sources(update=True)
568
566
        add_source.assert_called_with('source', 'key')
665
663
    @patch('charmhelpers.fetch.importlib.import_module')
666
664
    def test_skips_and_logs_missing_plugins(self, import_, log_):
667
665
        fetch_handlers = ['a.foo', 'b.foo', 'c.foo']
668
 
        import_.side_effect = (NotImplementedError, NotImplementedError, MagicMock())
 
666
        import_.side_effect = (NotImplementedError, NotImplementedError,
 
667
                               MagicMock())
669
668
        plugins = fetch.plugins(fetch_handlers)
670
669
 
671
670
        self.assertEqual(1, len(plugins))