Skip to content

Commit

Permalink
update test db core link
Browse files Browse the repository at this point in the history
  • Loading branch information
zcemycl committed Oct 27, 2023
1 parent 82799f7 commit 499c113
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/example_package/dataclasses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
Column(
"parent_person_id",
Integer,
ForeignKey("person.id"),
ForeignKey("person.id", ondelete="CASCADE"),
primary_key=True,
index=True,
unique=False,
),
Column(
"child_person_id",
Integer,
ForeignKey("person.id"),
ForeignKey("person.id", ondelete="CASCADE"),
primary_key=True,
index=True,
unique=False,
Expand All @@ -45,15 +45,15 @@
Column(
"person_id",
Integer,
ForeignKey("person.id"),
ForeignKey("person.id", ondelete="CASCADE"),
primary_key=True,
index=True,
unique=False,
),
Column(
"skill_id",
Integer,
ForeignKey("skill.id"),
ForeignKey("skill.id", ondelete="CASCADE"),
primary_key=True,
index=True,
unique=False,
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get_engine() -> Engine:

@pytest.fixture(autouse=True)
def reset(get_engine: Engine):
print("1")
engine = get_engine
metadata.drop_all(bind=engine)
metadata.create_all(bind=engine)
Expand Down
35 changes: 33 additions & 2 deletions tests/test_db.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
from pathlib import Path

from sqlalchemy.sql import insert, select
from sqlalchemy.sql import delete, insert, select

import example_package.dataclasses.orm as d
from example_package.dataclasses import person
from example_package.dataclasses import friendship, person


def test_db(get_engine):
Expand All @@ -18,6 +18,37 @@ def test_db(get_engine):
_ = conn.execute(stmt)


def test_db_core_link(get_engine):
engine = get_engine

with engine.begin() as conn:
_ = conn.execute(
insert(person).values(
[
{
"firstname": "1",
"lastname": "1",
"others": {},
"role": "developer",
},
{
"firstname": "2",
"lastname": "2",
"others": {},
"role": "developer",
},
]
)
)
_ = conn.execute(
insert(friendship).values(
[{"parent_person_id": 1, "child_person_id": 2}]
)
)
d = delete(person).where(person.c.id == 1)
conn.execute(d)


def test_orm_link(test_session2):
p1 = d.person(firstname="1", lastname="1", others={}, role="developer")
s1 = d.skill(name="python", persons=[p1])
Expand Down

0 comments on commit 499c113

Please sign in to comment.