Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_raise_error_for_missing_iam_api_key_and_credentials(self):
with self.assertRaises(CloudantException) as cm:
CloudFoundryService(
self._test_legacy_vcap_services_multiple,
instance_name='Cloudant NoSQL DB 7',
service_name='cloudantNoSQLDB'
)
self.assertEqual(
'Invalid service: IAM API key or username/password credentials are required.',
str(cm.exception)
)
def test_get_vcap_service_default_success_as_dict(self):
service = CloudFoundryService(
json.loads(self._test_vcap_services_single_legacy_credentials_enabled),
service_name='cloudantNoSQLDB'
)
self.assertEqual('Cloudant NoSQL DB 1', service.name)
def test_raise_error_for_missing_username(self):
with self.assertRaises(CloudantException) as cm:
CloudFoundryService(
self._test_legacy_vcap_services_multiple,
instance_name='Cloudant NoSQL DB 5',
service_name='cloudantNoSQLDB'
)
self.assertEqual(
"Invalid service: 'username' missing",
str(cm.exception)
)
def test_get_vcap_service_instance_username(self):
service = CloudFoundryService(
self._test_legacy_vcap_services_multiple,
instance_name='Cloudant NoSQL DB 1',
service_name='cloudantNoSQLDB'
)
self.assertEqual('example', service.username)
def test_get_vcap_service_instance_password(self):
service = CloudFoundryService(
self._test_legacy_vcap_services_multiple,
instance_name='Cloudant NoSQL DB 1',
service_name='cloudantNoSQLDB'
)
self.assertEqual('pa$$w0rd01', service.password)
def test_get_vcap_service_instance_host(self):
service = CloudFoundryService(
self._test_legacy_vcap_services_multiple,
instance_name='Cloudant NoSQL DB 1',
service_name='cloudantNoSQLDB'
)
self.assertEqual('example.cloudant.com', service.host)
def test_raise_error_for_invalid_vcap(self):
with self.assertRaises(CloudantException) as cm:
CloudFoundryService('{', 'Cloudant NoSQL DB 1') # invalid JSON
self.assertEqual('Failed to decode VCAP_SERVICES JSON', str(cm.exception))
def test_get_vcap_service_instance_iam_api_key(self):
service = CloudFoundryService(
self._test_legacy_vcap_services_multiple,
instance_name='Cloudant NoSQL DB 8',
service_name='cloudantNoSQLDB'
)
self.assertEqual('1234api', service.iam_api_key)
def test_raise_error_for_missing_service(self):
with self.assertRaises(CloudantException) as cm:
CloudFoundryService(
self._test_legacy_vcap_services_multiple,
instance_name='Cloudant NoSQL DB 9',
service_name='cloudantNoSQLDB'
)
self.assertEqual('Missing service in VCAP_SERVICES', str(cm.exception))
def test_raise_error_for_invalid_credentials_type(self):
with self.assertRaises(CloudantException) as cm:
CloudFoundryService(
self._test_legacy_vcap_services_multiple,
instance_name='Cloudant NoSQL DB 6',
service_name='cloudantNoSQLDB'
)
self.assertEqual(
'Failed to decode VCAP_SERVICES service credentials',
str(cm.exception)
)