diff options
author | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-11-30 10:49:06 +0100 |
---|---|---|
committer | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-12-21 00:30:48 +0100 |
commit | 5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868 (patch) | |
tree | 6b2ec753c753745ee7964b9544835619b915d0f2 /mediagoblin/tests | |
parent | 7e55bcb898d37010a5e9bd8a666cd3ddfa63de33 (diff) | |
download | mediagoblin-5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868.tar.lz mediagoblin-5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868.tar.xz mediagoblin-5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868.zip |
Move DBModel._id -> DBModel.id
We were refering to model._id in most of the code base as this is
what Mongo uses. However, each use of _id required a) fixup of queries:
e.g. what we did in our find() and find_one() functions moving all
'_id' to 'id'. It also required using AliasFields to make the ._id
attribute available. This all means lots of superfluous fixing and
transitioning in a SQL world.
It will also not work in the long run. Much newer code already refers
to the objects by model.id (e.g. in the oauth plugin), which will break
with Mongo. So let's be honest, rip out the _id mongoism and live with
.id as the one canonical way to address objects.
This commit modifies all users and providers of model._id to use
model.id instead. This patch works with or without Mongo removed first,
but will break Mongo usage (even more than before)
I have not bothered to fixup db.mongo.* and db.sql.convert
(which converts from Mongo to SQL)
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin/tests')
-rw-r--r-- | mediagoblin/tests/test_auth.py | 12 | ||||
-rw-r--r-- | mediagoblin/tests/test_submission.py | 2 | ||||
-rw-r--r-- | mediagoblin/tests/tools.py | 8 |
3 files changed, 11 insertions, 11 deletions
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index da17554b..06365161 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -154,7 +154,7 @@ def test_register_views(test_app): ## Make sure user is logged in request = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/user_pages/user.html']['request'] - assert request.session['user_id'] == unicode(new_user._id) + assert request.session['user_id'] == unicode(new_user.id) ## Make sure we get email confirmation, and try verifying assert len(mail.EMAIL_TEST_INBOX) == 1 @@ -171,7 +171,7 @@ def test_register_views(test_app): ### user should have these same parameters assert parsed_get_params['userid'] == [ - unicode(new_user._id)] + unicode(new_user.id)] assert parsed_get_params['token'] == [ new_user.verification_key] @@ -179,7 +179,7 @@ def test_register_views(test_app): template.clear_test_template_context() response = test_app.get( "/auth/verify_email/?userid=%s&token=total_bs" % unicode( - new_user._id)) + new_user.id)) response.follow() context = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/user_pages/user.html'] @@ -254,7 +254,7 @@ def test_register_views(test_app): # user should have matching parameters new_user = mg_globals.database.User.find_one({'username': u'happygirl'}) - assert parsed_get_params['userid'] == [unicode(new_user._id)] + assert parsed_get_params['userid'] == [unicode(new_user.id)] assert parsed_get_params['token'] == [new_user.fp_verification_key] ### The forgotten password token should be set to expire in ~ 10 days @@ -265,7 +265,7 @@ def test_register_views(test_app): template.clear_test_template_context() response = test_app.get( "/auth/forgot_password/verify/?userid=%s&token=total_bs" % unicode( - new_user._id), status=404) + new_user.id), status=404) assert_equal(response.status, '404 Not Found') ## Try using an expired token to change password, shouldn't work @@ -393,7 +393,7 @@ def test_authentication_views(test_app): # Make sure user is in the session context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html'] session = context['request'].session - assert session['user_id'] == unicode(test_user._id) + assert session['user_id'] == unicode(test_user.id) # Successful logout # ----------------- diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index b6fe0015..589ba7ed 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -184,7 +184,7 @@ class TestSubmission: # --------------------------------------------------- response, request = self.do_post({'confirm': 'y'}, *REQUEST_CONTEXT, do_follow=True, url=delete_url) - self.check_media(request, {'_id': media_id}, 0) + self.check_media(request, {'id': media_id}, 0) self.check_comments(request, media_id, 0) def test_evil_file(self): diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index d3369831..8c09c7ec 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -184,20 +184,20 @@ 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. + 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', + {'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']}) + 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 |