Пример #1
0
    def test_get_by_parent_and_type(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {"_id": "123", "type": "father", "parent": None}
        couchConnector.saveDocument(doc)

        doc = {"_id": "456", "type": "child", "parent": "123"}
        couchConnector.saveDocument(doc)

        doc = {"_id": "789", "type": "child", "parent": "123"}
        couchConnector.saveDocument(doc)

        ids = couchConnector.getDocsByFilter(parentId="123", type="child")

        self.assertEquals(len(ids), 2, "There should be two 'childs' with parent '123'")

        self.assertIn("456", ids, "Child '456' should be in the list of childs")

        self.assertIn("789", ids, "Child '789' should be in the list of childs")

        ids = couchConnector.getDocsByFilter(parentId="123", type="son")

        self.assertEquals(len(ids), 0, "There shouldn't be any 'son' with parent '123'")

        ids = couchConnector.getDocsByFilter(parentId="456", type="child")

        self.assertEquals(len(ids), 0, "There shouldn't be any 'child' with parent '456'")
Пример #2
0
    def test_get_Document(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {"_id": "123", "data": "some data"}
        couchConnector.saveDocument(doc)

        doc_retrieved = couchConnector.getDocument("123")

        self.assertNotEquals(doc_retrieved, None, "Document should be retrieved")

        self.assertEquals(doc_retrieved.get("data"), "some data", "Data retrieved should be the same as data saved")
Пример #3
0
    def test_save_Document(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {'_id': '123', 'data': 'some data'}
        couchConnector.saveDocument(doc)

        doc_from_db = self.db.get('123')

        self.assertNotEquals(doc_from_db, None, "Document should be retrieved")

        self.assertEquals(doc_from_db.get('data'), 'some data',
                          "Data retrieved should be the same as data saved")
Пример #4
0
    def test_remove_Document(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {"_id": "123", "data": "some data"}
        couchConnector.saveDocument(doc)

        couchConnector.remove("123")

        try:
            doc_from_db = self.db.get("123")
        except ResourceNotFound:
            doc_from_db = None

        self.assertEquals(doc_from_db, None, "Document should be None")
Пример #5
0
    def test_remove_Document(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {'_id': '123', 'data': 'some data'}
        couchConnector.saveDocument(doc)

        couchConnector.remove('123')

        try:
            doc_from_db = self.db.get('123')
        except ResourceNotFound:
            doc_from_db = None

        self.assertEquals(doc_from_db, None, "Document should be None")
Пример #6
0
    def test_get_by_parent_and_type(self):
        couchConnector = CouchDbConnector(self.db)
        doc = {
            '_id': '123',
            'type': 'father',
            'parent': None,
        }
        couchConnector.saveDocument(doc)

        doc = {
            '_id': '456',
            'type': 'child',
            'parent': '123',
        }
        couchConnector.saveDocument(doc)

        doc = {
            '_id': '789',
            'type': 'child',
            'parent': '123',
        }
        couchConnector.saveDocument(doc)

        ids = couchConnector.getDocsByFilter(parentId='123', type='child')

        self.assertEquals(len(ids), 2,
                          "There should be two 'childs' with parent '123'")

        self.assertIn('456', ids,
                      "Child '456' should be in the list of childs")

        self.assertIn('789', ids,
                      "Child '789' should be in the list of childs")

        ids = couchConnector.getDocsByFilter(parentId='123', type='son')

        self.assertEquals(len(ids), 0,
                          "There shouldn't be any 'son' with parent '123'")

        ids = couchConnector.getDocsByFilter(parentId='456', type='child')

        self.assertEquals(len(ids), 0,
                          "There shouldn't be any 'child' with parent '456'")