def test_advance_bucket_in_task_to_json(self, mock_conn):
        task = Task(mock_conn, "task-name", "profile")
        bucket = Bucket(mock_conn, "name", False)
        bucket2 = bucket.with_filtering(BucketPrefixFiltering(
            "prefix1")).with_resource_transformation(PrefixResourcesTransformation("prefix2"))

        task.resources.append(bucket2)
        json_task = task._to_json()
        json_bucket = json_task["advancedResourceBuckets"][0]
        assert "name" == json_bucket["bucketName"]
        assert "prefix1" == json_bucket["filtering"]["prefixFiltering"]["prefix"]
        assert "prefix2" == json_bucket["resourcesTransformation"]["stripPrefix"]["prefix"]
Exemple #2
0
    def test_advance_bucket_in_pool_to_json(self):
        pool = Pool(self.conn, "pool-name", "profile")
        bucket = Bucket(self.conn, "name", False)
        bucket2 = bucket.with_filtering(
            BucketPrefixFiltering("prefix1")).with_resource_transformation(
                PrefixResourcesTransformation("prefix2"))

        pool.resources.append(bucket2)
        json_pool = pool._to_json()
        json_bucket = json_pool["advancedResourceBuckets"][0]
        assert "name" == json_bucket["bucketName"]
        assert "prefix1" == json_bucket["filtering"]["prefixFiltering"][
            "prefix"]
        assert "prefix2" == json_bucket["resourcesTransformation"][
            "stripPrefix"]["prefix"]
Exemple #3
0
 def test_create_an_advance_resource_json(self):
     """
     {
         BucketName:"name",
         Filtering: {
             BucketPrefixFiltering: {
                 Prefix:"prefix"
             }
         },
         ResourcesTransformation: {
             StripPrefix: {
                 Prefix:"prefix"
             }
         },
         CacheTTLSec: 1000
     }
     """
     bucket = Bucket(MockConnection(), "name", False)
     bucket2 = bucket.with_filtering(BucketPrefixFiltering("prefix1")).with_resource_transformation(PrefixResourcesTransformation("prefix2")).with_cache_ttl(2000)
     json_dict = bucket2.to_json()
     assert "name" == json_dict["bucketName"]
     assert "prefix1" == json_dict["filtering"]["prefixFiltering"]["prefix"]
     assert "prefix2" == json_dict["resourcesTransformation"]["stripPrefix"]["prefix"]
     assert 2000 == json_dict["cacheTTLSec"]
Exemple #4
0
 def test_check_the_init_values(self):
     bucket = Bucket(MockConnection(), "name", False)
     bucket2 = bucket.with_filtering(BucketPrefixFiltering("test")).with_resource_transformation(PrefixResourcesTransformation("test2"))
     assert "name" == bucket2.uuid
     assert "test" == bucket2._filtering._filters["prefixFiltering"].prefix
     assert "test2" == bucket2._resources_transformation._resource_transformers["stripPrefix"].prefix
     bucket = Bucket(MockConnection(), "name", False)
     bucket2 = bucket.with_resource_transformation(PrefixResourcesTransformation("test2")).with_filtering(BucketPrefixFiltering("test"))
     assert "name" == bucket2.uuid
     assert "test" == bucket2._filtering._filters["prefixFiltering"].prefix
     assert "test2" == bucket2._resources_transformation._resource_transformers["stripPrefix"].prefix
Exemple #5
0
    def test_create_an_advance_bucket_from_a_json(self):
        json = {
            "bucketName": "name",
            "filtering": {
                "prefixFiltering": {
                    "prefix": "prefix1"
                }
            },
            "resourcesTransformation": {
                "stripPrefix": {
                    "prefix": "prefix2"
                }
            },
            "cacheTTLSec": 1000
        }

        bucket = Bucket.from_json(MockConnection(), json)
        assert "name" == bucket.uuid
        assert "prefix1" == bucket._filtering._filters["prefixFiltering"].prefix
        assert "prefix2" == bucket._resources_transformation._resource_transformers["stripPrefix"].prefix
        assert 1000 == bucket._cache_ttl_sec
 def test_init_bucket(self):
     mock_connection = mock_connection_base()
     bucket = Bucket(mock_connection, "name", True)
     mock_connection.s3client.create_bucket.assert_called_once()
Exemple #7
0
 def _connect_to_bucket(self) -> None:
     """Connect to the CSP bucket"""
     self._conn = Connection(client_token=cfg.QARNOT_TOKEN)
     self._bucket = Bucket(self._conn, cfg.BUCKET_NAME)
     if isinstance(cfg.BUCKET_MEDIA_FOLDER, str):
         self._media_folder = cfg.BUCKET_MEDIA_FOLDER