diff --git a/labelbox/client.py b/labelbox/client.py index a15c62a37..c7a1eb3c7 100644 --- a/labelbox/client.py +++ b/labelbox/client.py @@ -1685,3 +1685,30 @@ def delete_feature_schema_from_ontology( raise labelbox.exceptions.LabelboxError( "Failed to remove feature schema from ontology, message: " + str(response.json()['message'])) + + def unarchive_feature_schema_node(self, ontology_id: str, + root_feature_schema_id: str) -> None: + """ + Unarchives a feature schema node in an ontology. + Only root level feature schema nodes can be unarchived. + Args: + ontology_id (str): The ID of the ontology + root_feature_schema_id (str): The ID of the root level feature schema + Returns: + None + """ + ontology_endpoint = self.rest_endpoint + "/ontologies/" + urllib.parse.quote( + ontology_id) + '/feature-schemas/' + urllib.parse.quote( + root_feature_schema_id) + '/unarchive' + response = requests.patch( + ontology_endpoint, + headers=self.headers, + ) + if response.status_code == requests.codes.ok: + if not bool(response.json()['unarchived']): + raise labelbox.exceptions.LabelboxError( + "Failed unarchive the feature schema.") + else: + raise labelbox.exceptions.LabelboxError( + "Failed unarchive the feature schema node, message: ", + response.text) diff --git a/tests/integration/test_ontology.py b/tests/integration/test_ontology.py index 415cfa80e..e95e9eff7 100644 --- a/tests/integration/test_ontology.py +++ b/tests/integration/test_ontology.py @@ -246,3 +246,30 @@ def test_ontology_create_read(client, rand_gen): assert _get_attr_stringify_json(created_ontology, attr) == _get_attr_stringify_json( queried_ontology, attr) + + +def test_unarchive_feature_schema_node(client, ontology): + feature_schema_to_unarchive = ontology.normalized['tools'][0] + result = client.unarchive_feature_schema_node( + ontology.uid, feature_schema_to_unarchive['featureSchemaId']) + assert result == None + + +def test_unarchive_feature_schema_node_for_non_existing_feature_schema( + client, ontology): + with pytest.raises( + Exception, + match= + "Failed to find feature schema node by id: invalid-feature-schema-id" + ): + client.unarchive_feature_schema_node(ontology.uid, + 'invalid-feature-schema-id') + + +def test_unarchive_feature_schema_node_for_non_existing_ontology( + client, ontology): + feature_schema_to_unarchive = ontology.normalized['tools'][0] + with pytest.raises(Exception, + match="Failed to find ontology by id: invalid-ontology"): + client.unarchive_feature_schema_node( + 'invalid-ontology', feature_schema_to_unarchive['featureSchemaId'])