Skip to content

Commit 0f41152

Browse files
committed
[document-conversion] Adds unit tests
This commit adds convert_document and index_document unit tests for the python sdk project.
1 parent f7c791c commit 0f41152

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

resources/simple.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Simple HTML Page</title>
4+
</head>
5+
<body>
6+
<h1>Chapter 1</h1>
7+
<p>The content of the first chapter.</p>
8+
</body>
9+
</html>

test/test_document_conversion_v1.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# coding=utf-8
2+
import os
3+
import responses
4+
import watson_developer_cloud
5+
6+
7+
@responses.activate
8+
def test_success():
9+
convert_url = 'https://gateway.watsonplatform.net/document-conversion/api/v1/convert_document'
10+
convert_response = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><html>' \
11+
'<head><title>Simple HTML Page</title></head>' \
12+
'<body><h1>Chapter 1</h1><p>The content of the first chapter.</p></body></html>'
13+
document_conversion = watson_developer_cloud.DocumentConversionV1(
14+
username="username", password="password")
15+
16+
responses.add(responses.POST, convert_url,
17+
body=convert_response, status=200,
18+
content_type='application/json')
19+
20+
with open(os.path.join(os.path.dirname(__file__), '../resources/simple.html'), 'r') as document:
21+
config = {'conversion_target': watson_developer_cloud.DocumentConversionV1.NORMALIZED_HTML}
22+
document_conversion.convert_document(
23+
document=document, config=config, media_type='text/html')
24+
25+
assert responses.calls[
26+
1].request.url == convert_url
27+
assert responses.calls[1].response.text == convert_response
28+
29+
assert len(responses.calls) == 2
30+
31+
index_url = 'https://gateway.watsonplatform.net/document-conversion/api/v1/index_document'
32+
index_response = '{"status": "success"}'
33+
34+
responses.add(responses.POST, index_url,
35+
body=index_response, status=200,
36+
content_type='application/json')
37+
38+
with open(os.path.join(os.path.dirname(__file__), '../resources/simple.html'), 'r') as document:
39+
config = {
40+
'retrieve_and_rank': {
41+
'dry_run':'false',
42+
'service_instance_id':'serviceInstanceId',
43+
'cluster_id':'clusterId',
44+
'search_collection':'searchCollectionName'
45+
}
46+
}
47+
document_conversion.index_document(
48+
config=config, document=document)
49+
50+
assert responses.calls[
51+
1].request.url == index_url
52+
assert responses.calls[1].response.text == index_response
53+
54+
assert len(responses.calls) == 2

0 commit comments

Comments
 (0)