Get or create the demo user.
(server)
| 58 | |
| 59 | @pytest_asyncio.fixture(scope="module", loop_scope="module") |
| 60 | async def user(server): |
| 61 | """Get or create the demo user.""" |
| 62 | from mirix.schemas.organization import Organization, OrganizationCreate |
| 63 | from mirix.schemas.user import User as PydanticUser |
| 64 | |
| 65 | org_id = "demo-org" |
| 66 | user_id = "demo-user" |
| 67 | |
| 68 | # Try to get existing user |
| 69 | try: |
| 70 | user = await server.user_manager.get_user_by_id(user_id) |
| 71 | if user: |
| 72 | return user |
| 73 | except Exception: |
| 74 | pass |
| 75 | |
| 76 | # Create organization if it doesn't exist |
| 77 | try: |
| 78 | org = await server.organization_manager.get_organization_by_id(org_id) |
| 79 | except Exception: |
| 80 | org_create = OrganizationCreate(id=org_id, name=org_id) |
| 81 | org = await server.organization_manager.create_organization( |
| 82 | pydantic_org=Organization(**org_create.model_dump()) |
| 83 | ) |
| 84 | |
| 85 | # Create user |
| 86 | user = await server.user_manager.create_user( |
| 87 | pydantic_user=PydanticUser( |
| 88 | id=user_id, |
| 89 | name=user_id, |
| 90 | organization_id=org.id, |
| 91 | timezone=server.user_manager.DEFAULT_TIME_ZONE, |
| 92 | ) |
| 93 | ) |
| 94 | |
| 95 | return user |
| 96 | |
| 97 | |
| 98 | @pytest_asyncio.fixture(scope="module", loop_scope="module") |
nothing calls this directly
no test coverage detected