# Path: tests/bucket_update/test_base.py
# class TestBase(FunctionalTestBase):
#     def setUp(self):
#         super(TestBase, self).setUp()
#         self.fake_config = {
#             "name": "test",
#             "accessKey": "ABC123",
#             "secretKey": "321CBA",
#             "elasticsearch": FunctionalTestBase.CONFIG["elasticsearch"],
#             "logLevel": logging.INFO,
#             "chunkSize": 10,
#             "referenceName": "test-refname"
#         }
# 
#         self.logger = self.create_logger()
#         self.factory = Factory(self.logger)
#         self.container = Container(self.fake_config, self.logger)
#         self.cloud_portal = self.factory.create_cloud_portal(self.fake_config["name"])
# 
#     def create_logger(self):
#         handler = logging.StreamHandler(stream=sys.stdout)
#         logger = logging.Logger(self.fake_config["name"])
#         logger.addHandler(handler)
#         return logger
# 
#     def add_cloud_artifact(self, builder):
#         key = Key(self.test_bucket, builder.identity.cloud)
#         key.set_contents_from_string("test")
# 
#     def add_cloud(self, builder):
#         self.cloud_portal.update(builder.identity.cloud_metadata, builder.data)
# 
#     def add_search(self, builder):
#         self.search_wrapper.add_metadata(builder.identity.search, builder.data)
# 
#     def add_both(self, builder):
#         self.add_cloud(builder)
#         self.add_search(builder)
# 
# Path: tests/metadata_builder.py
# class MetadataBuilder(object):
#     DEFAULT = {
#         Keys.MD5: {
#             "immutable": True,
#             "name": Keys.MD5,
#             "value": Keys.MD5,
#         },
#         Keys.PATH: {
#             "immutable": True,
#             "name": Keys.PATH,
#             "value": Keys.PATH,
#         },
#         Keys.NAME: {
#             "immutable": True,
#             "name": Keys.NAME,
#             "value": Keys.NAME,
#         },
#     }
# 
#     def __init__(self, data=None):
#         if not data:
#             data = MetadataBuilder.DEFAULT
# 
#         self.data = deepcopy(data)
#         self._identity = None
# 
#     @property
#     def identity(self):
#         if not self._identity:
#             raise AttributeError("identity was not assigned on this MetadataBuilder.  Have you called resource_url()?")
# 
#         return self._identity
# 
#     @property
#     def mapper(self):
#         if not self._mapper:
#             self._mapper = Mapper()
# 
#         return self._mapper
# 
#     def property(self, key, value, immutable=False):
#         """
#             Upserts a metadata value
#         """
#         self.data[key] = {
#             "immutable": immutable,
#             "name": key,
#             "value": value
#         }
#         return self
# 
#     def version(self, value="1"):
#         return self.property("version", value)
# 
#     def resource_url(self, resource_url):
#         identity = ResourceIdentity(resource_url)
#         self._identity = identity
#         self.data[Keys.PATH]["value"] = identity.resource_path
#         self.data[Keys.NAME]["value"] = identity.artifact_name
#         return self
# 
#     def to_cloud(self):
#         return self.mapper.to_cloud(self.data)
# 
#     def copy(self):
#         builder = deepcopy(self)
#         return builder
# 
# Path: shelf/metadata/keys.py
# class Keys(object):
#     MD5 = "md5Hash"
#     PATH = "artifactPath"
#     NAME = "artifactName"
#     CREATED_DATE = "createdDate"


from tests.bucket_update.test_base import TestBase
from shelf.resource_identity import ResourceIdentity
from shelf.bucket_update.artifact_metadata_updater import ArtifactMetadataUpdater
from tests.metadata_builder import MetadataBuilder
from shelf.metadata.keys import Keys
        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 = {

# Path: tests/bucket_update/test_base.py
# class TestBase(FunctionalTestBase):
#     def setUp(self):
#         super(TestBase, self).setUp()
#         self.fake_config = {
#             "name": "test",
#             "accessKey": "ABC123",
#             "secretKey": "321CBA",
#             "elasticsearch": FunctionalTestBase.CONFIG["elasticsearch"],
#             "logLevel": logging.INFO,
#             "chunkSize": 10,
#             "referenceName": "test-refname"
#         }
# 
#         self.logger = self.create_logger()
#         self.factory = Factory(self.logger)
#         self.container = Container(self.fake_config, self.logger)
#         self.cloud_portal = self.factory.create_cloud_portal(self.fake_config["name"])
# 
#     def create_logger(self):
#         handler = logging.StreamHandler(stream=sys.stdout)
#         logger = logging.Logger(self.fake_config["name"])
#         logger.addHandler(handler)
#         return logger
# 
#     def add_cloud_artifact(self, builder):
#         key = Key(self.test_bucket, builder.identity.cloud)
#         key.set_contents_from_string("test")
# 
#     def add_cloud(self, builder):
#         self.cloud_portal.update(builder.identity.cloud_metadata, builder.data)
# 
#     def add_search(self, builder):
#         self.search_wrapper.add_metadata(builder.identity.search, builder.data)
# 
#     def add_both(self, builder):
#         self.add_cloud(builder)
#         self.add_search(builder)
# 
# Path: tests/metadata_builder.py
# class MetadataBuilder(object):
#     DEFAULT = {
#         Keys.MD5: {
#             "immutable": True,
#             "name": Keys.MD5,
#             "value": Keys.MD5,
#         },
#         Keys.PATH: {
#             "immutable": True,
#             "name": Keys.PATH,
#             "value": Keys.PATH,
#         },
#         Keys.NAME: {
#             "immutable": True,
#             "name": Keys.NAME,
#             "value": Keys.NAME,
#         },
#     }
# 
#     def __init__(self, data=None):
#         if not data:
#             data = MetadataBuilder.DEFAULT
# 
#         self.data = deepcopy(data)
#         self._identity = None
# 
#     @property
#     def identity(self):
#         if not self._identity:
#             raise AttributeError("identity was not assigned on this MetadataBuilder.  Have you called resource_url()?")
# 
#         return self._identity
# 
#     @property
#     def mapper(self):
#         if not self._mapper:
#             self._mapper = Mapper()
# 
#         return self._mapper
# 
#     def property(self, key, value, immutable=False):
#         """
#             Upserts a metadata value
#         """
#         self.data[key] = {
#             "immutable": immutable,
#             "name": key,
#             "value": value
#         }
#         return self
# 
#     def version(self, value="1"):
#         return self.property("version", value)
# 
#     def resource_url(self, resource_url):
#         identity = ResourceIdentity(resource_url)
#         self._identity = identity
#         self.data[Keys.PATH]["value"] = identity.resource_path
#         self.data[Keys.NAME]["value"] = identity.artifact_name
#         return self
# 
#     def to_cloud(self):
#         return self.mapper.to_cloud(self.data)
# 
#     def copy(self):
#         builder = deepcopy(self)
#         return builder
# 
# Path: shelf/metadata/keys.py
# class Keys(object):
#     MD5 = "md5Hash"
#     PATH = "artifactPath"
#     NAME = "artifactName"
#     CREATED_DATE = "createdDate"


# Path: tests/bucket_update/artifact_metadata_updater_test.py
from tests.bucket_update.test_base import TestBase
from shelf.resource_identity import ResourceIdentity
from shelf.bucket_update.artifact_metadata_updater import ArtifactMetadataUpdater
from tests.metadata_builder import MetadataBuilder
from shelf.metadata.keys import Keys

        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,