From a0e37dd9a3b8ec0f58b60e8f73c6d75648be8d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fre=CC=81de=CC=81ric=20LASNIER?= Date: Tue, 22 Nov 2011 18:45:01 +0100 Subject: [PATCH 1/4] Add fix, TODO : add test --- mongokit/grid.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mongokit/grid.py b/mongokit/grid.py index 4d54f84..6ceaefe 100644 --- a/mongokit/grid.py +++ b/mongokit/grid.py @@ -156,6 +156,33 @@ def get_version(self, filename, version=-1, **kwargs): except StopIteration: raise NoFile("no version %d for filename %r" % (version, filename)) + def versions(self, filename, **kwargs): + """Return number of version for specified filename + This is a rapid hack, which as not been add to tests + TODO : Ajouter le test de version + + class Doc(Document): + structure = { + 'title':unicode, + } + gridfs = {'files': ['source']} + con = Connection() + col = con['test']['mongokit'] + con.register([Doc]) + doc = col.Doc() + doc['title'] = u'Hello' + doc.fs.source = "Hello World !" + doc.fs.versions() --> 1 attendu + doc.fs.source = "Hello World 2 !" + doc.fs.versions() --> 2 attendu + """ + # This is took from pymongo source. We need to go a little deeper here + self._GridFS__files.ensure_index([("filename", ASCENDING), + ("uploadDate", DESCENDING)]) + ########## Begin of MongoKit hack ########## + return self._GridFS__files.find(self._get_spec(filename=filename, **kwargs)).count() + ########## end of MongoKit hack ############ + class FSContainer(FS): def __init__(self, container_name, obj): self._container_name = container_name From 14cdd8c0dfc6f731378e1fc3a95c99fb5f880d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fre=CC=81de=CC=81ric=20LASNIER?= Date: Mon, 28 Nov 2011 12:46:47 +0100 Subject: [PATCH 2/4] add test --- tests/test_gridfs.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/test_gridfs.py b/tests/test_gridfs.py index 645a26a..767bdc3 100644 --- a/tests/test_gridfs.py +++ b/tests/test_gridfs.py @@ -261,4 +261,40 @@ class Doc(Document): new_id = doc.fs.get_last_version("source")._id doc.fs.delete(new_id) assert doc.fs.source == 'Hello World', doc.fs.source - + + def test_gridfs_versions(self): + + class Doc(Document): + structure = { + 'title':unicode, + } + gridfs = {'files': ['source']} + self.connection.register([Doc]) + doc = self.col.Doc() + doc['title'] = u'Hello' + doc.save() + + # Version 1 + doc.fs.source = "Hello World !" + assert doc.fs.source == "Hello World !" + self.assertEqual(doc.fs.versions("source"), 1) + + # Version 2 + doc.fs.source = "Salut !" + assert doc.fs.source == "Salut !" + + self.assertEqual(doc.fs.versions("source"), 2) + + # assert doc.fs.source == "Hello World !" + + # f = doc.fs.attachments.new_file('test') + # f.write('this is a test') + # f.close() + # assert doc.fs.attachments['test'] == 'this is a test' + + # doc = self.col.Doc.find_one() + # assert doc.fs.bla == "Salut !" + # assert doc.fs.foo == "Hello World !" + # assert doc.fs.attachments['test'] == 'this is a test', doc.fs.attachments['test'] + # assert doc.fs.attachments.get_last_version('test').read() == 'this is a test' + From 2f394c01b3b88b68e2a74f0927f1b49226b77810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fre=CC=81de=CC=81ric=20LASNIER?= Date: Mon, 28 Nov 2011 12:49:42 +0100 Subject: [PATCH 3/4] add tests --- tests/test_gridfs.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/test_gridfs.py b/tests/test_gridfs.py index 767bdc3..7afe19b 100644 --- a/tests/test_gridfs.py +++ b/tests/test_gridfs.py @@ -285,16 +285,3 @@ class Doc(Document): self.assertEqual(doc.fs.versions("source"), 2) - # assert doc.fs.source == "Hello World !" - - # f = doc.fs.attachments.new_file('test') - # f.write('this is a test') - # f.close() - # assert doc.fs.attachments['test'] == 'this is a test' - - # doc = self.col.Doc.find_one() - # assert doc.fs.bla == "Salut !" - # assert doc.fs.foo == "Hello World !" - # assert doc.fs.attachments['test'] == 'this is a test', doc.fs.attachments['test'] - # assert doc.fs.attachments.get_last_version('test').read() == 'this is a test' - From 16dc18ab21a74e48f01069ccc73dae38026ee783 Mon Sep 17 00:00:00 2001 From: Frederic LASNIER Date: Wed, 29 Feb 2012 10:32:57 +0100 Subject: [PATCH 4/4] simple commit --- MANIFEST.in | 0 debian/rules | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 MANIFEST.in mode change 100755 => 100644 debian/rules diff --git a/MANIFEST.in b/MANIFEST.in old mode 100755 new mode 100644 diff --git a/debian/rules b/debian/rules old mode 100755 new mode 100644