~paelzer/cloud-init/test-apt-source

« back to all changes in this revision

Viewing changes to tests/unittests/test_handler/test_handler_apt_source.py

  • Committer: Christian Ehrhardt
  • Date: 2016-05-23 08:53:16 UTC
  • Revision ID: christian.ehrhardt@canonical.com-20160523085316-q00tdlarjxaccz9g
extend test_apt_source_keyid by no filename case

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
        with mock.patch.object(os.path, 'join', side_effect=self.myjoin):
149
149
            self.apt_source_replacement(filename, cfg)
150
150
 
151
 
    def test_apt_source_keyid(self):
152
 
        """ test_apt_source_keyid
 
151
    def apt_source_keyid(self, filename, cfg):
 
152
        """ apt_source_keyid
153
153
        Test specification of a source + keyid
154
154
        """
155
155
        params = self._get_default_params()
156
 
        cfg = {'source': ('deb '
157
 
                          'http://ppa.launchpad.net/'
158
 
                          'smoser/cloud-init-test/ubuntu'
159
 
                          ' xenial main'),
160
 
               'keyid': "03683F77",
161
 
               'filename': self.aptlistfile}
162
156
 
163
157
        with mock.patch.object(util, 'subp',
164
158
                               return_value=('fakekey 1234', '')) as mockobj:
166
160
 
167
161
        mockobj.assert_called_with(('apt-key', 'add', '-'), 'fakekey 1234')
168
162
 
169
 
        self.assertTrue(os.path.isfile(self.aptlistfile))
 
163
        self.assertTrue(os.path.isfile(filename))
170
164
 
171
 
        contents = load_tfile_or_url(self.aptlistfile)
 
165
        contents = load_tfile_or_url(filename)
172
166
        self.assertTrue(re.search(r"%s %s %s %s\n" %
173
167
                                  ("deb",
174
168
                                   ('http://ppa.launchpad.net/smoser/'
176
170
                                   "xenial", "main"),
177
171
                                  contents, flags=re.IGNORECASE))
178
172
 
 
173
    def test_apt_source_keyid(self):
 
174
        """ test_apt_source_keyid
 
175
        Test specification of a source + keyid with filename being set
 
176
        """
 
177
        cfg = {'source': ('deb '
 
178
                          'http://ppa.launchpad.net/'
 
179
                          'smoser/cloud-init-test/ubuntu'
 
180
                          ' xenial main'),
 
181
               'keyid': "03683F77",
 
182
               'filename': self.aptlistfile}
 
183
        self.apt_source_keyid(self.aptlistfile, cfg)
 
184
 
 
185
    def test_apt_source_keyid_nofn(self):
 
186
        """ test_apt_source_keyid
 
187
        Test specification of a source + keyid without filename being set
 
188
        """
 
189
        cfg = {'source': ('deb '
 
190
                          'http://ppa.launchpad.net/'
 
191
                          'smoser/cloud-init-test/ubuntu'
 
192
                          ' xenial main'),
 
193
               'keyid': "03683F77"}
 
194
        # mock into writable tmp dir and check path/content there
 
195
        filename = os.path.join(self.tmp, "etc/apt/sources.list.d/",
 
196
                                "cloud_config_sources.list")
 
197
        with mock.patch.object(os.path, 'join', side_effect=self.myjoin):
 
198
            self.apt_source_keyid(filename, cfg)
 
199
 
179
200
    def test_apt_source_key(self):
180
201
        """ test_apt_source_key
181
202
        Test specification of a source + key