Esempio n. 1
0
    def test_process_main_new_manifests(self, associate_single_unit):
        """
        Test process_main() when there are new manifests that were downloaded.
        """
        working_dir = '/working/dir/'
        step = sync.SaveUnitsStep()
        step.parent = mock.MagicMock()
        step.parent.get_working_dir.return_value = working_dir
        step.parent.get_repo.return_value = mock.MagicMock()
        step.parent.step_get_local_blobs.units_to_download = []
        # Simulate one newly downloaded manifest
        with open(os.path.join(
                TEST_DATA_PATH,
                'manifest_repeated_layers.json')) as manifest_file:
            manifest = manifest_file.read()
        manifest_digest = 'sha256:a001e892f3ba0685184486b08cda99bf81f551513f4b56e72954a1d4404195b1'
        manifest = models.Manifest.from_json(manifest, manifest_digest)
        step.parent.step_get_local_metadata.units_to_download = [manifest]
        units = list(step.get_iterator())

        for unit in units:
            unit.save_and_import_content = mock.MagicMock()

            step.process_main(item=unit)

            path = os.path.join(working_dir, unit.digest)
            unit.save_and_import_content.assert_called_once_with(path)
            self.assertEqual(associate_single_unit.mock_calls[-1][1][0],
                             step.parent.get_repo.return_value)
            self.assertEqual(associate_single_unit.mock_calls[-1][1][1], unit)
Esempio n. 2
0
    def test_process_main_new_blobs(self, associate_single_unit):
        """
        Test process_main() when there are new Blobs that were downloaded.
        """
        step = sync.SaveUnitsStep()
        digests = (
            'sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef',
            'sha256:cc8567d70002e957612902a8e985ea129d831ebe04057d88fb644857caa45d11'
        )
        step.parent = mock.MagicMock()
        step.parent.get_working_dir.return_value = '/some/path'
        step.parent.get_repo.return_value = mock.MagicMock()
        step.parent.step_get_local_manifests.units_to_download = []
        step.parent.step_get_local_blobs.units_to_download = [
            models.Blob(digest=digest) for digest in digests
        ]
        units = list(step.get_iterator())

        for unit in units:
            unit.save_and_import_content = mock.MagicMock()

            step.process_main(item=unit)
            path = os.path.join('/some/path', unit.digest)
            unit.save_and_import_content.assert_called_once_with(path)
            self.assertEqual(associate_single_unit.mock_calls[-1][1][0],
                             step.parent.get_repo.return_value.repo_obj)
            self.assertEqual(associate_single_unit.mock_calls[-1][1][1], unit)
Esempio n. 3
0
    def test___init__(self, super___init__):
        """
        Assert the correct operation of the __init__() method.
        """
        step = sync.SaveUnitsStep()

        super___init__.assert_called_once_with(
            step, step_type=constants.SYNC_STEP_SAVE)
        self.assertEqual(step.description, _('Saving Manifests and Blobs'))
Esempio n. 4
0
    def test_process_main_new_blobs_and_manifests(self, associate_single_unit):
        """
        Test process_main() when there are new Blobs and one Manifest that were downloaded.
        """
        working_dir = '/working/dir/'
        step = sync.SaveUnitsStep()
        # Simulate two newly downloaded blobs
        blob_digests = (
            'sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef',
            'sha256:cc8567d70002e957612902a8e985ea129d831ebe04057d88fb644857caa45d11'
        )
        step.parent = mock.MagicMock()
        step.parent.get_working_dir.return_value = working_dir
        step.parent.get_repo.return_value = mock.MagicMock()
        step.parent.step_get_local_blobs.units_to_download = [
            models.Blob(digest=digest) for digest in blob_digests
        ]
        # Simulate one newly downloaded manifest
        with open(os.path.join(
                TEST_DATA_PATH,
                'manifest_repeated_layers.json')) as manifest_file:
            manifest = manifest_file.read()
        manifest_digest = 'sha256:a001e892f3ba0685184486b08cda99bf81f551513f4b56e72954a1d4404195b1'
        manifest = models.Manifest.from_json(manifest, manifest_digest)
        step.parent.step_get_local_metadata.units_to_download = [manifest]
        units = list(step.get_iterator())

        for unit in units:
            unit.save_and_import_content = mock.MagicMock()

            step.process_main(item=unit)
            path = os.path.join(working_dir, unit.digest)
            unit.save_and_import_content.assert_called_once_with(path)
            self.assertEqual(associate_single_unit.mock_calls[-1][1][0],
                             step.parent.get_repo.return_value.repo_obj)
            self.assertEqual(associate_single_unit.mock_calls[-1][1][1], unit)