Skip to content

Commit 914e139

Browse files
authored
Add "valueExpression" to PropertyDescriptor class (needed for creating/adding domain calculated fields) (#79)
- add "valueExpression" to PropertyDescriptor class - update Domain class to append calculatedFields to the domain's fields - add integration test for adding calculated fields to a domain
1 parent f2037cd commit 914e139

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

CHANGE.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
LabKey Python Client API News
33
+++++++++++
44

5+
What's New in the LabKey 3.4.0 package
6+
==============================
7+
8+
*Release date: TBD*
9+
- Add "valueExpression" to PropertyDescriptor class
10+
- needed for creating/adding domain calculated fields
11+
- update Domain class to append calculatedFields to the domain's fields
12+
513
What's New in the LabKey 3.3.0 package
614
==============================
715

labkey/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
# limitations under the License.
1515
#
1616
__title__ = "labkey"
17-
__version__ = "3.3.0"
17+
__version__ = "3.4.0"
1818
__author__ = "LabKey"
1919
__license__ = "Apache License 2.0"

labkey/domain.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(self, **kwargs):
109109
)
110110
self.type_editable = kwargs.pop("type_editable", kwargs.pop("typeEditable", None))
111111
self.url = kwargs.pop("url", None)
112+
self.value_expression = kwargs.pop("value_expression", kwargs.pop("valueExpression", None))
112113

113114
def to_json(self, strip_none=True):
114115
# TODO: Likely only want to include those that are not None
@@ -155,6 +156,7 @@ def to_json(self, strip_none=True):
155156
"shownInUpdateView": self.shown_in_update_view,
156157
"typeEditable": self.type_editable,
157158
"url": self.url,
159+
"valueExpression": self.value_expression,
158160
}
159161

160162
json_formats = []
@@ -232,9 +234,11 @@ def __init__(self, **kwargs):
232234
"template_description", kwargs.pop("templateDescription", None)
233235
)
234236

235-
fields = kwargs.pop("fields", [])
236237
fields_instances = []
237-
238+
fields = kwargs.pop("fields", [])
239+
for field in fields:
240+
fields_instances.append(PropertyDescriptor(**field))
241+
fields = kwargs.pop("calculated_fields", kwargs.pop("calculatedFields", []))
238242
for field in fields:
239243
fields_instances.append(PropertyDescriptor(**field))
240244

test/integration/test_domain.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,21 @@ def test_domain_save_options(api: APIWrapper, list_fixture):
261261

262262
updated_domain, updated_options = api.domain.get_domain_details(LISTS_SCHEMA, LIST_NAME)
263263
assert updated_options.get("description") == expected_description
264+
265+
266+
def test_domain_add_calculated_field(api: APIWrapper, list_fixture):
267+
domain, options = api.domain.get_domain_details(LISTS_SCHEMA, LIST_NAME)
268+
domain.add_field({"name": "calcDouble", "conceptURI": "http://www.labkey.org/exp/xml#calculated", "valueExpression": "rowId * 2"})
269+
domain.add_field({"name": "calcCube", "conceptURI": "http://www.labkey.org/exp/xml#calculated", "valueExpression": "power(rowId, 3)"})
270+
271+
api.domain.save(LISTS_SCHEMA, LIST_NAME, domain, options=options)
272+
saved_domain = api.domain.get(LISTS_SCHEMA, LIST_NAME)
273+
274+
assert len(saved_domain.fields) == 4
275+
for field in saved_domain.fields:
276+
if field.name == "calcDouble":
277+
assert field.concept_uri == "http://www.labkey.org/exp/xml#calculated"
278+
assert field.value_expression == "rowId * 2"
279+
if field.name == "calcCube":
280+
assert field.concept_uri == "http://www.labkey.org/exp/xml#calculated"
281+
assert field.value_expression == "power(rowId, 3)"

0 commit comments

Comments
 (0)