Skip to content

Commit ba3067f

Browse files
committed
Tone: Accommodate non-deternminstic ordering of method parameters
1 parent 84b052d commit ba3067f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

test/test_tone_analyzer_v3.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def test_tone_with_args():
4545
username="username", password="password")
4646
tone_analyzer.tone(tone_text.read(), tones="social", sentences=False)
4747

48-
4948
assert responses.calls[0].request.url.split('?')[0] == tone_url
5049
# Compare args. Order is not deterministic!
5150
actualArgs = {}
@@ -60,7 +59,7 @@ def test_tone_with_args():
6059
## Invoking tone() with some modifiers specified as positional parameters: tones are emotion and social, and sentences is false
6160
def test_tone():
6261
tone_url = 'https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone'
63-
tone_args = '?version=2016-05-19&tones=emotion%2Csocial&sentences=false'
62+
tone_args = { 'version': '2016-05-19', 'tones': 'emotion%2Csocial', 'sentences': 'false' }
6463
tone_response = None
6564
with open(os.path.join(os.path.dirname(__file__), '../resources/tone-v3-expect1.json')) as response_json:
6665
tone_response = response_json.read()
@@ -74,9 +73,13 @@ def test_tone():
7473
username="username", password="password")
7574
tone_analyzer.tone(tone_text.read(), 'emotion,social', False)
7675

77-
assert responses.calls[0].request.url == tone_url + tone_args
76+
assert responses.calls[0].request.url.split('?')[0] == tone_url
77+
# Compare args. Order is not deterministic!
78+
actualArgs = {}
79+
for arg in responses.calls[0].request.url.split('?')[1].split('&'):
80+
actualArgs[arg.split('=')[0]] = arg.split('=')[1]
81+
assert actualArgs == tone_args
7882
assert responses.calls[0].response.text == tone_response
79-
8083
assert len(responses.calls) == 1
8184

8285

0 commit comments

Comments
 (0)