This repository was archived by the owner on Feb 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathconftest.py
More file actions
102 lines (80 loc) · 2.58 KB
/
conftest.py
File metadata and controls
102 lines (80 loc) · 2.58 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
93
94
95
96
97
98
99
100
101
102
"""
Pytest configuration and fixtures for AnotherFasterRunner tests
"""
import os
import django
import pytest
from django.conf import settings
from django.test.utils import get_runner
from django.utils.crypto import get_random_string
def pytest_configure(config):
"""Configure pytest settings"""
# Set up Django configuration first
import os
# Use CI settings if available, otherwise fall back to dev settings
if 'DJANGO_SETTINGS_MODULE' in os.environ:
pass # Use existing setting
else:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'FasterRunner.settings.dev')
# Configure Django
import django
from django.conf import settings
if not settings.configured:
django.setup()
@pytest.fixture
def api_client():
"""Create API client for testing"""
from rest_framework.test import APIClient
return APIClient()
@pytest.fixture
def authenticated_user():
"""Create authenticated user for testing"""
from fastuser.models import MyUser
user = MyUser.objects.create_user(
username='testuser',
email='test@example.com',
password=get_random_string(32)
)
return user
@pytest.fixture
def authenticated_client(api_client, authenticated_user):
"""Create authenticated API client"""
api_client.force_authenticate(user=authenticated_user)
return api_client
@pytest.fixture
def sample_project(authenticated_user):
"""Create sample project for testing"""
from fastrunner.models import Project
return Project.objects.create(
name="Test Project",
desc="Test Description",
responsible=authenticated_user.username
)
@pytest.fixture
def sample_api(sample_project, authenticated_user):
"""Create sample API for testing"""
from fastrunner.models import API
return API.objects.create(
name="Test API",
body='{"method": "GET", "url": "/test"}',
url="/api/test",
method="GET",
project=sample_project,
relation=1,
creator=authenticated_user
)
@pytest.fixture
def sample_config(sample_project):
"""Create sample config for testing"""
from fastrunner.models import Config
return Config.objects.create(
name="Test Config",
body='{"headers": {"Content-Type": "application/json"}}',
base_url="https://api.example.com",
project=sample_project,
is_default=True
)
# Test markers for categorizing tests
pytest.mark.unit = pytest.mark.mark('unit')
pytest.mark.integration = pytest.mark.mark('integration')
pytest.mark.slow = pytest.mark.mark('slow')