Exemplo n.º 1
0
def test_construct_many_to_one():
    """
    GIVEN artifacts for a many to one relationship
    WHEN construct is called with the artifacts
    THEN a many to one relationship is returned.
    """
    artifacts = artifacts_types.ManyToOneRelationshipPropertyArtifacts(
        type=types.PropertyType.RELATIONSHIP,
        schema={},
        required=False,
        description=None,
        sub_type=types.RelationshipType.MANY_TO_ONE,
        parent="Parent",
        backref_property=None,
        kwargs=None,
        write_only=False,
        foreign_key_property="prop_1",
        foreign_key="foreign.key",
        nullable=False,
    )

    returned_relationship = relationship.construct(artifacts=artifacts)

    assert returned_relationship.argument == "Parent"
    assert returned_relationship.backref is None
    assert returned_relationship.secondary is None
Exemplo n.º 2
0
def test_construct_many_to_many():
    """
    GIVEN artifacts for a many to many relationship
    WHEN construct is called with the artifacts
    THEN a many to many relationship is returned.
    """
    artifacts = artifacts_types.ManyToManyRelationshipPropertyArtifacts(
        type=types.PropertyType.RELATIONSHIP,
        schema={},
        required=False,
        description=None,
        sub_type=types.RelationshipType.MANY_TO_MANY,
        parent="Parent",
        backref_property=None,
        kwargs=None,
        write_only=False,
        secondary="association",
    )

    returned_relationship = relationship.construct(artifacts=artifacts)

    assert returned_relationship.secondary == "association"
Exemplo n.º 3
0
def test_construct_one_to_one_backref():
    """
    GIVEN artifacts for a one to one relationship with backref
    WHEN construct is called with the artifacts
    THEN a one to one relationship with backref is returned.
    """
    artifacts = artifacts_types.OneToOneRelationshipPropertyArtifacts(
        type=types.PropertyType.RELATIONSHIP,
        schema={},
        required=False,
        description=None,
        sub_type=types.RelationshipType.ONE_TO_ONE,
        parent="Parent",
        backref_property="prop_1",
        kwargs=None,
        write_only=False,
        foreign_key_property="prop_1",
        foreign_key="foreign.key",
        nullable=False,
    )

    returned_relationship = relationship.construct(artifacts=artifacts)

    assert returned_relationship.backref == ("prop_1", {"uselist": False})