Skip to content

Commit a1f57ff

Browse files
committed
deterministic way to compare URL args generated from a dict
1 parent 6dabdb8 commit a1f57ff

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/test_tone_analyzer_v3.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_success():
3131
## Invoking tone() with some modifiers given in 'params': specific tones requested, and sentences skipped
3232
def test_with_args():
3333
tone_url = 'https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone'
34-
tone_args = '?version=2016-05-19&tones=social&sentences=false'
34+
tone_args = { 'version': '2016-05-19', 'tones': 'social', 'sentences': 'false' }
3535
tone_response = None
3636
with open(os.path.join(os.path.dirname(__file__), '../resources/tone_response.json')) as response_json:
3737
tone_response = response_json.read()
@@ -46,8 +46,13 @@ def test_with_args():
4646
username="username", password="password")
4747
tone_analyzer.tone(tone_text.read(), params=params)
4848

49-
#print responses.calls[0].request.url
50-
assert responses.calls[0].request.url == tone_url + tone_args
51-
assert responses.calls[0].response.text == tone_response
5249

50+
print responses.calls[0].request.url
51+
assert responses.calls[0].request.url.split('?')[0] == tone_url
52+
# Compare args. Order is not deterministic!
53+
actualArgs = {}
54+
for arg in responses.calls[0].request.url.split('?')[1].split('&'):
55+
actualArgs[arg.split('=')[0]] = arg.split('=')[1]
56+
assert actualArgs == tone_args
57+
assert responses.calls[0].response.text == tone_response
5358
assert len(responses.calls) == 1

0 commit comments

Comments
 (0)