Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add versions() method #67

Open
wants to merge 4 commits into from

3 participants

@fredlala

method versions(self, filename, **kwargs) added to FS Class.

Tests included

@gulbinas
Collaborator

@fredlala - can you rebase your PR, so we can merge it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 22, 2011
  1. @fredl

    Add fix, TODO : add test

    fredl authored
Commits on Nov 28, 2011
  1. @fredl

    add test

    fredl authored
  2. @fredl

    add tests

    fredl authored
Commits on Feb 29, 2012
  1. @fredl

    simple commit

    fredl authored
This page is out of date. Refresh to see the latest.
View
0  MANIFEST.in 100755 → 100644
File mode changed
View
0  debian/rules 100755 → 100644
File mode changed
View
27 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
View
25 tests/test_gridfs.py
@@ -261,4 +261,27 @@ 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)
+
Something went wrong with that request. Please try again.