Exemplo n.º 1
0
def test_validate_error_selection_properties(selection, error_msg):
    # given

    # when
    with pytest.raises(InvalidParameterException) as e:
        validator = EcrLifecyclePolicyValidator(
            json.dumps({
                "rules": [{
                    "rulePriority": 1,
                    "selection": selection,
                    "action": {
                        "type": "expire"
                    },
                }]
            }))
        validator.validate()

    # then
    ex = e.value
    ex.code.should.equal(400)
    ex.error_type.should.equal("InvalidParameterException")
    ex.message.should.equal("".join([
        "Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
        "'Lifecycle policy validation failure: ",
        error_msg,
    ]))
Exemplo n.º 2
0
def test_validate_error_action_properties(action, error_msg):
    # given

    # when
    with pytest.raises(InvalidParameterException) as e:
        validator = EcrLifecyclePolicyValidator(
            json.dumps({
                "rules": [{
                    "rulePriority": 1,
                    "selection": {
                        "tagStatus": "untagged",
                        "countType": "imageCountMoreThan",
                        "countNumber": 30,
                    },
                    "action": action,
                }]
            }))
        validator.validate()

    # then
    ex = e.value
    ex.code.should.equal(400)
    ex.error_type.should.equal("InvalidParameterException")
    ex.message.should.equal("".join([
        "Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
        "'Lifecycle policy validation failure: ",
        error_msg,
    ]))
Exemplo n.º 3
0
def test_validate():
    # given
    policy = {
        "rules": [
            {
                "rulePriority": 1,
                "description": "test policy",
                "selection": {
                    "tagStatus": "untagged",
                    "countType": "imageCountMoreThan",
                    "countNumber": 30,
                },
                "action": {"type": "expire"},
            },
            {
                "rulePriority": 2,
                "description": "test policy",
                "selection": {
                    "tagStatus": "tagged",
                    "tagPrefixList": ["3.9"],
                    "countType": "sinceImagePushed",
                    "countUnit": "days",
                    "countNumber": 30,
                },
                "action": {"type": "expire"},
            },
        ]
    }

    # when/then
    validator = EcrLifecyclePolicyValidator(json.dumps(policy))
    validator.validate()
Exemplo n.º 4
0
    def put_lifecycle_policy(self, registry_id, repository_name, lifecycle_policy_text):
        repo = self._get_repository(repository_name, registry_id)

        validator = EcrLifecyclePolicyValidator(lifecycle_policy_text)
        validator.validate()

        repo.lifecycle_policy = lifecycle_policy_text

        return {
            "registryId": repo.registry_id,
            "repositoryName": repository_name,
            "lifecyclePolicyText": repo.lifecycle_policy,
        }
Exemplo n.º 5
0
def test_validate_error_parse(policy):
    # given

    # when
    with pytest.raises(InvalidParameterException) as e:
        validator = EcrLifecyclePolicyValidator(json.dumps(policy))
        validator.validate()

    # then
    ex = e.value
    ex.code.should.equal(400)
    ex.error_type.should.equal("InvalidParameterException")
    ex.message.should.equal(
        "Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
        "'Lifecycle policy validation failure: "
        "Could not map policyString into LifecyclePolicy.'")
Exemplo n.º 6
0
def test_validate_error_extract_rules(policy):
    # given

    # when
    with pytest.raises(InvalidParameterException) as e:
        validator = EcrLifecyclePolicyValidator(json.dumps(policy))
        validator.validate()

    # then
    ex = e.value
    ex.code.should.equal(400)
    ex.error_type.should.equal("InvalidParameterException")
    ex.message.should.equal(
        "Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
        "'Lifecycle policy validation failure: "
        'object has missing required properties (["rules"])\'')
Exemplo n.º 7
0
def test_validate_error_rule_type(rule):
    # given

    # when
    with pytest.raises(InvalidParameterException) as e:
        validator = EcrLifecyclePolicyValidator(json.dumps({"rules": [rule]}))
        validator.validate()

    # then
    ex = e.value
    ex.code.should.equal(400)
    ex.error_type.should.equal("InvalidParameterException")
    ex.message.should.equal(
        "Invalid parameter at 'LifecyclePolicyText' failed to satisfy constraint: "
        "'Lifecycle policy validation failure: "
        f'instance type ({type(rule)}) does not match any allowed primitive type (allowed: ["object"])\''
    )