Skip to content

Commit 568cb2a

Browse files
committed
list models methods and tests
1 parent 13290dc commit 568cb2a

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

test/test_natural_language_understanding.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,28 @@ def test_url_analyze(self):
122122
features.Emotion(document=False)], url="http://cnn.com",
123123
xpath="/bogus/xpath", language="en")
124124
assert len(responses.calls) == 1
125+
126+
@responses.activate
127+
def test_listModels(self):
128+
nlu_url = "http://bogus.com/v1/models"
129+
responses.add(responses.GET, nlu_url, status=200, body="{\"resulting_key\": true}",
130+
content_type='application/json')
131+
nlu = NaturalLanguageUnderstandingV1(version='2016-01-23',
132+
url='http://bogus.com',
133+
username='username',
134+
password='password')
135+
nlu.listModels();
136+
assert len(responses.calls) == 1
137+
138+
@responses.activate
139+
def test_deleteModel(self):
140+
model_id = "invalid_model_id"
141+
nlu_url = "http://bogus.com/v1/models/" + model_id
142+
responses.add(responses.DELETE, nlu_url, status=200,
143+
content_type='application/json')
144+
nlu = NaturalLanguageUnderstandingV1(version='2016-01-23',
145+
url='http://bogus.com',
146+
username='username',
147+
password='password')
148+
nlu.deleteModel(model_id);
149+
assert len(responses.calls) == 1

watson_developer_cloud/natural_language_understanding_v1.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,24 @@ def analyze(self, features, text=None, url=None, html=None,
8282
headers={'content-type': 'application/json'},
8383
json=body,
8484
accept_json=True)
85+
def listModels(self):
86+
"""
87+
Lists the custom models available for your service instance
88+
:return: dict of available custom models
89+
"""
90+
return self.request(method='GET', url='/v1/models',
91+
params={"version": self.version},
92+
accept_json=True)
93+
94+
def deleteModel(self, model_id=None):
95+
"""
96+
Deletes a custom model
97+
:param model_id: The ID of the model to delete
98+
:return: dict of analyzed text
99+
"""
100+
if model_id is None:
101+
raise ValueError("Missing parameter 'model_id'")
102+
103+
return self.request(method='DELETE', url='/v1/models/'+model_id,
104+
params={"version": self.version},
105+
accept_json=True)

0 commit comments

Comments
 (0)