diff options
-rw-r--r-- | mediagoblin/db/mixin.py | 2 | ||||
-rw-r--r-- | mediagoblin/db/sql/models.py | 4 | ||||
-rw-r--r-- | mediagoblin/decorators.py | 6 | ||||
-rw-r--r-- | mediagoblin/gmg_commands/dbupdate.py | 2 | ||||
-rw-r--r-- | mediagoblin/media_types/image/processing.py | 6 | ||||
-rw-r--r-- | mediagoblin/processing/__init__.py | 2 | ||||
-rw-r--r-- | mediagoblin/storage/__init__.py | 2 | ||||
-rw-r--r-- | mediagoblin/submit/views.py | 2 | ||||
-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 | ||||
-rw-r--r-- | mediagoblin/tools/mail.py | 7 | ||||
-rw-r--r-- | mediagoblin/user_pages/views.py | 16 |
15 files changed, 68 insertions, 61 deletions
diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index a5aded02..fe6dc796 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -60,7 +60,7 @@ class MediaEntryMixin(object): if duplicate: if self.id is not None: - self.slug = "%s-%s" % (self.id, self.slug) + self.slug = u"%s-%s" % (self.id, self.slug) else: self.slug = None diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index d17386fc..9815fcf9 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -158,7 +158,7 @@ class MediaEntry(Base, MediaEntryMixin): """get the next 'newer' entry by this user""" media = MediaEntry.query.filter( (MediaEntry.uploader == self.uploader) - & (MediaEntry.state == 'processed') + & (MediaEntry.state == u'processed') & (MediaEntry.id > self.id)).order_by(MediaEntry.id).first() if media is not None: @@ -168,7 +168,7 @@ class MediaEntry(Base, MediaEntryMixin): """get the next 'older' entry by this user""" media = MediaEntry.query.filter( (MediaEntry.uploader == self.uploader) - & (MediaEntry.state == 'processed') + & (MediaEntry.state == u'processed') & (MediaEntry.id < self.id)).order_by(desc(MediaEntry.id)).first() if media is not None: diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index 83602c70..b2791083 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -97,7 +97,7 @@ def get_user_media_entry(controller): return render_404(request) media = request.db.MediaEntry.find_one( {'slug': request.matchdict['media'], - 'state': 'processed', + 'state': u'processed', 'uploader': user._id}) # no media via slug? Grab it via ObjectId @@ -105,7 +105,7 @@ def get_user_media_entry(controller): try: media = request.db.MediaEntry.find_one( {'_id': ObjectId(request.matchdict['media']), - 'state': 'processed', + 'state': u'processed', 'uploader': user._id}) except InvalidId: return render_404(request) @@ -127,7 +127,7 @@ def get_media_entry_by_id(controller): try: media = request.db.MediaEntry.find_one( {'_id': ObjectId(request.matchdict['media']), - 'state': 'processed'}) + 'state': u'processed'}) except InvalidId: return render_404(request) diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index dc36be82..1c48ff57 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -52,7 +52,7 @@ def gather_database_data(media_types): managed_dbdata.append( DatabaseData( - '__main__', MAIN_MODELS, MAIN_MIGRATIONS)) + u'__main__', MAIN_MODELS, MAIN_MIGRATIONS)) # Then get all registered media managers (eventually, plugins) for media_type in media_types: diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py index 487d593a..32b1f4f7 100644 --- a/mediagoblin/media_types/image/processing.py +++ b/mediagoblin/media_types/image/processing.py @@ -143,10 +143,10 @@ def process_image(entry): # Insert media file information into database media_files_dict = entry.setdefault('media_files', {}) - media_files_dict['thumb'] = thumb_filepath - media_files_dict['original'] = original_filepath + media_files_dict[u'thumb'] = thumb_filepath + media_files_dict[u'original'] = original_filepath if medium_filepath: - media_files_dict['medium'] = medium_filepath + media_files_dict[u'medium'] = medium_filepath # Insert exif data into database exif_all = clean_exif(exif_tags) diff --git a/mediagoblin/processing/__init__.py b/mediagoblin/processing/__init__.py index 4a827af4..85b61880 100644 --- a/mediagoblin/processing/__init__.py +++ b/mediagoblin/processing/__init__.py @@ -84,7 +84,7 @@ def mark_entry_failed(entry_id, exc): atomic_update(mgg.database.MediaEntry, {'_id': entry_id}, {u'state': u'failed', - u'fail_error': exc.exception_path, + u'fail_error': unicode(exc.exception_path), u'fail_metadata': exc.metadata}) else: _log.warn("No idea what happened here, but it failed: %r", exc) diff --git a/mediagoblin/storage/__init__.py b/mediagoblin/storage/__init__.py index 3df56c2e..2db4c37d 100644 --- a/mediagoblin/storage/__init__.py +++ b/mediagoblin/storage/__init__.py @@ -248,3 +248,5 @@ def storage_system_from_config(config_section): storage_class = common.import_component(storage_class) return storage_class(**config_params) + +import filestorage diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 517fb646..72186136 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -167,7 +167,7 @@ def submit_start(request): except Exception as e: ''' This section is intended to catch exceptions raised in - mediagobling.media_types + mediagoblin.media_types ''' if isinstance(e, InvalidFileType) or \ isinstance(e, FileTypeNotSupported): 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) diff --git a/mediagoblin/tools/mail.py b/mediagoblin/tools/mail.py index 655d5b99..8639ba0c 100644 --- a/mediagoblin/tools/mail.py +++ b/mediagoblin/tools/mail.py @@ -98,8 +98,9 @@ def send_email(from_addr, to_addrs, subject, message_body): if not mg_globals.app_config['email_smtp_host']: # e.g. host = '' mhost.connect() # We SMTP.connect explicitly - if mg_globals.app_config['email_smtp_user'] \ - or mg_globals.app_config['email_smtp_pass']: + if ((not common.TESTS_ENABLED) + and (mg_globals.app_config['email_smtp_user'] + or mg_globals.app_config['email_smtp_pass'])): mhost.login( mg_globals.app_config['email_smtp_user'], mg_globals.app_config['email_smtp_pass']) @@ -112,7 +113,7 @@ def send_email(from_addr, to_addrs, subject, message_body): if common.TESTS_ENABLED: EMAIL_TEST_INBOX.append(message) - if mg_globals.app_config['email_debug_mode']: + elif mg_globals.app_config['email_debug_mode']: print u"===== Email =====" print u"From address: %s" % message['From'] print u"To addresses: %s" % message['To'] diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 870e2155..0e061c46 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -52,7 +52,7 @@ def user_home(request, page): cursor = request.db.MediaEntry.find( {'uploader': user._id, - 'state': 'processed'}).sort('created', DESCENDING) + 'state': u'processed'}).sort('created', DESCENDING) pagination = Pagination(page, cursor) media_entries = pagination() @@ -79,13 +79,13 @@ def user_gallery(request, page): """'Gallery' of a User()""" user = request.db.User.find_one({ 'username': request.matchdict['user'], - 'status': 'active'}) + 'status': u'active'}) if not user: return render_404(request) cursor = request.db.MediaEntry.find( {'uploader': user._id, - 'state': 'processed'}).sort('created', DESCENDING) + 'state': u'processed'}).sort('created', DESCENDING) pagination = Pagination(page, cursor) media_entries = pagination() @@ -235,13 +235,13 @@ def atom_feed(request): user = request.db.User.find_one({ 'username': request.matchdict['user'], - 'status': 'active'}) + 'status': u'active'}) if not user: return render_404(request) cursor = request.db.MediaEntry.find({ 'uploader': user._id, - 'state': 'processed'}) \ + 'state': u'processed'}) \ .sort('created', DESCENDING) \ .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) @@ -298,7 +298,7 @@ def processing_panel(request): # Get the user user = request.db.User.find_one( {'username': request.matchdict['user'], - 'status': 'active'}) + 'status': u'active'}) # Make sure the user exists and is active if not user: @@ -323,12 +323,12 @@ def processing_panel(request): # Get media entries which are in-processing processing_entries = request.db.MediaEntry.find( {'uploader': user._id, - 'state': 'unprocessed'}).sort('created', DESCENDING) + 'state': u'unprocessed'}).sort('created', DESCENDING) # Get media entries which have failed to process failed_entries = request.db.MediaEntry.find( {'uploader': user._id, - 'state': 'failed'}).sort('created', DESCENDING) + 'state': u'failed'}).sort('created', DESCENDING) # Render to response return render_to_response( |