How to use the cloudant.error.CloudantArgumentError 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 / view_tests.py View on Github external
def test_map_setter_failure(self):
        """
        Test that the map setter fails if a dict is not supplied
        """
        try:
            self.view.map = 'function (doc) {\n  emit(doc._id, 1);\n}'
            self.fail('Above statement should raise an Exception')
        except CloudantArgumentError as err:
            self.assertEqual(
                str(err),
                'The map property must be a dictionary.'
            )
github cloudant / python-cloudant / tests / unit / client_tests.py View on Github external
def test_set_year_with_invalid_month_for_volume_usage_data(self):
        """
        Test raising an exception when retrieving volume usage data with an
        invalid month parameter
        """
        try:
            self.client.connect()
            year = 2016
            month = 13
            with self.assertRaises(CloudantArgumentError) as cm:
                self.client.volume_usage(year, month)
            expected = ('Invalid year and/or month supplied.  '
                        'Found: year - 2016, month - 13')
            self.assertEqual(str(cm.exception), expected)
        finally:
            self.client.disconnect()
github cloudant / python-cloudant / tests / unit / query_tests.py View on Github external
def test_callable_without_selector(self):
        """
        Test Query __call__ without providing a selector
        """
        query = Query(self.db)
        try:
            query(fields=['_id', '_rev'])
            self.fail('Above statement should raise an Exception')
        except CloudantArgumentError as err:
            self.assertEqual(
                str(err),
                'No selector in the query or the selector was empty.  '
                'Add a selector to define the query and retry.'
github cloudant / python-cloudant / tests / unit / view_tests.py View on Github external
def test_reduce_setter_failure(self):
        """
        Test that the reduce setter fails if a string is not supplied
        """
        with self.assertRaises(CloudantArgumentError) as cm:
            self.view.reduce = {'_count'}
        err = cm.exception
        self.assertEqual(str(err), 'The reduce property must be a string.')
github cloudant / python-cloudant / tests / unit / db_updates_tests.py View on Github external
def test_invalid_feed_value(self):
        """
        Test that an invalid feed argument value is caught and an exception is
        raised
        """
        feed = Feed(self.client, feed='foo')
        with self.assertRaises(CloudantArgumentError) as cm:
            invalid_feed = [x for x in feed]
        self.assertTrue(str(cm.exception).startswith(
            'Invalid value (foo) for feed option.'))
github cloudant / python-cloudant / tests / unit / index_tests.py View on Github external
def test_deleting_index_without_index_name(self):
        """
        Tests that deleting an index without an index name provided fails as
        expected.
        """
        ddoc = DesignDocument(self.db, '_design/ddoc001')
        index = Index(self.db, 'ddoc001', fields=['name', 'age'])
        self.assertFalse(ddoc.exists())
        with self.assertRaises(CloudantArgumentError) as cm:
            index.delete()
        err = cm.exception
        self.assertEqual(
            str(err),
            'Deleting an index requires an index name be provided.'
        )
github cloudant / python-cloudant / tests / unit / changes_tests.py View on Github external
def test_invalid_argument_type(self):
        """
        Test that an invalid argument type is caught and an exception is raised
        """
        feed = Feed(self.db, conflicts=0)
        with self.assertRaises(CloudantArgumentError) as cm:
            invalid_feed = [x for x in feed]
        self.assertTrue(
            str(cm.exception).startswith('Argument conflicts not instance of expected type:')
        )
github cloudant / python-cloudant / tests / unit / index_tests.py View on Github external
def test_create_a_search_index_invalid_argument(self):
        """
        Test that a TEXT index is not created when an invalid argument is given.
        """
        index = TextIndex(self.db, 'ddoc001', 'index001', foo='bar')
        with self.assertRaises(CloudantArgumentError) as cm:
            index.create()
        err = cm.exception
        self.assertEqual(str(err), 'Invalid argument: foo')
github cloudant / python-cloudant / tests / unit / database_tests.py View on Github external
def test_share_database_invalid_role(self):
        """
        Test the sharing of a database fails when provided an invalid role.
        """
        share = 'user-{0}'.format(unicode_(uuid.uuid4()))
        with self.assertRaises(CloudantArgumentError) as cm:
            self.db.share_database(share, ['_writer', '_invalid_role'])
        err = cm.exception
        self.assertEqual(
            str(err),
            'Invalid role(s) provided: '
            '[\'_writer\', \'_invalid_role\'].  Valid roles are: '
github cloudant / python-cloudant / tests / unit / param_translation_tests.py View on Github external
def test_invalid_stale(self):
        """
        Test stale translation fails when the value is not either
        'ok' or 'update_after' is used.
        """
        msg = 'Argument stale not instance of expected type:'
        with self.assertRaises(CloudantArgumentError) as cm:
            python_to_couch({'stale': 10})
        self.assertTrue(str(cm.exception).startswith(msg))
        msg = 'Invalid value for stale option foo'
        with self.assertRaises(CloudantArgumentError) as cm:
            python_to_couch({'stale': 'foo'})
        self.assertTrue(str(cm.exception).startswith(msg))