def test_get_by_parent_and_type(self): fsConnector = FileSystemConnector(self.db_path) doc = {"_id": "123", "type": "father", "parent": None} fsConnector.saveDocument(doc) doc = {"_id": "456", "type": "child", "parent": "123"} fsConnector.saveDocument(doc) doc = {"_id": "789", "type": "child", "parent": "123"} fsConnector.saveDocument(doc) ids = fsConnector.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 = fsConnector.getDocsByFilter(parentId="123", type="son") self.assertEquals(len(ids), 0, "There shouldn't be any 'son' with parent '123'") ids = fsConnector.getDocsByFilter(parentId="456", type="child") self.assertEquals(len(ids), 0, "There shouldn't be any 'child' with parent '456'")
def test_get_Document(self): fsConnector = FileSystemConnector(self.db_path) doc = {"_id": "123", "data": "some data"} fsConnector.saveDocument(doc) doc_retrieved = fsConnector.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")
def test_save_Document(self): fsConnector = FileSystemConnector(self.db_path) doc = {"_id": "123", "data": "some data"} fsConnector.saveDocument(doc) doc_from_db = open(os.path.join(self.db_path, "%s.json" % "123"), "r") doc_from_db = json.loads(doc_from_db.read()) 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")
def test_get_Document(self): fsConnector = FileSystemConnector(self.db_path) doc = {'_id': '123', 'data': 'some data'} fsConnector.saveDocument(doc) doc_retrieved = fsConnector.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")
def test_save_Document(self): fsConnector = FileSystemConnector(self.db_path) doc = {'_id': '123', 'data': 'some data'} fsConnector.saveDocument(doc) doc_from_db = open(os.path.join(self.db_path, '%s.json' % '123'), 'r') doc_from_db = json.loads(doc_from_db.read()) 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")
def test_remove_Document(self): fsConnector = FileSystemConnector(self.db_path) doc = {"_id": "123", "data": "some data"} fsConnector.saveDocument(doc) fsConnector.remove("123") try: doc_from_db = open(os.path.join(self.db_path, "%s.json" % "123"), "r") doc_from_db = json.loads(doc_from_db.read()) except IOError: doc_from_db = None self.assertEquals(doc_from_db, None, "Document should be None")
def test_remove_Document(self): fsConnector = FileSystemConnector(self.db_path) doc = {'_id': '123', 'data': 'some data'} fsConnector.saveDocument(doc) fsConnector.remove('123') try: doc_from_db = open(os.path.join(self.db_path, '%s.json' % '123'), 'r') doc_from_db = json.loads(doc_from_db.read()) except IOError: doc_from_db = None self.assertEquals(doc_from_db, None, "Document should be None")
def test_get_by_parent_and_type(self): fsConnector = FileSystemConnector(self.db_path) doc = { '_id': '123', 'type': 'father', 'parent': None, } fsConnector.saveDocument(doc) doc = { '_id': '456', 'type': 'child', 'parent': '123', } fsConnector.saveDocument(doc) doc = { '_id': '789', 'type': 'child', 'parent': '123', } fsConnector.saveDocument(doc) ids = fsConnector.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 = fsConnector.getDocsByFilter(parentId='123', type='son') self.assertEquals(len(ids), 0, "There shouldn't be any 'son' with parent '123'") ids = fsConnector.getDocsByFilter(parentId='456', type='child') self.assertEquals(len(ids), 0, "There shouldn't be any 'child' with parent '456'")