コード例 #1
0
def test_build():
    NAME = "Test name"
    DERIVATION = "Test derivation"

    builder = WantedAttributeBuilder()

    attribute = builder.with_name(NAME).with_derivation(DERIVATION).build()

    assert attribute["name"] == NAME
    assert attribute["derivation"] == DERIVATION
コード例 #2
0
def test_with_constraint():
    constraint = SourceConstraintBuilder().with_driving_licence().build()
    attribute = (WantedAttributeBuilder().with_name(
        "test name").with_constraint(constraint).build())

    constraints = attribute["constraints"]
    assert len(constraints) == 1
    assert len(constraints[0]["preferred_sources"]["anchors"]) == 1
コード例 #3
0
def test_with_multiple_constraints():
    constraintA = SourceConstraintBuilder().with_driving_licence().build()
    constraintB = SourceConstraintBuilder().with_passport().build()

    attribute = (
        WantedAttributeBuilder().with_name("test name").with_constraint(
            [constraintA, constraintB]).build())

    constraints = attribute["constraints"]
    assert len(constraints) == 2
コード例 #4
0
def test_an_attribute_can_only_exist_once():
    NAME = "Test name"

    wanted_attribute = WantedAttributeBuilder().with_name(NAME).build()

    policy = (DynamicPolicyBuilder().with_wanted_attribute(
        wanted_attribute).with_wanted_attribute(wanted_attribute).build())

    assert len(policy["wanted"]) == 1
    assert wanted_attribute in policy["wanted"]
コード例 #5
0
def test_acccept_self_assert():
    attribute = (WantedAttributeBuilder().with_name(
        "test name").with_accept_self_asserted().build())
    assert attribute["accept_self_asserted"]
コード例 #6
0
def test_missing_attribute_name_raises():
    with pytest.raises(ValueError):
        WantedAttributeBuilder().build()