コード例 #1
0
 def test_update_a_search_index_with_analyzer(self):
     """
     Test that updating a search analyzer updates the contents of the correct
     search index object in the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.add_search_index('search001',
                           'not-a-valid-search-index',
                           'email')
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'not-a-valid-search-index', 'analyzer': 'email'}
     )
     ddoc.update_search_index(
         'search001',
         'function (doc) {\n  index("default", doc._id); '
         'if (doc._id) {index("name", doc.name, {"store": true}); }\n}',
         'simple'
     )
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, '
             '{"store": true}); }\n}',
          'analyzer': 'simple'
         }
     )
コード例 #2
0
 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"), {})
コード例 #3
0
 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'), {})
コード例 #4
0
 def test_delete_a_view(self):
     """
     Test deleting a view from the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, "_design/ddoc001")
     ddoc.add_view("view001", "function (doc) {\n  emit(doc._id, 1);\n}")
     self.assertEqual(ddoc.get("views")["view001"], {"map": "function (doc) {\n  emit(doc._id, 1);\n}"})
     ddoc.delete_view("view001")
     self.assertEqual(ddoc.get("views"), {})
コード例 #5
0
 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"), {})
コード例 #6
0
 def test_update_a_view(self):
     """
     Test that updating a view updates the contents of the correct
     View object in the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, "_design/ddoc001")
     ddoc.add_view("view001", "not-a-valid-map-function")
     self.assertEqual(ddoc.get("views")["view001"], {"map": "not-a-valid-map-function"})
     ddoc.update_view("view001", "function (doc) {\n  emit(doc._id, 1);\n}")
     self.assertEqual(ddoc.get("views")["view001"], {"map": "function (doc) {\n  emit(doc._id, 1);\n}"})
コード例 #7
0
 def test_create_design_document_with_docid_encoded_url(self):
     """
     Test creating a design document providing an id that has an encoded url
     """
     ddoc = DesignDocument(self.db, "_design/http://example.com")
     self.assertFalse(ddoc.exists())
     self.assertIsNone(ddoc.get("_rev"))
     ddoc.create()
     self.assertTrue(ddoc.exists())
     self.assertTrue(ddoc.get("_rev").startswith("1-"))
コード例 #8
0
 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}"})
コード例 #9
0
 def test_delete_a_view(self):
     """
     Test deleting a view from the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.add_view('view001', 'function (doc) {\n  emit(doc._id, 1);\n}')
     self.assertEqual(
         ddoc.get('views')['view001'],
         {'map': 'function (doc) {\n  emit(doc._id, 1);\n}'}
     )
     ddoc.delete_view('view001')
     self.assertEqual(ddoc.get('views'), {})
コード例 #10
0
 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.assertEqual(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}'}
     )
コード例 #11
0
 def test_add_a_search_index(self):
     """
     Test that adding a search index adds a search index object to
     the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     self.assertEqual(ddoc.get('indexes'), {})
     ddoc.add_search_index(
         'search001',
         'function (doc) {\n  index("default", doc._id); '
         'if (doc._id) {index("name", doc.name, {"store": true}); }\n}'
     )
     self.assertListEqual(list(ddoc.get('indexes').keys()), ['search001'])
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, {"store": true}); }\n}'}
      )
コード例 #12
0
 def test_delete_a_search_index(self):
     """
     Test deleting a search index from the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.add_search_index(
         'search001',
         'function (doc) {\n  index("default", doc._id); '
         'if (doc._id) {index("name", doc.name, '
         '{"store": true}); }\n}'
     )
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, '
             '{"store": true}); }\n}'}
     )
     ddoc.delete_index('search001')
     self.assertEqual(ddoc.get('indexes'), {})
コード例 #13
0
 def test_update_a_view(self):
     """
     Test that updating a view updates the contents of the correct
     View object in the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.add_view('view001', 'not-a-valid-map-function')
     self.assertEqual(
         ddoc.get('views')['view001'],
         {'map': 'not-a-valid-map-function'}
     )
     ddoc.update_view(
         'view001',
         'function (doc) {\n  emit(doc._id, 1);\n}'
     )
     self.assertEqual(
         ddoc.get('views')['view001'],
         {'map': 'function (doc) {\n  emit(doc._id, 1);\n}'}
     )
コード例 #14
0
 def test_setting_id(self):
     """
     Ensure when setting the design document id that it is
     prefaced by '_design/'
     """
     ddoc = DesignDocument(self.db)
     ddoc['_id'] = 'ddoc001'
     self.assertEqual(ddoc['_id'], '_design/ddoc001')
     del ddoc['_id']
     self.assertIsNone(ddoc.get('_id'))
     ddoc['_id'] = '_design/ddoc002'
     self.assertEqual(ddoc['_id'], '_design/ddoc002')
コード例 #15
0
 def test_setting_id(self):
     """
     Ensure when setting the design document id that it is
     prefaced by '_design/'
     """
     ddoc = DesignDocument(self.db)
     ddoc["_id"] = "ddoc001"
     self.assertEqual(ddoc["_id"], "_design/ddoc001")
     del ddoc["_id"]
     self.assertIsNone(ddoc.get("_id"))
     ddoc["_id"] = "_design/ddoc002"
     self.assertEqual(ddoc["_id"], "_design/ddoc002")
コード例 #16
0
 def test_add_a_search_index_with_analyzer(self):
     """
     Test that adding a search index with an analyzer adds a search index
     object to the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     self.assertEqual(ddoc.get('indexes'), {})
     ddoc.add_search_index(
         'search001',
         'function (doc) {\n  index("default", doc._id); '
         'if (doc._id) {index("name", doc.name, {"store": true}); }\n}',
         {'name': 'perfield', 'default': 'english', 'fields': {
             'spanish': 'spanish'}}
     )
     self.assertListEqual(list(ddoc.get('indexes').keys()), ['search001'])
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, {"store": true}); }\n}',
             'analyzer': {"name": "perfield", "default": "english", "fields":
                 {"spanish": "spanish"}}}
      )
コード例 #17
0
 def create_doc(self, doc_id=None, is_ddoc=False):
     """
     Function to create and return a Document or DesignDocument object.
     """
     if is_ddoc:
         if doc_id is not None:
             doc = DesignDocument(self.db, doc_id)
         else:
             doc = DesignDocument(self.db)
     elif doc_id is not None:
         doc = Document(self.db, doc_id)
     else:
         doc = Document(self.db)
     self.assertIsNone(doc.get('_rev'))
     return doc