-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
92 lines (67 loc) · 1.96 KB
/
conftest.py
File metadata and controls
92 lines (67 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
Pytest configuration and fixtures for Digital Wallet project.
"""
import pytest
# -- Pytest Configuration
def pytest_configure():
"""Configure Celery for testing."""
# Use eager mode for testing (tasks run synchronously)
from celery import current_app
current_app.conf.update(
task_always_eager=True,
task_eager_propagates=False, # Don't propagate exceptions, return them
task_store_eager_result=True,
)
# -- Fixtures
@pytest.fixture
def db_access():
"""Fixture to enable database access for tests."""
pass
@pytest.fixture
def client_user(db):
"""
Create a test client user with profile and wallet.
Returns:
tuple: (user, client_profile)
"""
from django.contrib.auth import get_user_model
from accounts.models import ClientProfile, UserType
CustomUser = get_user_model()
user = CustomUser.objects.create_user(
email="testclient@example.com",
password="testpass123",
user_type=UserType.CLIENT,
)
client_profile = ClientProfile.objects.get(user=user)
return user, client_profile
@pytest.fixture
def auth_client(client_user):
"""
Create an authenticated test client.
Returns:
Client: Logged-in Django test client
"""
from django.test import Client
user, client_profile = client_user
client = Client()
client.force_login(user)
return client
@pytest.fixture
def auth_client_no_wallet(db):
"""
Create an authenticated client without a wallet.
Returns:
Client: Logged-in Django test client
"""
from django.contrib.auth import get_user_model
from django.test import Client
from accounts.models import UserType
CustomUser = get_user_model()
user = CustomUser.objects.create_user(
email="testclient-nowallet@example.com",
password="testpass123",
user_type=UserType.CLIENT,
)
client = Client()
client.force_login(user)
return client