Skip to content

Commit c6635c6

Browse files
author
Ammar Dodin
committed
💚 add tests for new query methods and training data methods
1 parent fe4392b commit c6635c6

1 file changed

Lines changed: 197 additions & 0 deletions

File tree

test/test_discovery_v1.py

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,203 @@ def test_query():
234234
assert called_url.path == test_url.path
235235
assert len(responses.calls) == 1
236236

237+
@responses.activate
238+
def test_query_relations():
239+
discovery_url = urljoin(
240+
base_discovery_url,
241+
'environments/envid/collections/collid/query_relations')
242+
243+
responses.add(
244+
responses.POST,
245+
discovery_url,
246+
body="{\"body\": \"hello\"}",
247+
status=200,
248+
content_type='application/json')
249+
250+
discovery = watson_developer_cloud.DiscoveryV1(
251+
'2016-11-07', username='username', password='password')
252+
253+
discovery.query_relations('envid', 'collid', {'count': 10})
254+
called_url = urlparse(responses.calls[0].request.url)
255+
test_url = urlparse(discovery_url)
256+
assert called_url.netloc == test_url.netloc
257+
assert called_url.path == test_url.path
258+
assert len(responses.calls) == 1
259+
260+
261+
@responses.activate
262+
def test_query_entities():
263+
discovery_url = urljoin(
264+
base_discovery_url,
265+
'environments/envid/collections/collid/query_entities')
266+
267+
responses.add(
268+
responses.POST,
269+
discovery_url,
270+
body="{\"body\": \"hello\"}",
271+
status=200,
272+
content_type='application/json')
273+
274+
discovery = watson_developer_cloud.DiscoveryV1(
275+
'2016-11-07', username='username', password='password')
276+
277+
discovery.query_entities('envid', 'collid', {'count': 10})
278+
called_url = urlparse(responses.calls[0].request.url)
279+
test_url = urlparse(discovery_url)
280+
assert called_url.netloc == test_url.netloc
281+
assert called_url.path == test_url.path
282+
assert len(responses.calls) == 1
283+
284+
285+
@responses.activate
286+
def test_training_data():
287+
discovery_url = urljoin(
288+
base_discovery_url,
289+
'environments/envid/collections/collid/training_data')
290+
examples_url = urljoin(
291+
base_discovery_url,
292+
'environments/envid/collections/collid/training_data/qid/examples')
293+
example_url = urljoin(
294+
base_discovery_url,
295+
'environments/envid/collections/collid/training_data/qid/examples/exid')
296+
data_url = urljoin(
297+
base_discovery_url,
298+
'environments/envid/collections/collid/training_data/qid')
299+
300+
responses.add(
301+
responses.POST,
302+
discovery_url,
303+
body="{\"body\": \"hello\"}",
304+
status=200,
305+
content_type='application/json')
306+
307+
responses.add(
308+
responses.DELETE,
309+
discovery_url,
310+
body="{\"body\": \"hello\"}",
311+
status=200,
312+
content_type='application/json')
313+
314+
responses.add(
315+
responses.GET,
316+
discovery_url,
317+
body="{\"body\": \"hello\"}",
318+
status=200,
319+
content_type='application/json')
320+
321+
responses.add(
322+
responses.POST,
323+
examples_url,
324+
body="{\"body\": \"hello\"}",
325+
status=200,
326+
content_type='application/json')
327+
328+
responses.add(
329+
responses.GET,
330+
examples_url,
331+
body="{\"body\": \"hello\"}",
332+
status=200,
333+
content_type='application/json')
334+
335+
responses.add(
336+
responses.DELETE,
337+
example_url,
338+
body="{\"body\": \"hello\"}",
339+
status=200,
340+
content_type='application/json')
341+
342+
responses.add(
343+
responses.GET,
344+
example_url,
345+
body="{\"body\": \"hello\"}",
346+
status=200,
347+
content_type='application/json')
348+
349+
responses.add(
350+
responses.PUT,
351+
example_url,
352+
body="{\"body\": \"hello\"}",
353+
status=200,
354+
content_type='application/json')
355+
356+
responses.add(
357+
responses.DELETE,
358+
data_url,
359+
body="{\"body\": \"hello\"}",
360+
status=200,
361+
content_type='application/json')
362+
363+
responses.add(
364+
responses.GET,
365+
data_url,
366+
body="{\"body\": \"hello\"}",
367+
status=200,
368+
content_type='application/json')
369+
370+
discovery = watson_developer_cloud.DiscoveryV1(
371+
'2016-11-07', username='username', password='password')
372+
373+
discovery.add_training_data('envid', 'collid')
374+
called_url = urlparse(responses.calls[0].request.url)
375+
test_url = urlparse(discovery_url)
376+
assert called_url.netloc == test_url.netloc
377+
assert called_url.path == test_url.path
378+
379+
discovery.get_training_data('envid', 'collid', 'qid')
380+
called_url = urlparse(responses.calls[1].request.url)
381+
test_url = urlparse(data_url)
382+
assert called_url.netloc == test_url.netloc
383+
assert called_url.path == test_url.path
384+
385+
discovery.delete_training_data('envid', 'collid', 'qid')
386+
called_url = urlparse(responses.calls[2].request.url)
387+
test_url = urlparse(data_url)
388+
assert called_url.netloc == test_url.netloc
389+
assert called_url.path == test_url.path
390+
391+
discovery.list_training_data('envid', 'collid')
392+
called_url = urlparse(responses.calls[3].request.url)
393+
test_url = urlparse(discovery_url)
394+
assert called_url.netloc == test_url.netloc
395+
assert called_url.path == test_url.path
396+
397+
discovery.delete_all_training_data('envid', 'collid')
398+
called_url = urlparse(responses.calls[4].request.url)
399+
test_url = urlparse(discovery_url)
400+
assert called_url.netloc == test_url.netloc
401+
assert called_url.path == test_url.path
402+
403+
discovery.create_training_example('envid', 'collid', 'qid')
404+
called_url = urlparse(responses.calls[5].request.url)
405+
test_url = urlparse(examples_url)
406+
assert called_url.netloc == test_url.netloc
407+
assert called_url.path == test_url.path
408+
409+
discovery.get_training_example('envid', 'collid', 'qid', 'exid')
410+
called_url = urlparse(responses.calls[6].request.url)
411+
test_url = urlparse(example_url)
412+
assert called_url.netloc == test_url.netloc
413+
assert called_url.path == test_url.path
414+
415+
discovery.update_training_example('envid', 'collid', 'qid', 'exid')
416+
called_url = urlparse(responses.calls[7].request.url)
417+
test_url = urlparse(example_url)
418+
assert called_url.netloc == test_url.netloc
419+
assert called_url.path == test_url.path
420+
421+
discovery.delete_training_example('envid', 'collid', 'qid', 'exid')
422+
called_url = urlparse(responses.calls[8].request.url)
423+
test_url = urlparse(example_url)
424+
assert called_url.netloc == test_url.netloc
425+
assert called_url.path == test_url.path
426+
427+
discovery.list_training_examples('envid', 'collid', 'qid')
428+
called_url = urlparse(responses.calls[9].request.url)
429+
test_url = urlparse(examples_url)
430+
assert called_url.netloc == test_url.netloc
431+
assert called_url.path == test_url.path
432+
433+
assert len(responses.calls) == 10
237434

238435
@responses.activate
239436
def test_configs():

0 commit comments

Comments
 (0)