Skip to content

Commit a28b7f0

Browse files
author
Saurabh Badenkal
committed
Clean up code quality: remove unused imports, dead code, compile inline regex
- Remove unused imports in test_batch_edge_cases.py (_RecordCreate, _RecordUpdate, _QuerySql, _TableList) - Remove unused BatchResult import in test_batch_serialization.py - Remove dead _mock_batch_response function in test_batch_scenarios.py - Compile boundary regex to module-level _BOUNDARY_RE constant in _batch.py
1 parent be47e9e commit a28b7f0

4 files changed

Lines changed: 5 additions & 50 deletions

File tree

src/PowerPlatform/Dataverse/data/_batch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,11 @@ def _raise_top_level_batch_error(response: Any) -> None:
594594
)
595595

596596

597+
_BOUNDARY_RE = re.compile(r'boundary="?([^";,\s]+)"?', re.IGNORECASE)
598+
599+
597600
def _extract_boundary(content_type: str) -> Optional[str]:
598-
m = re.search(r'boundary="?([^";,\s]+)"?', content_type, re.IGNORECASE)
601+
m = _BOUNDARY_RE.search(content_type)
599602
return m.group(1) if m else None
600603

601604

tests/unit/data/test_batch_edge_cases.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616
_BatchClient,
1717
_ChangeSet,
1818
_ChangeSetBatchItem,
19-
_RecordCreate,
2019
_RecordDelete,
2120
_RecordGet,
22-
_RecordUpdate,
23-
_QuerySql,
24-
_TableList,
2521
_extract_boundary,
2622
_raise_top_level_batch_error,
2723
_split_multipart,

tests/unit/data/test_batch_serialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from PowerPlatform.Dataverse.core.errors import HttpError
3030
from PowerPlatform.Dataverse.models.upsert import UpsertItem
3131
from PowerPlatform.Dataverse.data._raw_request import _RawRequest
32-
from PowerPlatform.Dataverse.models.batch import BatchItemResponse, BatchResult
32+
from PowerPlatform.Dataverse.models.batch import BatchItemResponse
3333

3434

3535
def _make_od():

tests/unit/test_batch_scenarios.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,50 +28,6 @@ def _make_od():
2828
return od
2929

3030

31-
def _mock_batch_response(batch_boundary, parts):
32-
"""Build a mock HTTP response from a list of (status, headers_dict, body_str) tuples."""
33-
body_parts = []
34-
for status_line, headers, body in parts:
35-
lines = [
36-
f"--{batch_boundary}",
37-
"Content-Type: application/http",
38-
"Content-Transfer-Encoding: binary",
39-
]
40-
for k, v in (headers or {}).items():
41-
lines.append(f"{k}: {v}")
42-
lines.append("")
43-
lines.append(status_line)
44-
for k, v in (headers or {}).items():
45-
if k.lower() != "content-id":
46-
pass # handled below
47-
# Add response headers that contain OData-EntityId, Content-Type, etc.
48-
resp_lines = [status_line]
49-
if body:
50-
resp_lines.append("Content-Type: application/json; odata.metadata=minimal")
51-
resp_lines.append("OData-Version: 4.0")
52-
# Add OData-EntityId if present in headers
53-
for k, v in (headers or {}).items():
54-
resp_lines.append(f"{k}: {v}")
55-
resp_lines.append("")
56-
if body:
57-
resp_lines.append(body)
58-
resp_text = "\r\n".join(resp_lines)
59-
part = (
60-
f"--{batch_boundary}\r\n"
61-
"Content-Type: application/http\r\n"
62-
"Content-Transfer-Encoding: binary\r\n"
63-
"\r\n" + resp_text + "\r\n"
64-
)
65-
body_parts.append(part)
66-
body_parts.append(f"--{batch_boundary}--\r\n")
67-
full_body = "".join(body_parts)
68-
69-
mock_resp = MagicMock()
70-
mock_resp.headers = {"Content-Type": f'multipart/mixed; boundary="{batch_boundary}"'}
71-
mock_resp.text = full_body
72-
return mock_resp
73-
74-
7531
# ---------------------------------------------------------------------------
7632
# Scenario 1: Response ordering matches operation order
7733
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)