Exemple #1
0
    def test_bluemix_constructor_with_iam(self):
        """
        Test instantiating a client object using a VCAP_SERVICES environment
        variable.
        """
        instance_name = 'Cloudant NoSQL DB-lv'
        vcap_services = {
            'cloudantNoSQLDB': [{
                'credentials': {
                    'apikey': self.iam_api_key,
                    'username': self.user,
                    'host': '{0}.cloudant.com'.format(self.account),
                    'port': 443
                },
                '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)

        except Exception as err:
            self.fail('Exception {0} was raised.'.format(str(err)))

        finally:
            c.disconnect()
Exemple #2
0
    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': '******',
                    'password': '******',
                    'host': 'baz.com',
                    'port': 1234,
                    'url': 'https://*****:*****@baz.com: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()