示例#1
0
def test_create_error_neither(app):
    type_ = {"name": "doctor"}

    with app.app_context():
        count = ProductRelationType.query.count()
        with pytest.raises(ValueError):
            ops.create_product_relation_type(type_)
            ops.commit()

    with app.app_context():
        assert ProductRelationType.query.count() == count
示例#2
0
def test_create_error_both(app):
    type_ = {"name": "doctor"}
    reverse = {"name": "patient"}

    with app.app_context():
        count = ProductRelationType.query.count()
        with pytest.raises(ValueError):
            ops.create_product_relation_type(type_, reverse, self_reverse=True)
            ops.commit()

    with app.app_context():
        assert ProductRelationType.query.count() == count
示例#3
0
def test_create_self_reverse(app):
    type_ = {"name": "spouse"}

    with app.app_context():
        count = ProductRelationType.query.count()
        model = ops.create_product_relation_type(type_, self_reverse=True)
        ops.commit()
        type_id = model.type_id
        assert type_id

    with app.app_context():
        assert ProductRelationType.query.count() == (count + 1)
        model = ProductRelationType.query.filter_by(type_id=type_id).one()
        assert model.name == "spouse"
        assert model.reverse is model
示例#4
0
def test_create(app):
    type_ = {"name": "doctor"}
    reverse = {"name": "patient"}

    with app.app_context():
        count = ProductRelationType.query.count()
        model = ops.create_product_relation_type(type_, reverse)
        ops.commit()
        type_id = model.type_id
        assert type_id

    with app.app_context():
        assert ProductRelationType.query.count() == (count + 2)
        model = ProductRelationType.query.filter_by(type_id=type_id).one()
        assert model.name == "doctor"
        assert model.reverse.name == "patient"
示例#5
0
def test_delete(app):

    with app.app_context():
        model = ops.create_product_relation_type(
            type_={"name": "to_be_deleted"},
            reverse={"name": "reverse"},
        )
        ops.commit()
        type_id = model.type_id

    with app.app_context():
        count = ProductRelationType.query.count()
        ops.delete_product_relation_type(type_id=type_id)
        ops.commit()

    with app.app_context():
        assert ProductRelationType.query.count() == count - 2
示例#6
0
def app(app_users):

    y = app_users

    # map1 -> beam1
    #            |
    #            +---> beam2
    #
    # map2
    # map3

    with y.app_context():
        ops.create_product_relation_type(
            type_={
                "type_id": 1,
                "name": "parent"
            },
            reverse={
                "type_id": 2,
                "name": "child"
            },
        )

        ops.create_product_type(type_id=1, name="map")
        ops.create_product_type(type_id=2, name="beam")

        ops.commit()

    with y.app_context():
        ops.create_product(
            product_id=1,
            type_id=1,
            name="map1",
        )
        ops.create_product(
            product_id=2,
            type_id=1,
            name="map2",
        )
        ops.create_product(
            product_id=3,
            type_id=1,
            name="map3",
        )
        ops.create_product(
            product_id=4,
            type_id=2,
            name="beam1",
        )
        ops.create_product(
            product_id=5,
            type_id=2,
            name="beam2",
        )
        ops.commit()

    with y.app_context():
        ops.create_product_relation(
            relation_id=2,
            type_id=1,
            self_product_id=4,
            other_product_id=1,
        )
        ops.create_product_relation(
            relation_id=4,
            type_id=1,
            self_product_id=5,
            other_product_id=4,
        )
        ops.commit()

    yield y
示例#7
0
def app(app_empty):

    y = app_empty

    user1 = GitHubUser(login="******", git_hub_id="04:User1")
    token1 = GitHubToken(token="39d86487d76a84087f1da599c872dac4473e5f07",
                         scope="",
                         user=user1)

    with y.app_context():
        sa.session.add(user1)
        sa.session.add(token1)
        sa.session.commit()

    # map1 -> beam1
    #   |        |
    #   +--------+---> beam2
    #
    # map2
    # map3

    with y.app_context():
        ops.create_product_relation_type(
            type_={
                "type_id": 1,
                "name": "parent",
            },
            reverse={
                "type_id": 2,
                "name": "child",
            },
        )
        ops.commit()

    with y.app_context():
        ops.create_field(
            field_id=1,
            name="contact",
            type_=ops.FieldType.UnicodeText,
        )
        ops.create_field(
            field_id=2,
            name="produced_by",
            type_=ops.FieldType.UnicodeText,
        )
        ops.create_field(
            field_id=3,
            name="date_produced",
            type_=ops.FieldType.Date,
        )
        ops.commit()

    with y.app_context():
        ops.create_product_type(
            type_id=1,
            name="map",
            field_ids=[1, 2, 3],
        )
        ops.create_product_type(
            type_id=2,
            name="beam",
            field_ids=[1, 2, 3],
        )
        ops.commit()

    with y.app_context():
        ops.create_product(
            type_id=1,
            product_id=1,
            name="map1",
            attributes={3: datetime.date(2020, 2, 1)},
            paths=["site1:/path/to/map1", "site2:/another/way/map1"],
        )
        ops.create_product(
            type_id=1,
            product_id=2,
            name="map2",
            attributes={3: datetime.date(2020, 2, 10)},
            paths=["site1:/path/to/map2"],
        )
        ops.create_product(
            type_id=1,
            product_id=3,
            name="map3",
            attributes={3: datetime.date(2020, 3, 19)},
            paths=["site1:/path/to/map3", "site2:/another/way/map3"],
        )
        ops.create_product(
            type_id=2,
            product_id=4,
            name="beam1",
            attributes={3: datetime.date(2020, 2, 5)},
            paths=["site1:/path/to/beam1", "site2:/another/way/beam1"],
        )
        ops.create_product(
            type_id=2,
            product_id=5,
            name="beam2",
            attributes={3: datetime.date(2020, 3, 4)},
            paths=["site1:/path/to/beam2"],
        )
        ops.commit()

    with y.app_context():
        ops.create_product_relation(
            type_id=1,
            self_product_id=4,
            other_product_id=1,
        )
        ops.create_product_relation(
            type_id=1,
            self_product_id=5,
            other_product_id=1,
        )
        ops.create_product_relation(
            type_id=1,
            self_product_id=5,
            other_product_id=4,
        )
        ops.commit()

    yield y
示例#8
0
def app(app_users):

    y = app_users

    # Relation types:
    #   parent <-> child
    #   plaintiff <-> defendant

    # Products and Relations:
    #   map1 -> beam1
    #     |        |
    #     +--------+---> beam2
    #
    #   map2
    #   map3

    with y.app_context():
        ops.create_product_relation_type(
            type_={
                "type_id": 1,
                "name": "parent",
                "indef_article": "a",
                "singular": "parent",
                "plural": "parents",
            },
            reverse={
                "type_id": 2,
                "name": "child",
                "indef_article": "a",
                "singular": "child",
                "plural": "children",
            },
        )
        ops.create_product_relation_type(
            type_={
                "type_id": 3,
                "name": "plaintiff",
                "indef_article": "a",
                "singular": "plaintiff",
                "plural": "plaintiffs",
            },
            reverse={
                "type_id": 4,
                "name": "defendant",
                "indef_article": "a",
                "singular": "defendant",
                "plural": "defendants",
            },
        )
        ops.commit()

    with y.app_context():
        ops.create_field(
            field_id=1,
            name="contact",
            type_=ops.FieldType.UnicodeText,
        )
        ops.create_field(
            field_id=2,
            name="produced_by",
            type_=ops.FieldType.UnicodeText,
        )
        ops.create_field(
            field_id=3,
            name="date_produced",
            type_=ops.FieldType.Date,
        )
        ops.commit()

    with y.app_context():
        ops.create_product_type(
            type_id=1,
            name="map",
            order=2,
            indef_article="a",
            singular="map",
            plural="maps",
            icon="mdi-map",
            field_ids=[1, 2, 3],
        )
        ops.create_product_type(
            type_id=2,
            name="beam",
            order=1,
            indef_article="a",
            singular="beam",
            plural="beams",
            icon="mdi-spotlight-beam",
            field_ids=[1, 2, 3],
        )
        ops.commit()

    with y.app_context():
        ops.create_product(
            type_id=1,
            product_id=1,
            name="map1",
            attributes={3: datetime.date(2020, 2, 1)},
            paths=["site2:/another/way/map1"],
        )
        ops.create_product(
            type_id=1,
            product_id=2,
            name="map2",
            attributes={3: datetime.date(2020, 2, 10)},
            paths=["site1:/path/to/map2"],
        )
        ops.create_product(
            type_id=1,
            product_id=3,
            name="map3",
            attributes={3: datetime.date(2020, 3, 19)},
            paths=["site1:/path/to/map3", "site2:/another/way/map3"],
        )
        ops.create_product(
            type_id=2,
            product_id=4,
            name="beam1",
            attributes={3: datetime.date(2020, 2, 5)},
            paths=["site1:/path/to/beam1", "site2:/another/way/beam1"],
        )
        ops.create_product(
            type_id=2,
            product_id=5,
            name="beam2",
            attributes={3: datetime.date(2020, 3, 4)},
            paths=["site1:/path/to/beam2"],
        )
        ops.commit()

    with y.app_context():
        ops.create_product_file_path(
            product_id=1,
            path="site1:/path/to/map1",
            note="sample comment",
        )
        ops.commit()

    with y.app_context():
        ops.create_product_relation(
            type_id=1,
            self_product_id=4,
            other_product_id=1,
        )
        ops.create_product_relation(
            type_id=1,
            self_product_id=5,
            other_product_id=1,
        )
        ops.create_product_relation(
            type_id=1,
            self_product_id=5,
            other_product_id=4,
        )
        ops.commit()

    yield y
示例#9
0
def app(app_users):

    y = app_users

    # Relation types:
    #   parent <-> child
    #   plaintiff <-> defendant

    # Relations:
    #   map1 -> beam1
    #     |        |
    #     +--------+---> beam2

    with y.app_context():
        ops.create_product_relation_type(
            type_={
                "type_id": 1,
                "name": "parent",
                "indef_article": "a",
                "singular": "parent",
                "plural": "parents",
            },
            reverse={
                "type_id": 2,
                "name": "child",
                "indef_article": "a",
                "singular": "child",
                "plural": "children",
            },
        )
        ops.create_product_relation_type(
            type_={
                "type_id": 3,
                "name": "plaintiff",
                "indef_article": "a",
                "singular": "plaintiff",
                "plural": "plaintiffs",
            },
            reverse={
                "type_id": 4,
                "name": "defendant",
                "indef_article": "a",
                "singular": "defendant",
                "plural": "defendants",
            },
        )

        ops.create_product_type(type_id=1, name="map")
        ops.create_product_type(type_id=2, name="beam")

        ops.commit()

    with y.app_context():
        ops.create_product(
            product_id=1,
            type_id=1,
            name="map1",
        )
        ops.create_product(
            product_id=4,
            type_id=2,
            name="beam1",
        )
        ops.create_product(
            product_id=5,
            type_id=2,
            name="beam2",
        )
        ops.commit()

    with y.app_context():
        ops.create_product_relation(
            type_id=1,
            self_product_id=4,
            other_product_id=1,
        )
        ops.create_product_relation(
            type_id=1,
            self_product_id=5,
            other_product_id=1,
        )
        ops.create_product_relation(
            type_id=1,
            self_product_id=5,
            other_product_id=4,
        )
        ops.commit()

    yield y