How to use the cloudant.view.View 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(self):
        """
        Test that the map setter works
        """
        ddoc = DesignDocument(self.db, 'ddoc001')
        view = View(ddoc, 'view001')
        self.assertIsNone(view.get('map'))
        view.map = 'function (doc) {\n  emit(doc._id, 1);\n}'
        self.assertEqual(
            view.get('map'),
            'function (doc) {\n  emit(doc._id, 1);\n}'
        )
github cloudant / python-cloudant / tests / unit / view_tests.py View on Github external
def test_constructor(self):
        """
        Test instantiating a View
        """
        ddoc = DesignDocument(self.db, 'ddoc001')
        view = View(
            ddoc,
            'view001',
            'function (doc) {\n  emit(doc._id, 1);\n}',
            '_count',
            dbcopy='{0}-copy'.format(self.db.database_name)
        )
        self.assertEqual(view.design_doc, ddoc)
        self.assertEqual(view.view_name, 'view001')
        self.assertIsInstance(view['map'], _Code)
        self.assertEqual(
            view['map'],
            'function (doc) {\n  emit(doc._id, 1);\n}'
        )
        self.assertIsInstance(view['reduce'], _Code)
        self.assertEqual(view['reduce'], '_count')
        self.assertEqual(
github cloudant / python-cloudant / tests / unit / view_tests.py View on Github external
def test_view_callable_with_non_existing_view(self):
        """
        Test error condition when view used does not exist remotely.
        """
        self.populate_db_with_documents()
        # The view "missing-view" does not exist in the remote database
        view = View(
            DesignDocument(self.db, 'ddoc001'),
            'missing-view',
            'function (doc) {\n  emit(doc._id, 1);\n}'
        )
        self.assertIsInstance(view, View)
        try:
            for row in view.result:
                self.fail('Above statement should raise an Exception')
        except requests.HTTPError as err:
            self.assertEqual(err.response.status_code, 404)
github cloudant / python-cloudant / tests / unit / design_document_tests.py View on Github external
def test_add_a_view(self):
        """
        Test that adding a view adds a View object to
        the DesignDocument dictionary.
        """
        ddoc = DesignDocument(self.db, '_design/ddoc001')
        self.assertEqual(ddoc.get('views'), {})
        ddoc.add_view(
            'view001',
            'function (doc) {\n  emit(doc._id, 1);\n}'
        )
        self.assertListEqual(list(ddoc.get('views').keys()), ['view001'])
        self.assertIsInstance(ddoc.get('views')['view001'], View)
        self.assertEqual(
            ddoc.get('views')['view001'],
            {'map': 'function (doc) {\n  emit(doc._id, 1);\n}'}
        )
github cloudant / python-cloudant / tests / unit / view_tests.py View on Github external
def test_reduce_getter(self):
        """
        Test that the reduce getter works
        """
        ddoc = DesignDocument(self.db, 'ddoc001')
        view = View(ddoc, 'view001')
        self.assertIsNone(view.reduce)
        view.reduce = '_count'
        self.assertIsInstance(view.reduce, _Code)
        self.assertEqual(view.reduce, '_count')
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
def call(self, *args, **kwargs):
                self.outer.assertEqual(dict(kwargs),
                                       self.expected_calls.pop(),
                                       'pagination error')
                return View.__call__(self.outer.view007, *args, **kwargs)
github cloudant / python-cloudant / tests / unit / design_document_tests.py View on Github external
self.assertEqual(ddoc_remote, ddoc)
        self.assertTrue(ddoc_remote['_rev'].startswith('1-'))
        self.assertEqual(ddoc_remote, {
            '_id': '_design/ddoc001',
            '_rev': ddoc['_rev'],
            'options': {'partitioned': False},
            'lists': {},
            'shows': {},
            'indexes': {},
            'views': {
                'view001': {'map': view_map, 'reduce': view_reduce},
                'view003': {'map': view_map}
            }
        })
        self.assertIsInstance(ddoc_remote['views']['view001'], View)
        self.assertIsInstance(ddoc_remote['views']['view003'], View)
github cloudant / python-cloudant / tests / unit / view_tests.py View on Github external
def test_retrieve_view_url(self):
        """
        Test the retrieval of the View url
        """
        ddoc = DesignDocument(self.db, 'ddoc001')
        view = View(ddoc, 'view001')
        self.assertEqual(
            view.url,
            '/'.join((ddoc.document_url, '_view/view001'))
        )