test: broader db seeding
This commit is contained in:
parent
a2e18300b9
commit
7e89ab0afd
1 changed files with 22 additions and 0 deletions
|
|
@ -5,6 +5,10 @@ from httpx import AsyncClient, ASGITransport
|
|||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from src.user.models import User
|
||||
from src.service.models import Service
|
||||
from src.organisation.models import Organisation as Org
|
||||
from src.contact.models import Contact
|
||||
from src.iam.models import Group, Permission
|
||||
from src.auth.service import get_current_user, get_dev_user
|
||||
|
||||
from src.main import app # inited FastAPI app
|
||||
|
|
@ -51,6 +55,24 @@ def seed_db():
|
|||
db = SessionLocal()
|
||||
try:
|
||||
db.add(User(email="admin@test.com", first_name="Admin", last_name="Test", oidc_id="abcd-efgh-ijkl-mnop"))
|
||||
db.add(Contact(org_id=1))
|
||||
db.add(Contact(org_id=1))
|
||||
db.add(Contact(org_id=1))
|
||||
db.flush()
|
||||
db.add(Org(name="Test Org", root_user_id=1, billing_contact_id=1, owner_contact_id=1, security_contact_id=1,
|
||||
status="approved", intake_questionnaire="{}"))
|
||||
db.add(Service(name="Test Service", api_key="123456789"))
|
||||
db.add(Permission(service_id=1, resource="test_resource", action="read"))
|
||||
db.add(Group(name="Test Group"))
|
||||
db.flush()
|
||||
group_model = db.get(Group, 1)
|
||||
perm_model = db.get(Permission, 1)
|
||||
group_model.permission_rel.append(perm_model)
|
||||
user_model = db.get(User, 1)
|
||||
org_model = db.get(Org, 1)
|
||||
org_model.user_rel.append(user_model)
|
||||
db.flush()
|
||||
group_model.user_rel.append(user_model)
|
||||
db.commit()
|
||||
yield db
|
||||
finally:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue