~lamont/maas/bug-1645912-2.1

« back to all changes in this revision

Viewing changes to src/provisioningserver/import_images/tests/test_download_resources.py

  • Committer: LaMont Jones
  • Date: 2016-10-12 15:26:17 UTC
  • mfrom: (5469 maas)
  • mto: This revision was merged to the branch mainline in revision 5482.
  • Revision ID: lamont@canonical.com-20161012152617-t14n2jt7y5b7hidb
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
186
186
        if ftype is None:
187
187
            ftype = factory.make_name('ftype')
188
188
        return {
 
189
            'content_id': 'maas:v2:download',
 
190
            'product_name': factory.make_string(),
 
191
            'version_name': datetime.utcnow().strftime('%Y%m%d'),
189
192
            'sha256': factory.make_name('sha256'),
190
193
            'size': random.randint(2, 2**16),
191
194
            'ftype': ftype,
198
201
 
199
202
    def test_inserts_archive(self):
200
203
        product = self.make_product('archive.tar.xz')
201
 
        # Mock in test data
202
 
        repo_writer = download_resources.RepoWriter(None, None, None)
 
204
        product_mapping = ProductMapping()
 
205
        subarch = factory.make_name('subarch')
 
206
        product_mapping.add(product, subarch)
 
207
        repo_writer = download_resources.RepoWriter(
 
208
            None, None, product_mapping)
203
209
        self.patch(
204
210
            download_resources, 'products_exdata').return_value = product
205
 
        self.patch(repo_writer, 'product_mapping')
206
211
        mock_extract_archive_tar = self.patch(
207
212
            download_resources, 'extract_archive_tar')
208
213
        mock_link_resources = self.patch(download_resources, 'link_resources')
217
222
            MockCalledOnceWith(
218
223
                snapshot_path=None, links=mock.ANY, osystem=product['os'],
219
224
                arch=product['arch'], release=product['release'],
220
 
                label=product['label'], subarches=mock.ANY,
 
225
                label=product['label'], subarches=[subarch],
221
226
                bootloader_type=None))
222
227
 
223
228
    def test_inserts_root_image(self):
224
229
        product = self.make_product('root-image.gz')
225
 
        # Mock in test data
226
 
        repo_writer = download_resources.RepoWriter(None, None, None)
 
230
        product_mapping = ProductMapping()
 
231
        subarch = factory.make_name('subarch')
 
232
        product_mapping.add(product, subarch)
 
233
        repo_writer = download_resources.RepoWriter(
 
234
            None, None, product_mapping)
227
235
        self.patch(
228
236
            download_resources, 'products_exdata').return_value = product
229
 
        self.patch(repo_writer, 'product_mapping')
230
237
        mock_insert_root_image = self.patch(
231
238
            download_resources, 'insert_root_image')
232
239
        mock_link_resources = self.patch(download_resources, 'link_resources')
241
248
            MockCalledOnceWith(
242
249
                snapshot_path=None, links=mock.ANY, osystem=product['os'],
243
250
                arch=product['arch'], release=product['release'],
244
 
                label=product['label'], subarches=mock.ANY,
 
251
                label=product['label'], subarches=[subarch],
245
252
                bootloader_type=None))
246
253
 
247
254
    def test_inserts_file(self):
248
255
        product = self.make_product()
249
 
        # Mock in test data
250
 
        repo_writer = download_resources.RepoWriter(None, None, None)
251
 
        self.patch(
252
 
            download_resources, 'products_exdata').return_value = product
253
 
        self.patch(repo_writer, 'product_mapping')
254
 
        mock_insert_file = self.patch(download_resources, 'insert_file')
255
 
        mock_link_resources = self.patch(download_resources, 'link_resources')
256
 
        repo_writer.insert_item(product, None, None, None, None)
257
 
        self.assertThat(
258
 
            mock_insert_file,
259
 
            MockCalledOnceWith(
260
 
                mock.ANY, os.path.basename(product['path']), product['sha256'],
261
 
                {'sha256': product['sha256']}, product['size'], None))
262
 
        self.assertThat(
263
 
            mock_link_resources,
264
 
            MockCalledOnceWith(
265
 
                snapshot_path=None, links=mock.ANY, osystem=product['os'],
266
 
                arch=product['arch'], release=product['release'],
267
 
                label=product['label'], subarches=mock.ANY,
 
256
        product_mapping = ProductMapping()
 
257
        subarch = factory.make_name('subarch')
 
258
        product_mapping.add(product, subarch)
 
259
        repo_writer = download_resources.RepoWriter(
 
260
            None, None, product_mapping)
 
261
        self.patch(
 
262
            download_resources, 'products_exdata').return_value = product
 
263
        mock_insert_file = self.patch(download_resources, 'insert_file')
 
264
        mock_link_resources = self.patch(download_resources, 'link_resources')
 
265
        repo_writer.insert_item(product, None, None, None, None)
 
266
        self.assertThat(
 
267
            mock_insert_file,
 
268
            MockCalledOnceWith(
 
269
                mock.ANY, os.path.basename(product['path']), product['sha256'],
 
270
                {'sha256': product['sha256']}, product['size'], None))
 
271
        self.assertThat(
 
272
            mock_link_resources,
 
273
            MockCalledOnceWith(
 
274
                snapshot_path=None, links=mock.ANY, osystem=product['os'],
 
275
                arch=product['arch'], release=product['release'],
 
276
                label=product['label'], subarches=[subarch],
 
277
                bootloader_type=None))
 
278
 
 
279
    def test_inserts_rolling_links(self):
 
280
        product = self.make_product()
 
281
        product['subarch'] = 'hwe-16.04'
 
282
        product['rolling'] = True
 
283
        product_mapping = ProductMapping()
 
284
        product_mapping.add(product, 'hwe-16.04')
 
285
        repo_writer = download_resources.RepoWriter(
 
286
            None, None, product_mapping)
 
287
        self.patch(
 
288
            download_resources, 'products_exdata').return_value = product
 
289
        mock_insert_file = self.patch(download_resources, 'insert_file')
 
290
        mock_link_resources = self.patch(download_resources, 'link_resources')
 
291
        repo_writer.insert_item(product, None, None, None, None)
 
292
        self.assertThat(
 
293
            mock_insert_file,
 
294
            MockCalledOnceWith(
 
295
                mock.ANY, os.path.basename(product['path']), product['sha256'],
 
296
                {'sha256': product['sha256']}, product['size'], None))
 
297
        self.assertThat(
 
298
            mock_link_resources,
 
299
            MockCalledOnceWith(
 
300
                snapshot_path=None, links=mock.ANY, osystem=product['os'],
 
301
                arch=product['arch'], release=product['release'],
 
302
                label=product['label'], subarches=['hwe-16.04', 'hwe-rolling'],
268
303
                bootloader_type=None))
269
304
 
270
305