def save(self, document):
     '''Save the given `document`.'''
     assert isinstance(document, Document)
     existing = list(self._documents.find({'name': document.name}))
     if len(existing) > 0:
         raise self._exists(document.name)
     self._documents.insert(Document.to_dict(document))
 def load(self, name):
     '''Load a single document with given `name`.'''
     assert isinstance(name, unicode)
     results = list(self._documents.find({'name': name}))
     if len(results) == 0:
         raise self._not_exists(name)
     return Document.from_dict(results[0])
Ejemplo n.º 3
0
 def test_to_dict(self):
     A = Document(self.name(), self.text(), self.metadata())
     self.assertEqual(Document.to_dict(A), self.dictionary())
Ejemplo n.º 4
0
 def test_from_dict(self):
     A = Document(self.name(), self.text(), self.metadata())
     B = Document.from_dict(self.dictionary())
     self.assertEqual(A, B)
 def _iterator(self, cursor):
     for entry in cursor:
         yield Document.from_dict(entry)