diff options
Diffstat (limited to 'mediagoblin/tests')
-rw-r--r-- | mediagoblin/tests/test_auth.py | 21 | ||||
-rw-r--r-- | mediagoblin/tests/test_storage.py | 9 | ||||
-rw-r--r-- | mediagoblin/tests/test_submission.py | 2 | ||||
-rw-r--r-- | mediagoblin/tests/test_tests.py | 10 | ||||
-rw-r--r-- | mediagoblin/tests/tools.py | 10 |
5 files changed, 27 insertions, 25 deletions
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 1b84b435..169b2309 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -19,9 +19,10 @@ import datetime from nose.tools import assert_equal +from mediagoblin import mg_globals from mediagoblin.auth import lib as auth_lib +from mediagoblin.db.sql.models import User from mediagoblin.tests.tools import setup_fresh_app, fixture_add_user -from mediagoblin import mg_globals from mediagoblin.tools import template, mail @@ -124,7 +125,7 @@ def test_register_views(test_app): u'Invalid email address.'] ## At this point there should be no users in the database ;) - assert not mg_globals.database.User.find().count() + assert not User.query.count() # Successful register # ------------------- @@ -153,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 @@ -170,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] @@ -178,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'] @@ -253,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 @@ -264,8 +265,8 @@ 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) - assert_equal(response.status, '404 Not Found') + new_user.id), status=404) + assert_equal(response.status.split()[0], u'404') # status="404 NOT FOUND" ## Try using an expired token to change password, shouldn't work template.clear_test_template_context() @@ -274,7 +275,7 @@ def test_register_views(test_app): new_user.fp_token_expire = datetime.datetime.now() new_user.save() response = test_app.get("%s?%s" % (path, get_params), status=404) - assert_equal(response.status, '404 Not Found') + assert_equal(response.status.split()[0], u'404') # status="404 NOT FOUND" new_user.fp_token_expire = real_token_expiration new_user.save() @@ -392,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_storage.py b/mediagoblin/tests/test_storage.py index 6fc2e57c..61326ae9 100644 --- a/mediagoblin/tests/test_storage.py +++ b/mediagoblin/tests/test_storage.py @@ -18,7 +18,7 @@ import os import tempfile -from nose.tools import assert_raises +from nose.tools import assert_raises, assert_equal, assert_true from werkzeug.utils import secure_filename from mediagoblin import storage @@ -78,9 +78,10 @@ def test_storage_system_from_config(): 'garbage_arg': 'garbage_arg', 'storage_class': 'mediagoblin.tests.test_storage:FakeStorageSystem'}) - assert this_storage.foobie == 'eiboof' - assert this_storage.blech == 'hcelb' - assert this_storage.__class__ is FakeStorageSystem + assert_equal(this_storage.foobie, 'eiboof') + assert_equal(this_storage.blech, 'hcelb') + assert_equal(unicode(this_storage.__class__), + u'mediagoblin.tests.test_storage.FakeStorageSystem') ########################## 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/test_tests.py b/mediagoblin/tests/test_tests.py index 20832ac7..2228d15a 100644 --- a/mediagoblin/tests/test_tests.py +++ b/mediagoblin/tests/test_tests.py @@ -14,9 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -from mediagoblin.tests.tools import get_test_app - from mediagoblin import mg_globals +from mediagoblin.tests.tools import get_test_app +from mediagoblin.db.sql.models import User def test_get_test_app_wipes_db(): @@ -24,15 +24,15 @@ def test_get_test_app_wipes_db(): Make sure we get a fresh database on every wipe :) """ get_test_app() - assert mg_globals.database.User.find().count() == 0 + assert User.query.count() == 0 new_user = mg_globals.database.User() new_user.username = u'lolcat' new_user.email = u'lol@cats.example.org' new_user.pw_hash = u'pretend_this_is_a_hash' new_user.save() - assert mg_globals.database.User.find().count() == 1 + assert User.query.count() == 1 get_test_app() - assert mg_globals.database.User.find().count() == 0 + assert User.query.count() == 0 diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index d3369831..0e923aee 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -78,7 +78,7 @@ class TestingMeddleware(BaseMeddleware): def process_response(self, request, response): # All following tests should be for html only! - if response.content_type != "text/html": + if getattr(response, 'content_type', None) != "text/html": # Get out early return @@ -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 |