Skip to content

Commit e1df393

Browse files
committed
chore(global): test global transaction id
1 parent d631acc commit e1df393

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

test/test_api_exception.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def test_api_exception():
2020
responses.add(responses.GET,
2121
'https://test-again.com',
2222
status=500,
23-
headers={'global_transaction_id': 'xx'},
2423
body=json.dumps({
2524
"errors": [
2625
{
@@ -53,8 +52,9 @@ def test_api_exception():
5352
responses.add(responses.GET,
5453
'https://test-for-text.com',
5554
status=500,
55+
headers={'X-Global-Transaction-ID': 'xx'},
5656
body="plain text error")
5757
mock_response = requests.get('https://test-for-text.com')
5858
exception = ApiException(500, http_response=mock_response)
5959
assert exception.message == 'plain text error'
60-
assert exception.__str__() == 'Error: plain text error, Code: 500'
60+
assert exception.__str__() == 'Error: plain text error, Code: 500 , X-global-transaction-id: xx'

test/test_base_service.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ def test_has_bad_first_or_last_char():
235235
AnyServiceV1('2018-11-20', username='{username}', password='password')
236236
assert str(err.value) == 'The username shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your username'
237237

238+
with pytest.raises(ValueError) as err:
239+
AnyServiceV1('2018-11-20', username='username', password='{password}')
240+
assert str(err.value) == 'The password shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your password'
241+
238242
with pytest.raises(ValueError) as err:
239243
AnyServiceV1('2018-11-20', iam_apikey='{apikey}')
240244
assert str(err.value) == 'The credentials shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your credentials'
@@ -243,6 +247,16 @@ def test_has_bad_first_or_last_char():
243247
AnyServiceV1('2018-11-20', iam_apikey='apikey', url='"url"')
244248
assert str(err.value) == 'The URL shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your URL'
245249

250+
with pytest.raises(ValueError) as err:
251+
service = AnyServiceV1('2018-11-20', iam_apikey='apikey', url='url')
252+
service.set_iam_apikey('"wrong"')
253+
assert str(err.value) == 'The credentials shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your credentials'
254+
255+
with pytest.raises(ValueError) as err:
256+
service = AnyServiceV1('2018-11-20', iam_apikey='apikey', url='url')
257+
service.set_url('"wrong"')
258+
assert str(err.value) == 'The URL shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your URL'
259+
246260
def test_set_credential_based_on_type():
247261
file_path = os.path.join(os.path.dirname(__file__), '../resources/ibm-credentials.env')
248262
os.environ['IBM_CREDENTIALS_FILE'] = file_path

test/test_detailed_response.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ def test_detailed_response():
2121

2222
dict_repr = detailed_response._to_dict()
2323
assert dict_repr['result'] == {'foobar': 'baz'}
24+
detailed_response.__str__()

0 commit comments

Comments
 (0)