当前位置: 首页>>代码示例>>Python>>正文


Python design_document.DesignDocument类代码示例

本文整理汇总了Python中cloudant.design_document.DesignDocument的典型用法代码示例。如果您正苦于以下问题:Python DesignDocument类的具体用法?Python DesignDocument怎么用?Python DesignDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DesignDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fetch_query_views

 def test_fetch_query_views(self):
     """
     Ensure that the document fetch from the database returns the
     DesignDocument format as expected when retrieving a design document
     containing query index views.
     """
     # This is not the preferred way of dealing with query index
     # views but it works best for this test.
     data = {
         "_id": "_design/ddoc001",
         "language": "query",
         "views": {
             "view001": {
                 "map": {"fields": {"name": "asc", "age": "asc"}},
                 "reduce": "_count",
                 "options": {"def": {"fields": ["name", "age"]}, "w": 2},
             }
         },
     }
     doc = self.db.create_document(data)
     self.assertIsInstance(doc, Document)
     data["_rev"] = doc["_rev"]
     ddoc = DesignDocument(self.db, "_design/ddoc001")
     ddoc.fetch()
     self.assertIsInstance(ddoc, DesignDocument)
     self.assertEqual(ddoc, data)
     self.assertIsInstance(ddoc["views"]["view001"], QueryIndexView)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:27,代码来源:design_document_tests.py

示例2: test_rewrite_rule

 def test_rewrite_rule(self):
     """
     Test that design document URL is rewritten to the expected test document.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc['rewrites'] = [
         {"from": "",
          "to": "/../../rewrite_doc",
          "method": "GET",
          "query": {}
          }
     ]
     self.assertIsInstance(ddoc.rewrites, list)
     self.assertIsInstance(ddoc.rewrites[0], dict)
     ddoc.save()
     doc = Document(self.db, 'rewrite_doc')
     doc.save()
     resp = self.client.r_session.get('/'.join([ddoc.document_url, '_rewrite']))
     self.assertEquals(
         resp.json(),
         {
             '_id': 'rewrite_doc',
             '_rev': doc['_rev']
         }
     )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:25,代码来源:design_document_tests.py

示例3: test_fetch_text_indexes

 def test_fetch_text_indexes(self):
     """
     Ensure that the document fetch from the database returns the
     DesignDocument format as expected when retrieving a design document
     containing query index views.
     """
     # This is not the preferred way of dealing with query index
     # views but it works best for this test.
     data = {
         '_id': '_design/ddoc001',
         'language': 'query',
         'indexes': {'index001': 
                  {'index': {'index_array_lengths': True,
                             'fields': [{'name': 'name', 'type': 'string'},
                                        {'name': 'age', 'type': 'number'}],
                             'default_field': {'enabled': True,
                                               'analyzer': 'german'},
                             'default_analyzer': 'keyword',
                             'selector': {}},
                   'analyzer': {'name': 'perfield',
                                'default': 'keyword',
                                'fields': {'$default': 'german'}}}}}
     doc = self.db.create_document(data)
     self.assertIsInstance(doc, Document)
     data['_rev'] = doc['_rev']
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.fetch()
     self.assertIsInstance(ddoc, DesignDocument)
     self.assertEqual(ddoc, data)
     self.assertIsInstance(ddoc['indexes']['index001'], dict)
开发者ID:JanekLehr,项目名称:python-cloudant,代码行数:30,代码来源:design_document_tests.py

示例4: test_delete_a_query_index_view

 def test_delete_a_query_index_view(self):
     """
     Test deleting a query index view fails as expected.
     """
     # This is not the preferred way of dealing with query index
     # views but it works best for this test.
     data = {
         '_id': '_design/ddoc001',
         'language': 'query',
         'views': {
             'view001': {'map': {'fields': {'name': 'asc', 'age': 'asc'}},
                         'reduce': '_count',
                         'options': {'def': {'fields': ['name', 'age']},
                                     'w': 2}
                         }
                 }
     }
     self.db.create_document(data)
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.fetch()
     with self.assertRaises(CloudantException) as cm:
         ddoc.delete_view('view001')
     err = cm.exception
     self.assertEqual(
         str(err),
         'Cannot delete a query index view using this method.'
     )
开发者ID:JanekLehr,项目名称:python-cloudant,代码行数:27,代码来源:design_document_tests.py

示例5: test_fetch_query_views

 def test_fetch_query_views(self):
     """
     Ensure that the document fetch from the database returns the
     DesignDocument format as expected when retrieving a design document
     containing query index views.
     """
     # This is not the preferred way of dealing with query index
     # views but it works best for this test.
     data = {
         '_id': '_design/ddoc001',
         'language': 'query',
         'views': {
             'view001': {'map': {'fields': {'name': 'asc', 'age': 'asc'}},
                         'reduce': '_count',
                         'options': {'def': {'fields': ['name', 'age']},
                                     'w': 2}
                         }
                 }
     }
     doc = self.db.create_document(data)
     self.assertIsInstance(doc, Document)
     data['_rev'] = doc['_rev']
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.fetch()
     self.assertIsInstance(ddoc, DesignDocument)
     self.assertEqual(ddoc, data)
     self.assertIsInstance(ddoc['views']['view001'], QueryIndexView)
开发者ID:JanekLehr,项目名称:python-cloudant,代码行数:27,代码来源:design_document_tests.py

示例6: test_new_ddoc_add_view

 def test_new_ddoc_add_view(self):
     mock_database = mock.Mock()
     ddoc = DesignDocument(mock_database, '_design/unittest')
     ddoc.add_view('view1', "MAP")
     self.assertIn('view1', ddoc['views'])
     self.assertEqual(ddoc['views']['view1'].map, 'MAP')
     self.assertEqual(ddoc['views']['view1'].reduce, None)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:7,代码来源:design_doc_test.py

示例7: test_text_index_save_fails_with_existing_search_index

 def test_text_index_save_fails_with_existing_search_index(self):
     """
     Tests that save fails when language is not query and both a query text
     index and a search index exist in the design document.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     search_index = ('function (doc) {\n  index("default", doc._id); '
                     'if (doc._id) {index("name", doc.name, '
                     '{"store": true}); }\n}')
     ddoc.add_search_index('search001', search_index)
     self.assertIsInstance(
         ddoc['indexes']['search001']['index'], str
     )
     ddoc.save()
     self.assertTrue(ddoc['_rev'].startswith('1-'))
     ddoc_remote = DesignDocument(self.db, '_design/ddoc001')
     ddoc_remote.fetch()
     ddoc_remote['indexes']['index001'] = {
         'index': {'index_array_lengths': True,
                   'fields': [{'name': 'name', 'type': 'string'},
                              {'name': 'age', 'type': 'number'}],
                   'default_field': {'enabled': True, 'analyzer': 'german'},
                   'default_analyzer': 'keyword',
                   'selector': {}},
         'analyzer': {'name': 'perfield','default': 'keyword',
                      'fields': {'$default': 'german'}}}
     self.assertIsInstance(ddoc_remote['indexes']['index001']['index'], dict)
     with self.assertRaises(CloudantException) as cm:
         ddoc_remote.save()
     err = cm.exception
     self.assertEqual(
         str(err),
         'Function for search index index001 must be of type string.'
     )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:34,代码来源:design_document_tests.py

示例8: test_fetch_text_indexes

 def test_fetch_text_indexes(self):
     """
     Ensure that the document fetch from the database returns the
     DesignDocument format as expected when retrieving a design document
     containing query index views.
     """
     # This is not the preferred way of dealing with query index
     # views but it works best for this test.
     data = {
         "_id": "_design/ddoc001",
         "language": "query",
         "indexes": {
             "index001": {
                 "index": {
                     "index_array_lengths": True,
                     "fields": [{"name": "name", "type": "string"}, {"name": "age", "type": "number"}],
                     "default_field": {"enabled": True, "analyzer": "german"},
                     "default_analyzer": "keyword",
                     "selector": {},
                 },
                 "analyzer": {"name": "perfield", "default": "keyword", "fields": {"$default": "german"}},
             }
         },
     }
     doc = self.db.create_document(data)
     self.assertIsInstance(doc, Document)
     ddoc = DesignDocument(self.db, "_design/ddoc001")
     ddoc.fetch()
     self.assertIsInstance(ddoc, DesignDocument)
     data["_rev"] = doc["_rev"]
     data["views"] = dict()
     self.assertEqual(ddoc, data)
     self.assertIsInstance(ddoc["indexes"]["index001"], dict)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:33,代码来源:design_document_tests.py

示例9: test_list_views

 def test_list_views(self):
     mock_database = mock.Mock()
     ddoc = DesignDocument(mock_database, '_design/unittest')
     ddoc['views'] = {
         'view1': {'map': "MAP", 'reduce': 'REDUCE'},
         'view2': {'map': "MAP", 'reduce': 'REDUCE'},
     }
     self.assertListEqual(sorted(ddoc.list_views()), ['view1', 'view2'])
开发者ID:rredburn,项目名称:python-cloudant,代码行数:8,代码来源:design_doc_test.py

示例10: test_constructor_without_docid

 def test_constructor_without_docid(self):
     """
     Test instantiating a DesignDocument without providing an id
     """
     ddoc = DesignDocument(self.db)
     self.assertIsInstance(ddoc, DesignDocument)
     self.assertIsNone(ddoc.get("_id"))
     self.assertEqual(ddoc.get("views"), {})
开发者ID:rredburn,项目名称:python-cloudant,代码行数:8,代码来源:design_document_tests.py

示例11: test_constructor_with_docid

 def test_constructor_with_docid(self):
     """
     Test instantiating a DesignDocument providing an id
     not prefaced with '_design/'
     """
     ddoc = DesignDocument(self.db, 'ddoc001')
     self.assertIsInstance(ddoc, DesignDocument)
     self.assertEqual(ddoc.get('_id'), '_design/ddoc001')
     self.assertEqual(ddoc.get('views'), {})
开发者ID:JanekLehr,项目名称:python-cloudant,代码行数:9,代码来源:design_document_tests.py

示例12: test_constructor_with_design_docid

 def test_constructor_with_design_docid(self):
     """
     Test instantiating a DesignDocument providing an id
     prefaced with '_design/'
     """
     ddoc = DesignDocument(self.db, "_design/ddoc001")
     self.assertIsInstance(ddoc, DesignDocument)
     self.assertEqual(ddoc.get("_id"), "_design/ddoc001")
     self.assertEqual(ddoc.get("views"), {})
开发者ID:rredburn,项目名称:python-cloudant,代码行数:9,代码来源:design_document_tests.py

示例13: test_ddoc_update_view

 def test_ddoc_update_view(self):
     mock_database = mock.Mock()
     ddoc = DesignDocument(mock_database, '_design/unittest')
     ddoc.add_view('view1', "MAP", "REDUCE")
     
     ddoc.update_view('view1', "UPDATED_MAP", "REDUCE")
     self.assertTrue('view1' in ddoc['views'])
     self.assertEqual(ddoc['views']['view1'].map, 'UPDATED_MAP')
     self.assertEqual(ddoc['views']['view1'].reduce, 'REDUCE')
开发者ID:rredburn,项目名称:python-cloudant,代码行数:9,代码来源:design_doc_test.py

示例14: test_view_context

    def test_view_context(self):
        db = mock.Mock()
        db.database_name = 'unittest'
        ddoc = DesignDocument(db, "_design/tests")
        ddoc._database_host = "https://bob.cloudant.com"
        view1 = View(ddoc, "view1", map_func=self.map_func)

        with view1.custom_result() as v:
            self.assertTrue(isinstance(v, Result))
开发者ID:iblis17,项目名称:python-cloudant,代码行数:9,代码来源:views_test.py

示例15: test_adding_query_index_view

 def test_adding_query_index_view(self):
     """
     Test that adding a query index view fails as expected.
     """
     ddoc = DesignDocument(self.db, "_design/ddoc001")
     ddoc["language"] = "query"
     with self.assertRaises(CloudantException) as cm:
         ddoc.add_view("view001", {"foo": "bar"})
     err = cm.exception
     self.assertEqual(str(err), "Cannot add a MapReduce view to a " "design document for query indexes.")
开发者ID:rredburn,项目名称:python-cloudant,代码行数:10,代码来源:design_document_tests.py


注:本文中的cloudant.design_document.DesignDocument类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。