Skip to content

Commit 1387796

Browse files
tpellissierclaude
andcommitted
Format code with black
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0d177ff commit 1387796

5 files changed

Lines changed: 27 additions & 57 deletions

File tree

src/PowerPlatform/Dataverse/data/_odata.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
from ..__version__ import __version__ as _SDK_VERSION
3939

40-
4140
_USER_AGENT = f"DataverseSvcPythonClient:{_SDK_VERSION}"
4241
_GUID_RE = re.compile(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}")
4342
_CALL_SCOPE_CORRELATION_ID: ContextVar[Optional[str]] = ContextVar("_CALL_SCOPE_CORRELATION_ID", default=None)

src/PowerPlatform/Dataverse/data/_relationships.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ def _get_relationship(self, schema_name: str) -> Optional[Dict[str, Any]]:
139139
:raises HttpError: If the Web API request fails.
140140
"""
141141
url = f"{self.api}/RelationshipDefinitions"
142-
params = {
143-
"$filter": f"SchemaName eq '{schema_name}'"
144-
}
142+
params = {"$filter": f"SchemaName eq '{schema_name}'"}
145143
r = self._request("get", url, headers=self._headers(), params=params)
146144
data = r.json()
147145
results = data.get("value", [])
@@ -159,5 +157,5 @@ def _extract_id_from_header(self, header_value: Optional[str]) -> Optional[str]:
159157
"""
160158
if not header_value:
161159
return None
162-
match = re.search(r'\(([0-9a-fA-F-]+)\)', header_value)
160+
match = re.search(r"\(([0-9a-fA-F-]+)\)", header_value)
163161
return match.group(1) if match else None

src/PowerPlatform/Dataverse/extensions/relationships.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,18 @@ def create_lookup_field(
8787
print(f"Created lookup: {result['lookup_schema_name']}")
8888
"""
8989
# Build the label
90-
localized_labels = [LocalizedLabel(
91-
label=display_name or referenced_table,
92-
language_code=language_code
93-
)]
90+
localized_labels = [LocalizedLabel(label=display_name or referenced_table, language_code=language_code)]
9491

9592
# Build the lookup attribute
9693
lookup = LookupAttributeMetadata(
9794
schema_name=lookup_field_name,
9895
display_name=Label(localized_labels=localized_labels),
99-
required_level="ApplicationRequired" if required else "None"
96+
required_level="ApplicationRequired" if required else "None",
10097
)
10198

10299
# Add description if provided
103100
if description:
104-
lookup.description = Label(
105-
localized_labels=[LocalizedLabel(
106-
label=description,
107-
language_code=language_code
108-
)]
109-
)
101+
lookup.description = Label(localized_labels=[LocalizedLabel(label=description, language_code=language_code)])
110102

111103
# Generate a relationship name if not provided
112104
relationship_name = f"{referenced_table}_{referencing_table}_{lookup_field_name}"
@@ -117,15 +109,11 @@ def create_lookup_field(
117109
referenced_entity=referenced_table,
118110
referencing_entity=referencing_table,
119111
referenced_attribute=f"{referenced_table}id",
120-
cascade_configuration=CascadeConfiguration(delete=cascade_delete)
112+
cascade_configuration=CascadeConfiguration(delete=cascade_delete),
121113
)
122114

123115
# Delegate to client
124-
return client.create_one_to_many_relationship(
125-
lookup,
126-
relationship,
127-
solution_unique_name
128-
)
116+
return client.create_one_to_many_relationship(lookup, relationship, solution_unique_name)
129117

130118

131119
__all__ = ["create_lookup_field"]

src/PowerPlatform/Dataverse/models/metadata.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class LocalizedLabel:
2929
in the Web API payload. These are merged last and can override default values.
3030
:type additional_properties: Optional[Dict[str, Any]]
3131
"""
32+
3233
label: str
3334
language_code: int
3435
additional_properties: Optional[Dict[str, Any]] = None
@@ -58,6 +59,7 @@ class Label:
5859
in the Web API payload. These are merged last and can override default values.
5960
:type additional_properties: Optional[Dict[str, Any]]
6061
"""
62+
6163
localized_labels: List[LocalizedLabel]
6264
user_localized_label: Optional[LocalizedLabel] = None
6365
additional_properties: Optional[Dict[str, Any]] = None
@@ -106,6 +108,7 @@ class CascadeConfiguration:
106108
- "RemoveLink": Remove the relationship link but keep the records
107109
- "Restrict": Prevent the operation if related records exist
108110
"""
111+
109112
assign: str = "NoCascade"
110113
delete: str = "RemoveLink"
111114
merge: str = "NoCascade"
@@ -152,6 +155,7 @@ class AssociatedMenuConfiguration:
152155
- "UseLabel": Use the specified label
153156
- "DoNotDisplay": Do not display in the menu
154157
"""
158+
155159
behavior: str = "UseLabel"
156160
group: str = "Details"
157161
label: Optional[Label] = None
@@ -197,6 +201,7 @@ class LookupAttributeMetadata:
197201
- "Recommended": The attribute is recommended
198202
- "ApplicationRequired": The attribute is required
199203
"""
204+
200205
schema_name: str
201206
display_name: Label
202207
description: Optional[Label] = None
@@ -209,15 +214,13 @@ def to_dict(self) -> Dict[str, Any]:
209214
"@odata.type": "Microsoft.Dynamics.CRM.LookupAttributeMetadata",
210215
"SchemaName": self.schema_name,
211216
"AttributeType": "Lookup",
212-
"AttributeTypeName": {
213-
"Value": "LookupType"
214-
},
217+
"AttributeTypeName": {"Value": "LookupType"},
215218
"DisplayName": self.display_name.to_dict(),
216219
"RequiredLevel": {
217220
"Value": self.required_level,
218221
"CanBeChanged": True,
219-
"ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
220-
}
222+
"ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings",
223+
},
221224
}
222225
if self.description:
223226
result["Description"] = self.description.to_dict()
@@ -251,6 +254,7 @@ class OneToManyRelationshipMetadata:
251254
These are merged last and can override default values.
252255
:type additional_properties: Optional[Dict[str, Any]]
253256
"""
257+
254258
schema_name: str
255259
referenced_entity: str
256260
referencing_entity: str
@@ -303,6 +307,7 @@ class ManyToManyRelationshipMetadata:
303307
and can override default values.
304308
:type additional_properties: Optional[Dict[str, Any]]
305309
"""
310+
306311
schema_name: str
307312
entity1_logical_name: str
308313
entity2_logical_name: str

tests/unit/models/test_metadata.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ class TestLabel:
5757

5858
def test_to_dict_basic(self):
5959
"""Test basic serialization with auto UserLocalizedLabel."""
60-
label = Label(
61-
localized_labels=[LocalizedLabel(label="Test", language_code=1033)]
62-
)
60+
label = Label(localized_labels=[LocalizedLabel(label="Test", language_code=1033)])
6361
result = label.to_dict()
6462

6563
assert result["@odata.type"] == "Microsoft.Dynamics.CRM.Label"
@@ -149,9 +147,7 @@ def test_to_dict_defaults(self):
149147
def test_to_dict_with_label(self):
150148
"""Test with a label."""
151149
menu = AssociatedMenuConfiguration(
152-
label=Label(
153-
localized_labels=[LocalizedLabel(label="Related Items", language_code=1033)]
154-
)
150+
label=Label(localized_labels=[LocalizedLabel(label="Related Items", language_code=1033)])
155151
)
156152
result = menu.to_dict()
157153

@@ -180,9 +176,7 @@ def test_to_dict_basic(self):
180176
"""Test basic serialization."""
181177
lookup = LookupAttributeMetadata(
182178
schema_name="new_AccountId",
183-
display_name=Label(
184-
localized_labels=[LocalizedLabel(label="Account", language_code=1033)]
185-
),
179+
display_name=Label(localized_labels=[LocalizedLabel(label="Account", language_code=1033)]),
186180
)
187181
result = lookup.to_dict()
188182

@@ -196,9 +190,7 @@ def test_to_dict_required(self):
196190
"""Test required level."""
197191
lookup = LookupAttributeMetadata(
198192
schema_name="new_AccountId",
199-
display_name=Label(
200-
localized_labels=[LocalizedLabel(label="Account", language_code=1033)]
201-
),
193+
display_name=Label(localized_labels=[LocalizedLabel(label="Account", language_code=1033)]),
202194
required_level="ApplicationRequired",
203195
)
204196
result = lookup.to_dict()
@@ -209,12 +201,8 @@ def test_to_dict_with_description(self):
209201
"""Test with description."""
210202
lookup = LookupAttributeMetadata(
211203
schema_name="new_AccountId",
212-
display_name=Label(
213-
localized_labels=[LocalizedLabel(label="Account", language_code=1033)]
214-
),
215-
description=Label(
216-
localized_labels=[LocalizedLabel(label="The related account", language_code=1033)]
217-
),
204+
display_name=Label(localized_labels=[LocalizedLabel(label="Account", language_code=1033)]),
205+
description=Label(localized_labels=[LocalizedLabel(label="The related account", language_code=1033)]),
218206
)
219207
result = lookup.to_dict()
220208

@@ -225,9 +213,7 @@ def test_to_dict_with_additional_properties(self):
225213
"""Test additional properties like Targets and IsSecured."""
226214
lookup = LookupAttributeMetadata(
227215
schema_name="new_ParentId",
228-
display_name=Label(
229-
localized_labels=[LocalizedLabel(label="Parent", language_code=1033)]
230-
),
216+
display_name=Label(localized_labels=[LocalizedLabel(label="Parent", language_code=1033)]),
231217
additional_properties={
232218
"Targets": ["account", "contact"],
233219
"IsSecured": True,
@@ -287,9 +273,7 @@ def test_to_dict_with_menu_configuration(self):
287273
referenced_attribute="accountid",
288274
associated_menu_configuration=AssociatedMenuConfiguration(
289275
behavior="UseLabel",
290-
label=Label(
291-
localized_labels=[LocalizedLabel(label="Orders", language_code=1033)]
292-
),
276+
label=Label(localized_labels=[LocalizedLabel(label="Orders", language_code=1033)]),
293277
),
294278
)
295279
result = rel.to_dict()
@@ -368,14 +352,10 @@ def test_to_dict_with_menu_configurations(self):
368352
entity1_logical_name="account",
369353
entity2_logical_name="contact",
370354
entity1_associated_menu_configuration=AssociatedMenuConfiguration(
371-
label=Label(
372-
localized_labels=[LocalizedLabel(label="Contacts", language_code=1033)]
373-
)
355+
label=Label(localized_labels=[LocalizedLabel(label="Contacts", language_code=1033)])
374356
),
375357
entity2_associated_menu_configuration=AssociatedMenuConfiguration(
376-
label=Label(
377-
localized_labels=[LocalizedLabel(label="Accounts", language_code=1033)]
378-
)
358+
label=Label(localized_labels=[LocalizedLabel(label="Accounts", language_code=1033)])
379359
),
380360
)
381361
result = rel.to_dict()

0 commit comments

Comments
 (0)