|
8 | 8 | and unified metadata cache introduced for explicit naming enforcement. |
9 | 9 | """ |
10 | 10 |
|
11 | | -import types |
12 | 11 | import pytest |
13 | | -from dataverse_sdk.data.odata import ODataClient |
14 | 12 | from dataverse_sdk.core.errors import MetadataError |
15 | | - |
16 | | - |
17 | | -class DummyAuth: |
18 | | - """Mock authentication for testing.""" |
19 | | - def acquire_token(self, scope): |
20 | | - class T: |
21 | | - access_token = "test_token" |
22 | | - return T() |
23 | | - |
24 | | - |
25 | | -class DummyHTTPClient: |
26 | | - """Mock HTTP client that returns pre-configured responses.""" |
27 | | - def __init__(self, responses): |
28 | | - self._responses = responses |
29 | | - self.calls = [] |
30 | | - |
31 | | - def request(self, method, url, **kwargs): |
32 | | - self.calls.append((method, url, kwargs)) |
33 | | - if not self._responses: |
34 | | - raise AssertionError("No more dummy responses configured") |
35 | | - status, headers, body = self._responses.pop(0) |
36 | | - resp = types.SimpleNamespace() |
37 | | - resp.status_code = status |
38 | | - resp.headers = headers |
39 | | - resp.text = "" if body is None else ("{}" if isinstance(body, dict) else str(body)) |
40 | | - |
41 | | - def raise_for_status(): |
42 | | - if status >= 400: |
43 | | - raise RuntimeError(f"HTTP {status}") |
44 | | - return None |
45 | | - |
46 | | - def json_func(): |
47 | | - return body if isinstance(body, dict) else {} |
48 | | - |
49 | | - resp.raise_for_status = raise_for_status |
50 | | - resp.json = json_func |
51 | | - return resp |
52 | | - |
53 | | - |
54 | | -class TestableClient(ODataClient): |
55 | | - """ODataClient with mocked HTTP for testing.""" |
56 | | - def __init__(self, responses): |
57 | | - super().__init__(DummyAuth(), "https://org.example", None) |
58 | | - self._http = DummyHTTPClient(responses) |
59 | | - |
60 | | - def _convert_labels_to_ints(self, logical_name, record): |
61 | | - """Test shim - no-op conversion.""" |
62 | | - return record |
63 | | - |
| 13 | +from tests.unit.test_helpers import ( |
| 14 | + TestableClient, |
| 15 | + MD_ACCOUNT, |
| 16 | + MD_SAMPLE_ITEM, |
| 17 | + make_entity_create_headers |
| 18 | +) |
64 | 19 |
|
65 | 20 | # ============================================================================ |
66 | | -# Test Data - Metadata Responses |
| 21 | +# Test Data - Additional Metadata Responses for this test file |
67 | 22 | # ============================================================================ |
68 | 23 |
|
69 | | -MD_SAMPLE_ITEM = { |
70 | | - "value": [ |
71 | | - { |
72 | | - "LogicalName": "new_sampleitem", |
73 | | - "EntitySetName": "new_sampleitems", |
74 | | - "SchemaName": "new_Sampleitem", |
75 | | - "PrimaryIdAttribute": "new_sampleitemid" |
76 | | - } |
77 | | - ] |
78 | | -} |
79 | | - |
80 | | -MD_ACCOUNT = { |
81 | | - "value": [ |
82 | | - { |
83 | | - "LogicalName": "account", |
84 | | - "EntitySetName": "accounts", |
85 | | - "SchemaName": "Account", |
86 | | - "PrimaryIdAttribute": "accountid" |
87 | | - } |
88 | | - ] |
89 | | -} |
90 | | - |
91 | 24 | MD_ENTITY_BY_LOGICAL = { |
92 | 25 | "LogicalName": "new_sampleitem", |
93 | 26 | "EntitySetName": "new_sampleitems", |
|
0 commit comments