Skip to content

Commit 1f511f6

Browse files
authored
Merge pull request #939 from Labelbox/PTDT-1108
[PTDT-1108] Added client method unarchive_root_schema_node
2 parents aa69e7b + 5f89245 commit 1f511f6

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

labelbox/client.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,3 +1685,30 @@ def delete_feature_schema_from_ontology(
16851685
raise labelbox.exceptions.LabelboxError(
16861686
"Failed to remove feature schema from ontology, message: " +
16871687
str(response.json()['message']))
1688+
1689+
def unarchive_feature_schema_node(self, ontology_id: str,
1690+
root_feature_schema_id: str) -> None:
1691+
"""
1692+
Unarchives a feature schema node in an ontology.
1693+
Only root level feature schema nodes can be unarchived.
1694+
Args:
1695+
ontology_id (str): The ID of the ontology
1696+
root_feature_schema_id (str): The ID of the root level feature schema
1697+
Returns:
1698+
None
1699+
"""
1700+
ontology_endpoint = self.rest_endpoint + "/ontologies/" + urllib.parse.quote(
1701+
ontology_id) + '/feature-schemas/' + urllib.parse.quote(
1702+
root_feature_schema_id) + '/unarchive'
1703+
response = requests.patch(
1704+
ontology_endpoint,
1705+
headers=self.headers,
1706+
)
1707+
if response.status_code == requests.codes.ok:
1708+
if not bool(response.json()['unarchived']):
1709+
raise labelbox.exceptions.LabelboxError(
1710+
"Failed unarchive the feature schema.")
1711+
else:
1712+
raise labelbox.exceptions.LabelboxError(
1713+
"Failed unarchive the feature schema node, message: ",
1714+
response.text)

tests/integration/test_ontology.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,30 @@ def test_ontology_create_read(client, rand_gen):
246246
assert _get_attr_stringify_json(created_ontology,
247247
attr) == _get_attr_stringify_json(
248248
queried_ontology, attr)
249+
250+
251+
def test_unarchive_feature_schema_node(client, ontology):
252+
feature_schema_to_unarchive = ontology.normalized['tools'][0]
253+
result = client.unarchive_feature_schema_node(
254+
ontology.uid, feature_schema_to_unarchive['featureSchemaId'])
255+
assert result == None
256+
257+
258+
def test_unarchive_feature_schema_node_for_non_existing_feature_schema(
259+
client, ontology):
260+
with pytest.raises(
261+
Exception,
262+
match=
263+
"Failed to find feature schema node by id: invalid-feature-schema-id"
264+
):
265+
client.unarchive_feature_schema_node(ontology.uid,
266+
'invalid-feature-schema-id')
267+
268+
269+
def test_unarchive_feature_schema_node_for_non_existing_ontology(
270+
client, ontology):
271+
feature_schema_to_unarchive = ontology.normalized['tools'][0]
272+
with pytest.raises(Exception,
273+
match="Failed to find ontology by id: invalid-ontology"):
274+
client.unarchive_feature_schema_node(
275+
'invalid-ontology', feature_schema_to_unarchive['featureSchemaId'])

0 commit comments

Comments
 (0)