3
3
import os
4
4
5
5
# Set test environment before any other imports
6
- os .environ .update ({
7
- "SECRET_KEY" : "secret-key" ,
8
- "DATABASE_URL" : "sqlite+aiosqlite:///:memory:" ,
9
- "DATABASE_ECHO" : "false" ,
10
- "DATABASE_ECHO_POOL" : "false" ,
11
- "VALKEY_PORT" : "6308" ,
12
- "REDIS_URL" : "redis://localhost:6308/0" ,
13
- "SAQ_USE_SERVER_LIFESPAN" : "False" ,
14
- "SAQ_WEB_ENABLED" : "True" ,
15
- "SAQ_BACKGROUND_WORKERS" : "1" ,
16
- "SAQ_CONCURRENCY" : "1" ,
17
- "VITE_HOST" : "localhost" ,
18
- "VITE_PORT" : "3006" ,
19
- "VITE_HOT_RELOAD" : "True" ,
20
- "VITE_DEV_MODE" : "True" ,
21
- "VITE_USE_SERVER_LIFESPAN" : "False" ,
22
- "EMAIL_ENABLED" : "false" ,
23
- })
6
+ os .environ .update (
7
+ {
8
+ "SECRET_KEY" : "secret-key" ,
9
+ "DATABASE_URL" : "sqlite+aiosqlite:///:memory:" ,
10
+ "DATABASE_ECHO" : "false" ,
11
+ "DATABASE_ECHO_POOL" : "false" ,
12
+ "VALKEY_PORT" : "6308" ,
13
+ "REDIS_URL" : "redis://localhost:6308/0" ,
14
+ "SAQ_USE_SERVER_LIFESPAN" : "False" ,
15
+ "SAQ_WEB_ENABLED" : "True" ,
16
+ "SAQ_BACKGROUND_WORKERS" : "1" ,
17
+ "SAQ_CONCURRENCY" : "1" ,
18
+ "VITE_HOST" : "localhost" ,
19
+ "VITE_PORT" : "3006" ,
20
+ "VITE_HOT_RELOAD" : "True" ,
21
+ "VITE_DEV_MODE" : "True" ,
22
+ "VITE_USE_SERVER_LIFESPAN" : "False" ,
23
+ "EMAIL_ENABLED" : "false" ,
24
+ }
25
+ )
24
26
25
27
from typing import TYPE_CHECKING
26
28
from uuid import uuid4
@@ -57,7 +59,6 @@ def anyio_backend() -> str:
57
59
@pytest .fixture (autouse = True )
58
60
def _patch_settings (monkeypatch : MonkeyPatch ) -> None :
59
61
"""Patch the settings - environment already set at module level."""
60
- pass
61
62
62
63
63
64
@pytest .fixture (name = "engine" )
@@ -111,9 +112,11 @@ async def session(sessionmaker: async_sessionmaker[AsyncSession]) -> AsyncGenera
111
112
def app ():
112
113
"""Create Litestar app for testing."""
113
114
import os
115
+
114
116
os .environ .setdefault ("DATABASE_URL" , "sqlite:///:memory:" )
115
-
117
+
116
118
from app .server .asgi import create_app
119
+
117
120
return create_app ()
118
121
119
122
@@ -128,6 +131,7 @@ async def client(app: Litestar) -> AsyncGenerator[AsyncTestClient, None]:
128
131
async def user_service (sessionmaker : async_sessionmaker [AsyncSession ]):
129
132
"""Create UserService instance."""
130
133
from app .services import UserService
134
+
131
135
async with UserService .new (sessionmaker ()) as service :
132
136
yield service
133
137
@@ -136,6 +140,7 @@ async def user_service(sessionmaker: async_sessionmaker[AsyncSession]):
136
140
async def team_service (sessionmaker : async_sessionmaker [AsyncSession ]):
137
141
"""Create TeamService instance."""
138
142
from app .services import TeamService
143
+
139
144
async with TeamService .new (sessionmaker ()) as service :
140
145
yield service
141
146
@@ -145,7 +150,7 @@ async def test_user(session: AsyncSession):
145
150
"""Create a test user."""
146
151
from app .db import models as m
147
152
from app .lib .crypt import get_password_hash
148
-
153
+
149
154
user = m .User (
150
155
id = uuid4 (),
151
156
@@ -165,7 +170,7 @@ async def admin_user(session: AsyncSession):
165
170
"""Create an admin user."""
166
171
from app .db import models as m
167
172
from app .lib .crypt import get_password_hash
168
-
173
+
169
174
user = m .User (
170
175
id = uuid4 (),
171
176
@@ -187,7 +192,7 @@ async def test_team(session: AsyncSession, test_user):
187
192
from app .db import models as m
188
193
from app .db .models .team_member import TeamMember
189
194
from app .db .models .team_roles import TeamRoles
190
-
195
+
191
196
team = m .Team (
192
197
id = uuid4 (),
193
198
name = "Test Team" ,
@@ -247,6 +252,7 @@ async def admin_client(client: AsyncTestClient, admin_user) -> AsyncTestClient:
247
252
async def email_verification_service (sessionmaker : async_sessionmaker [AsyncSession ]):
248
253
"""Create EmailVerificationTokenService instance."""
249
254
from app .services import EmailVerificationTokenService
255
+
250
256
async with EmailVerificationTokenService .new (sessionmaker ()) as service :
251
257
yield service
252
258
@@ -255,6 +261,7 @@ async def email_verification_service(sessionmaker: async_sessionmaker[AsyncSessi
255
261
async def password_reset_service (sessionmaker : async_sessionmaker [AsyncSession ]):
256
262
"""Create PasswordResetService instance."""
257
263
from app .services import PasswordResetService
264
+
258
265
async with PasswordResetService .new (sessionmaker ()) as service :
259
266
yield service
260
267
@@ -263,6 +270,7 @@ async def password_reset_service(sessionmaker: async_sessionmaker[AsyncSession])
263
270
async def role_service (sessionmaker : async_sessionmaker [AsyncSession ]):
264
271
"""Create RoleService instance."""
265
272
from app .services import RoleService
273
+
266
274
async with RoleService .new (sessionmaker ()) as service :
267
275
yield service
268
276
@@ -271,6 +279,7 @@ async def role_service(sessionmaker: async_sessionmaker[AsyncSession]):
271
279
async def tag_service (sessionmaker : async_sessionmaker [AsyncSession ]):
272
280
"""Create TagService instance."""
273
281
from app .services import TagService
282
+
274
283
async with TagService .new (sessionmaker ()) as service :
275
284
yield service
276
285
@@ -279,6 +288,7 @@ async def tag_service(sessionmaker: async_sessionmaker[AsyncSession]):
279
288
async def team_member_service (sessionmaker : async_sessionmaker [AsyncSession ]):
280
289
"""Create TeamMemberService instance."""
281
290
from app .services import TeamMemberService
291
+
282
292
async with TeamMemberService .new (sessionmaker ()) as service :
283
293
yield service
284
294
@@ -287,6 +297,7 @@ async def team_member_service(sessionmaker: async_sessionmaker[AsyncSession]):
287
297
async def team_invitation_service (sessionmaker : async_sessionmaker [AsyncSession ]):
288
298
"""Create TeamInvitationService instance."""
289
299
from app .services import TeamInvitationService
300
+
290
301
async with TeamInvitationService .new (sessionmaker ()) as service :
291
302
yield service
292
303
@@ -295,6 +306,7 @@ async def team_invitation_service(sessionmaker: async_sessionmaker[AsyncSession]
295
306
async def user_role_service (sessionmaker : async_sessionmaker [AsyncSession ]):
296
307
"""Create UserRoleService instance."""
297
308
from app .services import UserRoleService
309
+
298
310
async with UserRoleService .new (sessionmaker ()) as service :
299
311
yield service
300
312
@@ -303,6 +315,7 @@ async def user_role_service(sessionmaker: async_sessionmaker[AsyncSession]):
303
315
async def user_oauth_service (sessionmaker : async_sessionmaker [AsyncSession ]):
304
316
"""Create UserOAuthAccountService instance."""
305
317
from app .services import UserOAuthAccountService
318
+
306
319
async with UserOAuthAccountService .new (sessionmaker ()) as service :
307
320
yield service
308
321
@@ -311,6 +324,7 @@ async def user_oauth_service(sessionmaker: async_sessionmaker[AsyncSession]):
311
324
def email_service ():
312
325
"""Create EmailService instance for testing."""
313
326
from app .lib .email import EmailService
327
+
314
328
return EmailService ()
315
329
316
330
@@ -320,7 +334,7 @@ async def unverified_user(session: AsyncSession):
320
334
"""Create an unverified user."""
321
335
from app .db import models as m
322
336
from app .lib .crypt import get_password_hash
323
-
337
+
324
338
user = m .User (
325
339
id = uuid4 (),
326
340
@@ -340,7 +354,7 @@ async def inactive_user(session: AsyncSession):
340
354
"""Create an inactive user."""
341
355
from app .db import models as m
342
356
from app .lib .crypt import get_password_hash
343
-
357
+
344
358
user = m .User (
345
359
id = uuid4 (),
346
360
@@ -359,7 +373,7 @@ async def inactive_user(session: AsyncSession):
359
373
async def test_role (session : AsyncSession ):
360
374
"""Create a test role."""
361
375
from app .db import models as m
362
-
376
+
363
377
role = m .Role (
364
378
id = uuid4 (),
365
379
name = "test_role" ,
@@ -376,7 +390,7 @@ async def test_role(session: AsyncSession):
376
390
async def test_tag (session : AsyncSession ):
377
391
"""Create a test tag."""
378
392
from app .db import models as m
379
-
393
+
380
394
tag = m .Tag (
381
395
id = uuid4 (),
382
396
name = "test_tag" ,
@@ -393,6 +407,7 @@ async def test_tag(session: AsyncSession):
393
407
async def test_verification_token (session : AsyncSession , unverified_user ):
394
408
"""Create a test email verification token."""
395
409
from datetime import UTC , datetime , timedelta
410
+
396
411
from app .db import models as m
397
412
398
413
token = m .EmailVerificationToken (
@@ -411,6 +426,7 @@ async def test_verification_token(session: AsyncSession, unverified_user):
411
426
async def test_password_reset_token (session : AsyncSession , test_user ):
412
427
"""Create a test password reset token."""
413
428
from datetime import UTC , datetime , timedelta
429
+
414
430
from app .db import models as m
415
431
416
432
token = m .PasswordResetToken (
@@ -431,6 +447,7 @@ async def test_password_reset_token(session: AsyncSession, test_user):
431
447
async def test_oauth_account (session : AsyncSession , test_user ):
432
448
"""Create a test OAuth account."""
433
449
from datetime import UTC , datetime , timedelta
450
+
434
451
from app .db import models as m
435
452
436
453
oauth_account = m .UserOauthAccount (
@@ -459,6 +476,7 @@ async def test_oauth_account(session: AsyncSession, test_user):
459
476
async def test_team_invitation (session : AsyncSession , test_team , test_user ):
460
477
"""Create a test team invitation."""
461
478
from datetime import UTC , datetime , timedelta
479
+
462
480
from app .db import models as m
463
481
464
482
invitation = m .TeamInvitation (
0 commit comments