aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2011-07-10 21:16:50 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2011-07-10 21:16:50 -0500
commit85663692cdedf95082e5f505319a22f03d298bfd (patch)
tree9f583fddad15d9c0a4f0e87cd92568a8678251ed
parentae6b0a4e6e5234c7721b105813cf91f23db3b10b (diff)
downloadmediagoblin-85663692cdedf95082e5f505319a22f03d298bfd.tar.lz
mediagoblin-85663692cdedf95082e5f505319a22f03d298bfd.tar.xz
mediagoblin-85663692cdedf95082e5f505319a22f03d298bfd.zip
testing tools install_fixtures_simple and assert_db_meets_expected
Thought I installed these... guess I didn't!
-rw-r--r--mediagoblin/tests/tools.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index e56af4de..4b61f259 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -118,3 +118,35 @@ def setup_fresh_app(func):
return func(test_app, *args, **kwargs)
return _make_safe(wrapper, func)
+
+
+def install_fixtures_simple(db, fixtures):
+ """
+ Very simply install fixtures in the database
+ """
+ for collection_name, collection_fixtures in fixtures.iteritems():
+ collection = db[collection_name]
+ for fixture in collection_fixtures:
+ collection.insert(fixture)
+
+
+def assert_db_meets_expected(db, expected):
+ """
+ Assert a database contains the things we expect it to.
+
+ Objects are found via '_id', so you should make sure your document
+ has an _id.
+
+ Args:
+ - db: pymongo or mongokit database connection
+ - expected: the data we expect. Formatted like:
+ {'collection_name': [
+ {'_id': 'foo',
+ 'some_field': 'some_value'},]}
+ """
+ for collection_name, collection_data in expected.iteritems():
+ collection = db[collection_name]
+ for expected_document in collection_data:
+ document = collection.find_one({'_id': expected_document['_id']})
+ assert document is not None # make sure it exists
+ assert document == expected_document # make sure it matches