Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit ebcb98c

Browse files
committed
Fix client tests to not always use account
1 parent c409805 commit ebcb98c

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

tests/unit/client_tests.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (C) 2015, 2020 IBM Corp. All rights reserved.
2+
# Copyright (C) 2015, 2021 IBM Corp. All rights reserved.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
2727
import sys
2828
import unittest
2929
from time import sleep
30+
from urllib.parse import urlparse
3031

3132
import mock
3233
import requests
@@ -213,7 +214,7 @@ def test_auto_renew_enabled_with_auto_connect(self):
213214
@skip_if_not_cookie_auth
214215
def test_session(self):
215216
"""
216-
Test getting session information.
217+
Test getting session information.
217218
Session info is None if CouchDB Admin Party mode was selected.
218219
"""
219220
try:
@@ -563,7 +564,7 @@ def test_get_cached_db_object_via_get(self):
563564
self.client.connect()
564565
# Default returns None
565566
self.assertIsNone(self.client.get('no_such_db'))
566-
# Creates the database remotely and adds it to the
567+
# Creates the database remotely and adds it to the
567568
# client database cache
568569
db = self.client.create_database(dbname)
569570
# Locally cached database object is returned
@@ -702,7 +703,7 @@ def test_cloudant_context_helper(self):
702703
Test that the cloudant context helper works as expected.
703704
"""
704705
try:
705-
with cloudant(self.user, self.pwd, account=self.account) as c:
706+
with cloudant(self.user, self.pwd, url=self.url) as c:
706707
self.assertIsInstance(c, Cloudant)
707708
self.assertIsInstance(c.r_session, requests.Session)
708709
except Exception as err:
@@ -718,7 +719,7 @@ def test_cloudant_bluemix_context_helper_with_legacy_creds(self):
718719
'credentials': {
719720
'username': self.user,
720721
'password': self.pwd,
721-
'host': '{0}.cloudant.com'.format(self.account),
722+
'host': urlparse(self.url).hostname,
722723
'port': 443,
723724
'url': self.url
724725
},
@@ -744,7 +745,7 @@ def test_cloudant_bluemix_context_helper_with_iam(self):
744745
'credentials': {
745746
'apikey': self.iam_api_key,
746747
'username': self.user,
747-
'host': '{0}.cloudant.com'.format(self.account),
748+
'host': urlparse(self.url).hostname,
748749
'port': 443,
749750
'url': self.url
750751
},
@@ -766,7 +767,7 @@ def test_cloudant_bluemix_context_helper_raise_error_for_missing_iam_and_creds(s
766767
instance_name = 'Cloudant NoSQL DB-lv'
767768
vcap_services = {'cloudantNoSQLDB': [{
768769
'credentials': {
769-
'host': '{0}.cloudant.com'.format(self.account),
770+
'host': urlparse(self.url).hostname,
770771
'port': 443,
771772
'url': self.url
772773
},
@@ -795,7 +796,7 @@ def test_cloudant_bluemix_dedicated_context_helper(self):
795796
'credentials': {
796797
'username': self.user,
797798
'password': self.pwd,
798-
'host': '{0}.cloudant.com'.format(self.account),
799+
'host': urlparse(self.url).hostname,
799800
'port': 443,
800801
'url': self.url
801802
},
@@ -818,10 +819,10 @@ def test_constructor_with_account(self):
818819
"""
819820
# Ensure that the client is new
820821
del self.client
821-
self.client = Cloudant(self.user, self.pwd, account=self.account)
822+
self.client = Cloudant('user', 'pass', account='foo')
822823
self.assertEqual(
823824
self.client.server_url,
824-
'https://{0}.cloudant.com'.format(self.account)
825+
'https://foo.cloudant.com'
825826
)
826827

827828
@skip_if_not_cookie_auth
@@ -835,7 +836,7 @@ def test_bluemix_constructor_with_legacy_creds(self):
835836
'credentials': {
836837
'username': self.user,
837838
'password': self.pwd,
838-
'host': '{0}.cloudant.com'.format(self.account),
839+
'host': urlparse(self.url).hostname,
839840
'port': 443,
840841
'url': self.url
841842
},
@@ -870,7 +871,7 @@ def test_bluemix_constructor_with_iam(self):
870871
'credentials': {
871872
'apikey': self.iam_api_key,
872873
'username': self.user,
873-
'host': '{0}.cloudant.com'.format(self.account),
874+
'host': urlparse(self.url).hostname,
874875
'port': 443
875876
},
876877
'name': instance_name
@@ -901,7 +902,7 @@ def test_bluemix_constructor_specify_instance_name(self):
901902
'credentials': {
902903
'username': self.user,
903904
'password': self.pwd,
904-
'host': '{0}.cloudant.com'.format(self.account),
905+
'host': urlparse(self.url).hostname,
905906
'port': 443,
906907
'url': self.url
907908
},
@@ -934,7 +935,7 @@ def test_bluemix_constructor_with_multiple_services(self):
934935
{
935936
'credentials': {
936937
'apikey': '1234api',
937-
'host': '{0}.cloudant.com'.format(self.account),
938+
'host': urlparse(self.url).hostname,
938939
'port': 443,
939940
'url': self.url
940941
},
@@ -973,10 +974,11 @@ def test_connect_headers(self):
973974
"""
974975
try:
975976
self.client.connect()
976-
self.assertEqual(
977-
self.client.r_session.headers['X-Cloudant-User'],
978-
self.account
979-
)
977+
if (self.account):
978+
self.assertEqual(
979+
self.client.r_session.headers['X-Cloudant-User'],
980+
self.account
981+
)
980982
agent = self.client.r_session.headers.get('User-Agent')
981983
ua_parts = agent.split('/')
982984
self.assertEqual(len(ua_parts), 6)
@@ -1413,4 +1415,4 @@ def test_update_cors_configuration(self):
14131415
self.client.disconnect()
14141416

14151417
if __name__ == '__main__':
1416-
unittest.main()
1418+
unittest.main()

0 commit comments

Comments
 (0)