Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
107 lines (89 loc) · 3.04 KB
/
Copy pathconftest.py
File metadata and controls
107 lines (89 loc) · 3.04 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
103
104
105
106
107
import pytest
from mpt_api_client.auth import BearerTokenAuthentication
from mpt_api_client.http import AsyncHTTPClient, HTTPClient, TransportSettings
from mpt_api_client.models import Model
API_TOKEN = "test-token"
API_URL = "https://api.example.com"
class DummyModel(Model):
"""Dummy resource for testing."""
@pytest.fixture
def http_client():
return HTTPClient(
transport=TransportSettings(base_url=API_URL),
authentication=BearerTokenAuthentication(API_TOKEN),
)
@pytest.fixture
def async_http_client():
return AsyncHTTPClient(
transport=TransportSettings(base_url=API_URL),
authentication=BearerTokenAuthentication(API_TOKEN),
)
@pytest.fixture
def attachment_data():
return {
"id": "ATT-001",
"name": "attachment.pdf",
"type": "Document",
"size": 2048,
"description": "Attachment description",
"contentType": "application/pdf",
}
@pytest.fixture
def document_inherited_data():
return {
"id": "DOC-001",
"name": "User Guide",
"type": "Document",
"description": "User guide document",
"status": "Active",
"filename": "guide.pdf",
"size": 4096,
"contentType": "application/pdf",
"url": "https://example.com/guide.pdf",
}
@pytest.fixture
def media_inherited_data():
return {
"id": "MED-001",
"name": "Screenshot",
"type": "Image",
"description": "Product screenshot",
"status": "Active",
"filename": "screenshot.png",
"size": 512000,
"contentType": "image/png",
"displayOrder": 1,
"url": "https://example.com/screenshot.png",
}
@pytest.fixture
def term_variant_inherited_data():
return {
"id": "TRV-001",
"name": "English Variant",
"type": "PDF",
"assetUrl": "https://example.com/file.pdf",
"languageCode": "en-US",
"description": "English language variant",
"status": "Active",
"filename": "terms.pdf",
"size": 2048,
"contentType": "application/pdf",
"fileId": "FILE-001",
}
# Error-response body shapes. Only a JSON object carries the API error members, so every
# other shape must still reach the caller as a typed error that preserves the status code:
# valid JSON that is not an object gave a raw AttributeError before MPT-25030, and bytes
# that are not valid UTF-8 escaped the decode guard as a UnicodeDecodeError.
JSON_OBJECT_ERROR_BODY = b'{"detail": "Invalid filter expression"}'
NON_OBJECT_ERROR_BODIES = (
pytest.param(b'"Invalid filter expression"', id="bare json string"),
pytest.param(b"null", id="json null"),
pytest.param(b'[{"code": "invalid-rql"}]', id="json array"),
pytest.param(b"<html>Bad Gateway</html>", id="body that is not json"),
pytest.param(b"", id="empty body"),
pytest.param("Grenzwert\u00a0erreicht".encode("iso-8859-1"), id="body that is not utf-8"),
)
ERROR_BODY_SHAPES = (
pytest.param(JSON_OBJECT_ERROR_BODY, id="json object"),
*NON_OBJECT_ERROR_BODIES,
)