-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
89 lines (68 loc) · 1.99 KB
/
Copy pathconftest.py
File metadata and controls
89 lines (68 loc) · 1.99 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
import pytest
from django.contrib.auth import get_user_model
from rest_framework.test import APIClient
from model_registry.models import Model, ModelVersion
from api_keys.models import APIKey
User = get_user_model()
from unittest.mock import MagicMock
@pytest.fixture(autouse=True)
def mock_s3(monkeypatch):
mock_client = MagicMock()
mock_client.list_objects_v2.return_value = {}
# Safely try patching if the module is loaded
try:
monkeypatch.setattr("model_registry.views.get_s3_client", lambda: mock_client)
except Exception:
pass
@pytest.fixture
def api_client():
return APIClient()
@pytest.fixture
def user(db):
return User.objects.create_user(
email="test@example.com", username="testuser", password="TestPass123!"
)
@pytest.fixture
def user2(db):
return User.objects.create_user(
email="other@example.com", username="otheruser", password="TestPass123!"
)
@pytest.fixture
def auth_client(api_client, user):
res = api_client.post(
"/api/auth/login/",
{"email": "test@example.com", "password": "TestPass123!"},
format="json",
)
token = res.data["access"]
api_client.credentials(HTTP_AUTHORIZATION=f"Bearer {token}")
return api_client
@pytest.fixture
def model_obj(db, user):
return Model.objects.create(
id="model-test-1",
name="M1",
framework="sklearn",
task_type="regression",
owner=user,
)
@pytest.fixture
def model_obj_user2(db, user2):
return Model.objects.create(
id="model-test-2",
name="M2",
framework="sklearn",
task_type="regression",
owner=user2,
)
@pytest.fixture
def model_version(db, model_obj):
return ModelVersion.objects.create(
model=model_obj,
version="v1",
artifact_path="/tmp/dummy-artifacts",
status="READY",
)
@pytest.fixture
def api_key(db, user, model_obj):
return APIKey.objects.create(user=user, model=model_obj, name="test-key")