diff options
Diffstat (limited to 'mediagoblin/tests')
-rw-r--r-- | mediagoblin/tests/test_auth.py | 16 | ||||
-rw-r--r-- | mediagoblin/tests/test_edit.py | 8 | ||||
-rw-r--r-- | mediagoblin/tests/test_sql_migrations.py | 14 | ||||
-rw-r--r-- | mediagoblin/tests/test_submission.py | 36 | ||||
-rw-r--r-- | mediagoblin/tests/tools.py | 6 |
5 files changed, 42 insertions, 38 deletions
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 8f988af3..1b84b435 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -131,7 +131,7 @@ def test_register_views(test_app): template.clear_test_template_context() response = test_app.post( '/auth/register/', { - 'username': 'happygirl', + 'username': u'happygirl', 'password': 'iamsohappy', 'email': 'happygrrl@example.org'}) response.follow() @@ -145,7 +145,7 @@ def test_register_views(test_app): ## Make sure user is in place new_user = mg_globals.database.User.find_one( - {'username': 'happygirl'}) + {'username': u'happygirl'}) assert new_user assert new_user.status == u'needs_email_verification' assert new_user.email_verified == False @@ -185,7 +185,7 @@ def test_register_views(test_app): # assert context['verification_successful'] == True # TODO: Would be good to test messages here when we can do so... new_user = mg_globals.database.User.find_one( - {'username': 'happygirl'}) + {'username': u'happygirl'}) assert new_user assert new_user.status == u'needs_email_verification' assert new_user.email_verified == False @@ -199,7 +199,7 @@ def test_register_views(test_app): # assert context['verification_successful'] == True # TODO: Would be good to test messages here when we can do so... new_user = mg_globals.database.User.find_one( - {'username': 'happygirl'}) + {'username': u'happygirl'}) assert new_user assert new_user.status == u'active' assert new_user.email_verified == True @@ -210,7 +210,7 @@ def test_register_views(test_app): template.clear_test_template_context() response = test_app.post( '/auth/register/', { - 'username': 'happygirl', + 'username': u'happygirl', 'password': 'iamsohappy2', 'email': 'happygrrl2@example.org'}) @@ -227,7 +227,7 @@ def test_register_views(test_app): template.clear_test_template_context() response = test_app.post( '/auth/forgot_password/', - {'username': 'happygirl'}) + {'username': u'happygirl'}) response.follow() ## Did we redirect to the proper page? Use the right template? @@ -252,7 +252,7 @@ def test_register_views(test_app): parsed_get_params = urlparse.parse_qs(get_params) # user should have matching parameters - new_user = mg_globals.database.User.find_one({'username': 'happygirl'}) + new_user = mg_globals.database.User.find_one({'username': u'happygirl'}) assert parsed_get_params['userid'] == [unicode(new_user._id)] assert parsed_get_params['token'] == [new_user.fp_verification_key] @@ -269,7 +269,7 @@ def test_register_views(test_app): ## Try using an expired token to change password, shouldn't work template.clear_test_template_context() - new_user = mg_globals.database.User.find_one({'username': 'happygirl'}) + new_user = mg_globals.database.User.find_one({'username': u'happygirl'}) real_token_expiration = new_user.fp_token_expire new_user.fp_token_expire = datetime.datetime.now() new_user.save() diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py index 6c4020da..353a7eb9 100644 --- a/mediagoblin/tests/test_edit.py +++ b/mediagoblin/tests/test_edit.py @@ -41,7 +41,7 @@ def test_change_password(test_app): }) # test_user has to be fetched again in order to have the current values - test_user = mg_globals.database.User.one({'username': 'chris'}) + test_user = mg_globals.database.User.one({'username': u'chris'}) assert bcrypt_check_password('123456', test_user.pw_hash) @@ -54,7 +54,7 @@ def test_change_password(test_app): 'new_password': '098765', }) - test_user = mg_globals.database.User.one({'username': 'chris'}) + test_user = mg_globals.database.User.one({'username': u'chris'}) assert not bcrypt_check_password('098765', test_user.pw_hash) @@ -71,7 +71,7 @@ def change_bio_url(test_app): 'bio': u'I love toast!', 'url': u'http://dustycloud.org/'}) - test_user = mg_globals.database.User.one({'username': 'chris'}) + test_user = mg_globals.database.User.one({'username': u'chris'}) assert test_user.bio == u'I love toast!' assert test_user.url == u'http://dustycloud.org/' @@ -85,7 +85,7 @@ def change_bio_url(test_app): 'bio': too_long_bio, 'url': 'this-is-no-url'}) - test_user = mg_globals.database.User.one({'username': 'chris'}) + test_user = mg_globals.database.User.one({'username': u'chris'}) context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/edit/edit_profile.html'] form = context['edit_profile_form'] diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py index 507a7725..8ef46fdc 100644 --- a/mediagoblin/tests/test_sql_migrations.py +++ b/mediagoblin/tests/test_sql_migrations.py @@ -344,8 +344,8 @@ def _insert_migration1_objects(session): name=u'The Necroplex', description=u'A complex full of pure deathzone.', exits={ - 'deathwell': 'evilstorm', - 'portal': 'central_park'}), + u'deathwell': u'evilstorm', + u'portal': u'central_park'}), Level1(id=u'evilstorm', name=u'Evil Storm', description=u'A storm full of pure evil.', @@ -354,7 +354,7 @@ def _insert_migration1_objects(session): name=u'Central Park, NY, NY', description=u"New York's friendly Central Park.", exits={ - 'portal': 'necroplex'})]) + u'portal': u'necroplex'})]) session.commit() @@ -561,7 +561,7 @@ def test_set1_to_set3(): printer = CollectingPrinter() migration_manager = MigrationManager( - '__main__', SET1_MODELS, SET1_MIGRATIONS, Session(), + u'__main__', SET1_MODELS, SET1_MIGRATIONS, Session(), printer) # Check latest migration and database current migration @@ -586,7 +586,7 @@ def test_set1_to_set3(): # Try to "re-migrate" with same manager settings... nothing should happen migration_manager = MigrationManager( - '__main__', SET1_MODELS, SET1_MIGRATIONS, Session(), + u'__main__', SET1_MODELS, SET1_MIGRATIONS, Session(), printer) assert migration_manager.init_or_migrate() == None @@ -668,7 +668,7 @@ def test_set1_to_set3(): # isn't said to be updated yet printer = CollectingPrinter() migration_manager = MigrationManager( - '__main__', SET3_MODELS, SET3_MIGRATIONS, Session(), + u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(), printer) assert migration_manager.latest_migration == 7 @@ -694,7 +694,7 @@ def test_set1_to_set3(): # Make sure version matches expected migration_manager = MigrationManager( - '__main__', SET3_MODELS, SET3_MIGRATIONS, Session(), + u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(), printer) assert migration_manager.latest_migration == 7 assert migration_manager.database_current_migration == 7 diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index bf1b87aa..b7b0e574 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -14,6 +14,10 @@ # 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/>. +import sys +reload(sys) +sys.setdefaultencoding('utf-8') + import urlparse import os @@ -37,8 +41,8 @@ EVIL_JPG = resource('evil.jpg') EVIL_PNG = resource('evil.png') BIG_BLUE = resource('bigblue.png') -GOOD_TAG_STRING = 'yin,yang' -BAD_TAG_STRING = 'rage,' + 'f' * 26 + 'u' * 26 +GOOD_TAG_STRING = u'yin,yang' +BAD_TAG_STRING = unicode('rage,' + 'f' * 26 + 'u' * 26) FORM_CONTEXT = ['mediagoblin/submit/start.html', 'submit_form'] REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request'] @@ -92,7 +96,7 @@ class TestSubmission: # Test blank file # --------------- - response, form = self.do_post({'title': 'test title'}, *FORM_CONTEXT) + response, form = self.do_post({'title': u'test title'}, *FORM_CONTEXT) assert_equal(form.file.errors, [u'You must provide a file.']) def check_url(self, response, path): @@ -112,10 +116,10 @@ class TestSubmission: self.test_app.get(url) def test_normal_jpg(self): - self.check_normal_upload('Normal upload 1', GOOD_JPG) + self.check_normal_upload(u'Normal upload 1', GOOD_JPG) def test_normal_png(self): - self.check_normal_upload('Normal upload 2', GOOD_PNG) + self.check_normal_upload(u'Normal upload 2', GOOD_PNG) def check_media(self, request, find_data, count=None): media = request.db.MediaEntry.find(find_data) @@ -128,11 +132,11 @@ class TestSubmission: def test_tags(self): # Good tag string # -------- - response, request = self.do_post({'title': 'Balanced Goblin', + response, request = self.do_post({'title': u'Balanced Goblin', 'tags': GOOD_TAG_STRING}, *REQUEST_CONTEXT, do_follow=True, **self.upload_data(GOOD_JPG)) - media = self.check_media(request, {'title': 'Balanced Goblin'}, 1) + media = self.check_media(request, {'title': u'Balanced Goblin'}, 1) assert media.tags[0]['name'] == u'yin' assert media.tags[0]['slug'] == u'yin' @@ -141,7 +145,7 @@ class TestSubmission: # Test tags that are too long # --------------- - response, form = self.do_post({'title': 'Balanced Goblin', + response, form = self.do_post({'title': u'Balanced Goblin', 'tags': BAD_TAG_STRING}, *FORM_CONTEXT, **self.upload_data(GOOD_JPG)) @@ -151,10 +155,10 @@ class TestSubmission: 'ffffffffffffffffffffffffffuuuuuuuuuuuuuuuuuuuuuuuuuu']) def test_delete(self): - response, request = self.do_post({'title': 'Balanced Goblin'}, + response, request = self.do_post({'title': u'Balanced Goblin'}, *REQUEST_CONTEXT, do_follow=True, **self.upload_data(GOOD_JPG)) - media = self.check_media(request, {'title': 'Balanced Goblin'}, 1) + media = self.check_media(request, {'title': u'Balanced Goblin'}, 1) media_id = media.id # Add a comment, so we can test for its deletion later. @@ -173,7 +177,7 @@ class TestSubmission: user=self.test_user.username, media=media_id) # Empty data means don't confirm response = self.do_post({}, do_follow=True, url=delete_url)[0] - media = self.check_media(request, {'title': 'Balanced Goblin'}, 1) + media = self.check_media(request, {'title': u'Balanced Goblin'}, 1) media_id = media.id # Confirm deletion @@ -186,7 +190,7 @@ class TestSubmission: def test_evil_file(self): # Test non-suppoerted file with non-supported extension # ----------------------------------------------------- - response, form = self.do_post({'title': 'Malicious Upload 1'}, + response, form = self.do_post({'title': u'Malicious Upload 1'}, *FORM_CONTEXT, **self.upload_data(EVIL_FILE)) assert_equal(len(form.file.errors), 1) @@ -200,7 +204,7 @@ class TestSubmission: template.clear_test_template_context() response = self.test_app.post( '/submit/', { - 'title': 'UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE' + 'title': u'UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE' }, upload_files=[( 'file', GOOD_JPG)]) @@ -229,15 +233,15 @@ class TestSubmission: def test_evil_jpg(self): # Test non-supported file with .jpg extension # ------------------------------------------- - self.check_false_image('Malicious Upload 2', EVIL_JPG) + self.check_false_image(u'Malicious Upload 2', EVIL_JPG) def test_evil_png(self): # Test non-supported file with .png extension # ------------------------------------------- - self.check_false_image('Malicious Upload 3', EVIL_PNG) + self.check_false_image(u'Malicious Upload 3', EVIL_PNG) def test_processing(self): - data = {'title': 'Big Blue'} + data = {'title': u'Big Blue'} response, request = self.do_post(data, *REQUEST_CONTEXT, do_follow=True, **self.upload_data(BIG_BLUE)) media = self.check_media(request, data, 1) diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index 5b4e3746..bf40ea8b 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -116,6 +116,9 @@ def get_test_app(dump_old_app=True): if MGOBLIN_APP and not dump_old_app: return MGOBLIN_APP + Session.rollback() + Session.remove() + # Remove and reinstall user_dev directories if os.path.exists(TEST_USER_DEV): shutil.rmtree(TEST_USER_DEV) @@ -135,9 +138,6 @@ def get_test_app(dump_old_app=True): test_app = loadapp( 'config:' + TEST_SERVER_CONFIG) - Session.rollback() - Session.remove() - # Re-setup celery setup_celery_app(app_config, global_config) |