def test_find_artifact(self):
        backend = LocalArtifactBackend(config={"path": "./test_storage/"})
        artifact = Artifact(self.stage_config)
        payload = "SHRIM"
        artifact.item = Item(payload="SHRIM")
        backend.save_artifact(artifact)

        loaded_artifact = backend._find_cached_artifact(artifact)

        # Ensure that we found the artifact
        self.assertNotEqual(None, loaded_artifact)

        # Ensure that the artifact doesn't have a payload
        self.assertNotEqual(None, loaded_artifact.item)
        self.assertEqual(None, loaded_artifact.item.payload)

        # Ensure that meta properties are correctly set on artifact
        self.assertEqual(loaded_artifact._specific_hash,
                         artifact._specific_hash)
        self.assertEqual(loaded_artifact._dependency_hash,
                         artifact._dependency_hash)
        self.assertEqual(loaded_artifact._definition_hash,
                         artifact._definition_hash)
        self.assertEqual(loaded_artifact._pipeline_stage,
                         artifact._pipeline_stage)
        self.assertEqual(loaded_artifact.item.type, artifact.item.type)
    def test_pipeline_stage_status(self):
        backend = LocalArtifactBackend(config={"path": "./test_storage/"})
        artifact = Artifact(self.stage_config)
        payload = "SHRIM"
        artifact.item = Item(payload=payload)

        status = backend.pipeline_stage_run_status(self.stage_config,
                                                   artifact._dependency_hash)
        self.assertEqual(status, STAGE_DOES_NOT_EXIST)

        backend.save_artifact(artifact)

        status = backend.pipeline_stage_run_status(self.stage_config,
                                                   artifact._dependency_hash)
        self.assertEqual(status, STAGE_IN_PROGRESS)

        backend.log_pipeline_stage_run_complete(self.stage_config,
                                                artifact._dependency_hash)
        status = backend.pipeline_stage_run_status(self.stage_config,
                                                   artifact._dependency_hash)
        self.assertEqual(status, STAGE_COMPLETE)

        meta = backend._get_pipeline_stage_run_meta(self.stage_config,
                                                    artifact._dependency_hash)

        self.assertEqual(len(meta['artifacts']), 1)
    def test_load_artifact(self):
        backend = LocalArtifactBackend(config={"path": "./test_storage/"})
        artifact = Artifact(self.stage_config)
        payload = "SHRIM"
        artifact.item = Item(payload="SHRIM")
        backend.save_artifact(artifact)

        loaded_artifact = backend.load_artifact(artifact)
        self.assertEqual(loaded_artifact.item.payload, artifact.item.payload)
    def test_pipeline_stage_run_meta(self):
        backend = LocalArtifactBackend(config={"path": "./test_storage/"})
        artifact = Artifact(self.stage_config)
        payload = "SHRIM"
        artifact.item = Item(payload=payload)
        backend.save_artifact(artifact)

        backend.log_pipeline_stage_run_complete(self.stage_config,
                                                artifact._dependency_hash)

        arts = backend.find_pipeline_stage_run_artifacts(
            self.stage_config, artifact._dependency_hash)
        self.assertEqual(len(arts), 1)
        self.assertEqual(arts[0].get_uid(), artifact.get_uid())
示例#5
0
    def test_load_artifact_from_s3(self):
        backend = self._default_backend
        artifact = Artifact(self.stage_config)
        payload = "SHRIM"
        artifact.item = Item(payload=payload)
        backend.save_artifact(artifact)

        # Now we'll delete the local artifact cache, forcing retrieval from S3
        path = backend._localArtifactBackend.path
        for root, dirs, files in os.walk(path, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))
        distutils.dir_util.mkpath(path)

        loaded_artifact = backend.load_artifact(artifact)
        self.assertEqual(loaded_artifact.item.payload.decode('utf-8'), payload)
        self.assertEqual(True, loaded_artifact._loaded_from_s3_cache)

        self.cleanup_test_tables(self._default_backend)
 def test_save_artifact(self):
     backend = LocalArtifactBackend(config={"path": "./test_storage/"})
     artifact = Artifact(self.stage_config)
     artifact.item = Item(payload="SHRIM")
     backend.save_artifact(artifact)
     pass