This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from cloudant/313-bluemix-client-constructor
Implement Cloudant.bluemix client class method
- Loading branch information
Showing
3 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -539,6 +539,114 @@ def test_constructor_with_account(self): | |
'https://{0}.cloudant.com'.format(self.account) | ||
) | ||
|
||
def test_bluemix_constructor(self): | ||
""" | ||
Test instantiating a client object using a VCAP_SERVICES environment | ||
variable. | ||
""" | ||
instance_name = 'Cloudant NoSQL DB-lv' | ||
vcap_services = {'cloudantNoSQLDB': [{ | ||
'credentials': { | ||
'username': self.user, | ||
'password': self.pwd, | ||
'host': '{0}.cloudant.com'.format(self.account), | ||
'port': 443, | ||
'url': self.url | ||
}, | ||
'name': instance_name | ||
}]} | ||
|
||
# create Cloudant Bluemix client | ||
c = Cloudant.bluemix(vcap_services) | ||
|
||
try: | ||
c.connect() | ||
self.assertIsInstance(c, Cloudant) | ||
self.assertIsInstance(c.r_session, requests.Session) | ||
self.assertEquals(c.session()['userCtx']['name'], self.user) | ||
|
||
except Exception as err: | ||
self.fail('Exception {0} was raised.'.format(str(err))) | ||
|
||
finally: | ||
c.disconnect() | ||
|
||
def test_bluemix_constructor_specify_instance_name(self): | ||
""" | ||
Test instantiating a client object using a VCAP_SERVICES environment | ||
variable and specifying which instance name to use. | ||
""" | ||
instance_name = 'Cloudant NoSQL DB-lv' | ||
vcap_services = {'cloudantNoSQLDB': [{ | ||
'credentials': { | ||
'username': self.user, | ||
'password': self.pwd, | ||
'host': '{0}.cloudant.com'.format(self.account), | ||
'port': 443, | ||
'url': self.url | ||
}, | ||
'name': instance_name | ||
}]} | ||
|
||
# create Cloudant Bluemix client | ||
c = Cloudant.bluemix(vcap_services, instance_name=instance_name) | ||
|
||
try: | ||
c.connect() | ||
self.assertIsInstance(c, Cloudant) | ||
self.assertIsInstance(c.r_session, requests.Session) | ||
self.assertEquals(c.session()['userCtx']['name'], self.user) | ||
|
||
except Exception as err: | ||
self.fail('Exception {0} was raised.'.format(str(err))) | ||
|
||
finally: | ||
c.disconnect() | ||
|
||
def test_bluemix_constructor_with_multiple_services(self): | ||
""" | ||
Test instantiating a client object using a VCAP_SERVICES environment | ||
variable that contains multiple services. | ||
""" | ||
instance_name = 'Cloudant NoSQL DB-lv' | ||
vcap_services = {'cloudantNoSQLDB': [ | ||
{ | ||
'credentials': { | ||
'username': self.user, | ||
'password': self.pwd, | ||
'host': '{0}.cloudant.com'.format(self.account), | ||
'port': 443, | ||
'url': self.url | ||
}, | ||
'name': instance_name | ||
}, | ||
{ | ||
'credentials': { | ||
'username': 'foo', | ||
'password': 'bar', | ||
'host': 'baz.com', | ||
'port': 1234, | ||
'url': 'https://foo:[email protected]:1234' | ||
}, | ||
'name': 'Cloudant NoSQL DB-yu' | ||
} | ||
]} | ||
|
||
# create Cloudant Bluemix client | ||
c = Cloudant.bluemix(vcap_services, instance_name=instance_name) | ||
|
||
try: | ||
c.connect() | ||
self.assertIsInstance(c, Cloudant) | ||
self.assertIsInstance(c.r_session, requests.Session) | ||
self.assertEquals(c.session()['userCtx']['name'], self.user) | ||
|
||
except Exception as err: | ||
self.fail('Exception {0} was raised.'.format(str(err))) | ||
|
||
finally: | ||
c.disconnect() | ||
|
||
def test_connect_headers(self): | ||
""" | ||
Test that the appropriate request headers are set | ||
|