def test_run_initialization_always(self):
        """
            Important that whenever this runs it always
            reinitializes.  Specifically this is because
            somebody may change the referenceName.  In that
            case it must be updated to be the new artifactPath
        """
        path = "/test/artifact/my/fake/path"
        identity = ResourceIdentity(path)
        metadata = {
            "lol": {
                "name": "lol",
                "value": "whatever",
                "immutable": False,
            },
            Keys.PATH: {
                "name": Keys.PATH,
                "value": "/testing-api-bucket/artifact/my/fake/path",
                "immutable": True
            }
        }

        builder = MetadataBuilder(metadata)

        # Specifically setting it instead of
        # calling resource_url so that other
        # metadata is not generated
        builder._identity = identity
        self.add_cloud(builder)
        # Just need this to exist so the etag exists
        self.add_cloud_artifact(builder)

        actual_before_update = self.cloud_portal.load(identity.cloud_metadata)

        # Sanity check
        self.assertEqual(metadata, actual_before_update)

        updater = ArtifactMetadataUpdater(self.container.bucket_container, identity)
        updater.run()

        new_metadata = self.cloud_portal.load(builder.identity.cloud_metadata)
        expected_keys = [
            Keys.MD5,
            Keys.PATH,
            Keys.NAME,
        ]

        for key in expected_keys:
            if key not in new_metadata:
                self.fail("Key {0} was not initialized".format(key))

        expected_artifact_path = {
            "name": Keys.PATH,
            "value": path,
            "immutable": True
        }
        self.assertEqual(expected_artifact_path, new_metadata["artifactPath"])

        self.assertEqual(updater.metadata, new_metadata)
Beispiel #2
0
    def add_artifact_metadata(self, path, bulk_update):
        """
            Takes a path for a particular artifact, gets the metadata
            for that artifact, and adds it to the bulk_update dictionary.

            I prefer to not return two things, so instead I just pass along
            the dictionary that the data needs to be added to.

            Args:
                path(basestring): Path to an artifact.  Not it's metadata
                bulk_update(dict(schemas/metadata.json)): A structure that stores an artifact's
                    metadata and keys it based off of their search identifier.
                    See pyshelf.resource_identifier.ResourceIdentifier for more
                    information about identifiers.
        """
        identity = self.container.resource_identity_factory \
            .from_cloud_identifier(path)
        updater = ArtifactMetadataUpdater(self.bucket_container, identity)
        updater.run()
        bulk_update[identity.search] = updater.metadata
Beispiel #3
0
    def add_artifact_metadata(self, path, bulk_update):
        """
            Takes a path for a particular artifact, gets the metadata
            for that artifact, and adds it to the bulk_update dictionary.

            I prefer to not return two things, so instead I just pass along
            the dictionary that the data needs to be added to.

            Args:
                path(basestring): Path to an artifact.  Not it's metadata
                bulk_update(dict(schemas/metadata.json)): A structure that stores an artifact's
                    metadata and keys it based off of their search identifier.
                    See pyshelf.resource_identifier.ResourceIdentifier for more
                    information about identifiers.
        """
        identity = self.container.resource_identity_factory \
            .from_cloud_identifier(path)
        updater = ArtifactMetadataUpdater(self.bucket_container, identity)
        updater.run()
        bulk_update[identity.search] = updater.metadata