def test_pool_are_in_pool_to_json(self): pool = Pool(self.conn, "pool-name", "profile") pool.completion_ttl = "4.11:08:06" pool.auto_delete = True json_pool = pool._to_json() assert json_pool['completionTimeToLive'] == '4.11:08:06' assert json_pool['autoDeleteOnCompletion'] == True
def test_pool_completion_ttl_set_get(self): pool = Pool(self.conn, "pool-name", "profile") pool.completion_ttl = datetime.timedelta(days=2, hours=33, minutes=66, seconds=66) assert "3.10:07:06" == pool.completion_ttl pool.completion_ttl = "4.11:08:06" assert "4.11:08:06" == pool.completion_ttl
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"]
def test_update_resources_send_the_good_url(self): update_connection = MockConnection() pool = Pool(update_connection, "pool-name", "profile") pool._uuid = "uuid" pool.update = none_function pool.update_resources() assert type(update_connection.requests[0]) == PatchRequest assert update_connection.requests[0].uri == "/pools/uuid"
def test_pool_privileges(self): pool = Pool(self.conn, "pool-name", "profile") pool.allow_credentials_to_be_exported_to_pool_environment() assert pool.privileges is not None assert pool.privileges._exportApiAndStorageCredentialsInEnvironment == True json_pool = pool._to_json() assert json_pool['privileges'] is not None assert json_pool['privileges'][ 'exportApiAndStorageCredentialsInEnvironment'] is True # fields that need to be non null for the deserialization to not fail json_pool['creationDate'] = datetime.datetime.utcnow().strftime( "%Y-%m-%dT%H:%M:%SZ") json_pool['uuid'] = str(uuid.uuid4()) json_pool['state'] = 'Submitted' pool_from_json = Pool(self.conn, "pool-name", "profile") pool_from_json._update(json_pool) assert pool_from_json.privileges is not None assert pool_from_json.privileges._exportApiAndStorageCredentialsInEnvironment is True
def test_bucket_in_pool_from_json(self): json_bucket = "bucket-name" json_pool = { "name": "poolName", "shortname": "poolShortname", "profile": "profile", "instanceCount": 1, "runningCoreCount": None, "runningInstanceCount": None, "resourceBuckets": [json_bucket], "creationDate": "2019-11-08T10:54:11Z", "uuid": "000", "state": "Submitted", } pool = Pool.from_json(self.conn, json_pool) pool._auto_update = False assert "bucket-name" == pool.resources[0].uuid
def test_advance_bucket_in_pool_from_json(self): json_bucket = { "bucketName": "name", "filtering": { "prefixFiltering": { "prefix": "prefix1" } }, "resourcesTransformation": { "stripPrefix": { "prefix": "prefix2" } }, "cacheTTLSec": 1000 } json_pool = { "name": "poolName", "shortname": "poolShortname", "profile": "profile", "instanceCount": 1, "runningCoreCount": None, "runningInstanceCount": None, "advancedResourceBuckets": [json_bucket], "creationDate": "2019-11-08T10:54:11Z", "uuid": "000", "state": "Submitted", } pool = Pool.from_json(self.conn, json_pool) pool._auto_update = False assert "name" == pool.resources[0].uuid assert "prefix1" == pool.resources[0]._filtering._filters[ "prefixFiltering"].prefix assert "prefix2" == pool.resources[ 0]._resources_transformation._resource_transformers[ "stripPrefix"].prefix assert 1000 == pool.resources[0]._cache_ttl_sec
def test_pool_property_default_value(self, property_name, expected_value): pool = Pool(self.conn, "pool-name", "profile") assert getattr(pool, property_name) == expected_value
def test_pool_autodelete_set_get(self): pool = Pool(self.conn, "pool-name", "profile") pool.auto_delete = False assert False == pool.auto_delete pool.auto_delete = True assert True == pool.auto_delete
def test_pool_completion_ttl_default_value(self): pool = Pool(self.conn, "pool-name", "profile") assert "00:00:00" == pool.completion_ttl
def test_pool_setting_throw_exception_after_submitted(self): job = Job(self.conn, "job-name") self.submit_job(job) pool = Pool(self.conn, "pool-name", "profile", 2, "shortname") with pytest.raises(AttributeError): job.pool = pool
def test_pool_autodelete_default_value(self): pool = Pool(self.conn, "pool-name", "profile") assert False == pool.auto_delete
def test_pool_set_property_raise_exception_after_submitted( self, property_name, set_value, exception): pool = Pool(self.conn, "pool-name", "profile") self.submit_pool(pool) with pytest.raises(exception): setattr(pool, property_name, set_value)
def test_pool_set_forbidden_property_raise_exception( self, property_name, set_value, exception): pool = Pool(self.conn, "pool-name", "profile") with pytest.raises(exception): setattr(pool, property_name, set_value)
def retrieve_pool(self, uuid): pool = Pool(self, "name", "profile", 2, "shortname") return pool
def test_pool_property_update_value(self, property_name, expected_value): pool = Pool(self.conn, "pool-name", "profile") pool._update(default_json_pool) assert getattr(pool, property_name) == expected_value
def test_pool_property_send_to_json_representation(self, property_name, expected_value): pool = Pool(self.conn, "pool-name", "profile") pool._update(default_json_pool) pool_json = pool._to_json() assert pool_json[property_name] == expected_value
def test_pool_is_set_before_submit(self): job = Job(self.conn, "job-name") pool = Pool(self.conn, "pool-name", "profile", 2, "shortname") job.pool = pool assert pool.shortname == job.pool.shortname