How to use the cloudant.error.CloudantClientException function in cloudant

To help you get started, we’ve selected a few cloudant examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudant / python-cloudant / tests / unit / client_tests.py View on Github external
"""
        instance_name = 'Cloudant NoSQL DB-lv'
        vcap_services = {'cloudantNoSQLDB': [{
          'credentials': {
            'host': '{0}.cloudant.com'.format(self.account),
            'port': 443,
            'url': self.url
          },
          'name': instance_name,
        }]}

        try:
            with cloudant_bluemix(vcap_services, instance_name=instance_name) as c:
                self.assertIsInstance(c, Cloudant)
                self.assertIsInstance(c.r_session, requests.Session)
        except CloudantClientException as err:
            self.assertEqual(
                'Invalid service: IAM API key or username/password credentials are required.',
                str(err)
            )
github cloudant / python-cloudant / tests / unit / client_tests.py View on Github external
def test_raise_without_code(self):
        """
        Ensure that a default exception/code is used if none is provided.
        """
        with self.assertRaises(CloudantClientException) as cm:
            raise CloudantClientException()
        self.assertEqual(cm.exception.status_code, 100)
github cloudant / python-cloudant / tests / unit / client_tests.py View on Github external
def test_raise_with_proper_code_and_args(self):
        """
        Ensure that the requested exception is raised.
        """
        with self.assertRaises(CloudantClientException) as cm:
            raise CloudantClientException(404, 'foo')
        self.assertEqual(cm.exception.status_code, 404)
github cloudant / python-cloudant / tests / unit / client_tests.py View on Github external
def test_raise_using_invalid_code(self):
        """
        Ensure that a default exception/code is used if invalid code is provided.
        """
        with self.assertRaises(CloudantClientException) as cm:
            raise CloudantClientException('foo')
        self.assertEqual(cm.exception.status_code, 100)
github cloudant / python-cloudant / tests / unit / client_tests.py View on Github external
def test_create_existing_database(self):
        """
        Test creation of already existing database
        """
        dbname = self.dbname()
        self.client.connect()
        self.client.create_database(dbname)
        with self.assertRaises(CloudantClientException) as cm:
            self.client.create_database(dbname, throw_on_exists=True)
        self.assertEqual(cm.exception.status_code, 412)

        self.client.delete_database(dbname)
        self.client.disconnect()
github cloudant / python-cloudant / tests / unit / replicator_tests.py View on Github external
def test_constructor_failure(self):
        """
        Test that constructing a Replicator will not work
        without a valid client.
        """
        repl = None
        try:
            self.client.disconnect()
            repl = Replicator(self.client)
            self.fail('Above statement should raise a CloudantException')
        except CloudantClientException as err:
            self.assertEqual(
                str(err),
                'Database _replicator does not exist. '
                'Verify that the client is valid and try again.'
            )
        finally:
            self.assertIsNone(repl)
            self.client.connect()
github cloudant / python-cloudant / tests / unit / unit_t_db_base.py View on Github external
def create_db_updates(self):
        """
        Create '_global_changes' system database required for testing against _db_updates
        """
        self.DB_UPDATES = '_global_changes'
        try:
            self.client.create_database(self.DB_UPDATES, throw_on_exists=True)
        except CloudantClientException:
            self.delete_db_updates()
            self.create_db_updates()
github cloudant / python-cloudant / tests / unit / client_tests.py View on Github external
def test_raise_without_args(self):
        """
        Ensure that a default exception/code is used if the message requested
        by the code provided requires an argument list and none is provided.
        """
        with self.assertRaises(CloudantClientException) as cm:
            raise CloudantClientException(404)
        self.assertEqual(cm.exception.status_code, 100)