From 386c9c7c55147b27c258edd5deee36594553493d Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 26 May 2014 19:50:38 +0300 Subject: Use six.iteritems() instead of dict.iteritems(). --- mediagoblin/tests/test_sql_migrations.py | 4 +++- mediagoblin/tests/tools.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py index 3d67fdf6..e86dcd80 100644 --- a/mediagoblin/tests/test_sql_migrations.py +++ b/mediagoblin/tests/test_sql_migrations.py @@ -16,6 +16,8 @@ import copy +import six + from sqlalchemy import ( Table, Column, MetaData, Index, Integer, Float, Unicode, UnicodeText, DateTime, Boolean, @@ -190,7 +192,7 @@ def level_exits_new_table(db_conn): for level in result: - for exit_name, to_level in level['exits'].iteritems(): + for exit_name, to_level in six.iteritems(level['exits']): # Insert the level exit db_conn.execute( level_exits.insert().values( diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index 060dfda9..b8e06e19 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -19,6 +19,7 @@ import os import pkg_resources import shutil +import six from paste.deploy import loadapp from webtest import TestApp @@ -142,7 +143,7 @@ def install_fixtures_simple(db, fixtures): """ Very simply install fixtures in the database """ - for collection_name, collection_fixtures in fixtures.iteritems(): + for collection_name, collection_fixtures in six.iteritems(fixtures): collection = db[collection_name] for fixture in collection_fixtures: collection.insert(fixture) @@ -162,7 +163,7 @@ def assert_db_meets_expected(db, expected): {'id': 'foo', 'some_field': 'some_value'},]} """ - for collection_name, collection_data in expected.iteritems(): + for collection_name, collection_data in six.iteritems(expected): collection = db[collection_name] for expected_document in collection_data: document = collection.query.filter_by(id=expected_document['id']).first() -- cgit v1.2.3 From fd19da346b7bcbc6310a4f53d3d224797a319e9c Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 26 May 2014 19:52:18 +0300 Subject: Use six.moves.urllib.parse instead of the urlparse module. --- mediagoblin/tests/test_auth.py | 4 +++- mediagoblin/tests/test_basic_auth.py | 3 ++- mediagoblin/tests/test_ldap.py | 4 +++- mediagoblin/tests/test_notifications.py | 2 +- mediagoblin/tests/test_persona.py | 4 +++- mediagoblin/tests/test_submission.py | 3 ++- 6 files changed, 14 insertions(+), 6 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 1bbc3d01..e8fd76d8 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -14,10 +14,12 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import urlparse + import pkg_resources import pytest +import six.moves.urllib.parse as urlparse + from mediagoblin import mg_globals from mediagoblin.db.models import User from mediagoblin.tests.tools import get_app, fixture_add_user diff --git a/mediagoblin/tests/test_basic_auth.py b/mediagoblin/tests/test_basic_auth.py index 828f0515..e7157bee 100644 --- a/mediagoblin/tests/test_basic_auth.py +++ b/mediagoblin/tests/test_basic_auth.py @@ -13,7 +13,8 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import urlparse + +import six.moves.urllib.parse as urlparse from mediagoblin.db.models import User from mediagoblin.plugins.basic_auth import tools as auth_tools diff --git a/mediagoblin/tests/test_ldap.py b/mediagoblin/tests/test_ldap.py index 48efb4b6..33cf85d6 100644 --- a/mediagoblin/tests/test_ldap.py +++ b/mediagoblin/tests/test_ldap.py @@ -13,11 +13,13 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import urlparse + import pkg_resources import pytest import mock +import six.moves.urllib.parse as urlparse + from mediagoblin import mg_globals from mediagoblin.db.base import Session from mediagoblin.tests.tools import get_app diff --git a/mediagoblin/tests/test_notifications.py b/mediagoblin/tests/test_notifications.py index 3bf36f5f..37d61c41 100644 --- a/mediagoblin/tests/test_notifications.py +++ b/mediagoblin/tests/test_notifications.py @@ -16,7 +16,7 @@ import pytest -import urlparse +import six.moves.urllib.parse as urlparse from mediagoblin.tools import template, mail diff --git a/mediagoblin/tests/test_persona.py b/mediagoblin/tests/test_persona.py index a1cd30eb..dbc4797a 100644 --- a/mediagoblin/tests/test_persona.py +++ b/mediagoblin/tests/test_persona.py @@ -13,11 +13,13 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import urlparse + import pkg_resources import pytest import mock +import six.moves.urllib.parse as urlparse + pytest.importorskip("requests") from mediagoblin import mg_globals diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index b5b13ed3..5ddd882c 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -18,10 +18,11 @@ import sys reload(sys) sys.setdefaultencoding('utf-8') -import urlparse import os import pytest +import six.moves.urllib.parse as urlparse + from mediagoblin.tests.tools import fixture_add_user from mediagoblin import mg_globals from mediagoblin.db.models import MediaEntry, User -- cgit v1.2.3 From e49b7e02b2150413d2e78db709277fae0887be46 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 2 Jun 2014 20:59:28 +0300 Subject: Use six.text_type instead of unicode(). I will be switch to use ``from __future__ import unicode_literals`` later. --- mediagoblin/tests/test_auth.py | 6 ++++-- mediagoblin/tests/test_http_callback.py | 4 +++- mediagoblin/tests/test_ldap.py | 3 ++- mediagoblin/tests/test_oauth2.py | 6 ++++-- mediagoblin/tests/test_openid.py | 3 ++- mediagoblin/tests/test_persona.py | 3 ++- mediagoblin/tests/test_reporting.py | 5 +++-- mediagoblin/tests/test_storage.py | 4 +++- mediagoblin/tests/test_submission.py | 3 ++- mediagoblin/tests/test_util.py | 6 ++++-- 10 files changed, 29 insertions(+), 14 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index e8fd76d8..9b7f9825 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -18,6 +18,8 @@ import pkg_resources import pytest +import six + import six.moves.urllib.parse as urlparse from mediagoblin import mg_globals @@ -109,7 +111,7 @@ def test_register_views(test_app): ## Make sure user is logged in request = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/user_pages/user_nonactive.html']['request'] - assert request.session['user_id'] == unicode(new_user.id) + assert request.session['user_id'] == six.text_type(new_user.id) ## Make sure we get email confirmation, and try verifying assert len(mail.EMAIL_TEST_INBOX) == 1 @@ -307,7 +309,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'] == six.text_type(test_user.id) # Successful logout # ----------------- diff --git a/mediagoblin/tests/test_http_callback.py b/mediagoblin/tests/test_http_callback.py index 64b7ee8f..d0a8c823 100644 --- a/mediagoblin/tests/test_http_callback.py +++ b/mediagoblin/tests/test_http_callback.py @@ -17,6 +17,8 @@ import json import pytest +import six + from urlparse import urlparse, parse_qs from mediagoblin import mg_globals @@ -63,7 +65,7 @@ class TestHTTPCallback(object): code = parse_qs(urlparse(redirect.location).query)['code'][0] client = self.db.OAuthClient.query.filter( - self.db.OAuthClient.identifier == unicode(client_id)).first() + self.db.OAuthClient.identifier == six.text_type(client_id)).first() client_secret = client.secret diff --git a/mediagoblin/tests/test_ldap.py b/mediagoblin/tests/test_ldap.py index 33cf85d6..e69a3203 100644 --- a/mediagoblin/tests/test_ldap.py +++ b/mediagoblin/tests/test_ldap.py @@ -17,6 +17,7 @@ import pkg_resources import pytest import mock +import six import six.moves.urllib.parse as urlparse @@ -122,6 +123,6 @@ def test_ldap_plugin(ldap_plugin_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'] == six.text_type(test_user.id) _test_authentication() diff --git a/mediagoblin/tests/test_oauth2.py b/mediagoblin/tests/test_oauth2.py index 957f4e65..6bdb729e 100644 --- a/mediagoblin/tests/test_oauth2.py +++ b/mediagoblin/tests/test_oauth2.py @@ -18,6 +18,8 @@ import json import logging import pytest +import six + from urlparse import parse_qs, urlparse from mediagoblin import mg_globals @@ -154,7 +156,7 @@ class TestOAuth(object): code = self.get_code_from_redirect_uri(code_redirect.location) client = self.db.OAuthClient.query.filter( - self.db.OAuthClient.identifier == unicode(client_id)).first() + self.db.OAuthClient.identifier == six.text_type(client_id)).first() token_res = self.test_app.get('/oauth-2/access_token?client_id={0}&\ code={1}&client_secret={2}'.format(client_id, code, client.secret)) @@ -182,7 +184,7 @@ code={1}&client_secret={2}'.format(client_id, code, client.secret)) code = self.get_code_from_redirect_uri(code_redirect.location) client = self.db.OAuthClient.query.filter( - self.db.OAuthClient.identifier == unicode(client_id)).first() + self.db.OAuthClient.identifier == six.text_type(client_id)).first() token_res = self.test_app.get('/oauth-2/access_token?\ code={0}&client_secret={1}'.format(code, client.secret)) diff --git a/mediagoblin/tests/test_openid.py b/mediagoblin/tests/test_openid.py index 0424fdda..7ef01052 100644 --- a/mediagoblin/tests/test_openid.py +++ b/mediagoblin/tests/test_openid.py @@ -18,6 +18,7 @@ import urlparse import pkg_resources import pytest import mock +import six openid_consumer = pytest.importorskip( "openid.consumer.consumer") @@ -206,7 +207,7 @@ class TestOpenIDPlugin(object): # 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'] == six.text_type(test_user.id) _test_new_user() diff --git a/mediagoblin/tests/test_persona.py b/mediagoblin/tests/test_persona.py index dbc4797a..f2dd4001 100644 --- a/mediagoblin/tests/test_persona.py +++ b/mediagoblin/tests/test_persona.py @@ -17,6 +17,7 @@ import pkg_resources import pytest import mock +import six import six.moves.urllib.parse as urlparse @@ -142,7 +143,7 @@ class TestPersonaPlugin(object): # 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'] == six.text_type(test_user.id) _test_registration() diff --git a/mediagoblin/tests/test_reporting.py b/mediagoblin/tests/test_reporting.py index a154a061..6a9fe205 100644 --- a/mediagoblin/tests/test_reporting.py +++ b/mediagoblin/tests/test_reporting.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import pytest +import six from mediagoblin.tools import template from mediagoblin.tests.tools import (fixture_add_user, fixture_media_entry, @@ -75,7 +76,7 @@ class TestReportFiling: response, context = self.do_post( {'report_reason':u'Testing Media Report', - 'reporter_id':unicode(allie_id)},url= media_uri_slug + "report/") + 'reporter_id':six.text_type(allie_id)},url= media_uri_slug + "report/") assert response.status == "302 FOUND" @@ -110,7 +111,7 @@ class TestReportFiling: response, context = self.do_post({ 'report_reason':u'Testing Comment Report', - 'reporter_id':unicode(allie_id)},url= comment_uri_slug + "report/") + 'reporter_id':six.text_type(allie_id)},url= comment_uri_slug + "report/") assert response.status == "302 FOUND" diff --git a/mediagoblin/tests/test_storage.py b/mediagoblin/tests/test_storage.py index f6f1d18f..21947415 100644 --- a/mediagoblin/tests/test_storage.py +++ b/mediagoblin/tests/test_storage.py @@ -19,6 +19,8 @@ import os import tempfile import pytest +import six + from werkzeug.utils import secure_filename from mediagoblin import storage @@ -78,7 +80,7 @@ def test_storage_system_from_config(): 'mediagoblin.tests.test_storage:FakeStorageSystem'}) assert this_storage.foobie == 'eiboof' assert this_storage.blech == 'hcelb' - assert unicode(this_storage.__class__) == \ + assert six.text_type(this_storage.__class__) == \ u'mediagoblin.tests.test_storage.FakeStorageSystem' diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index 5ddd882c..6143c0ac 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -20,6 +20,7 @@ sys.setdefaultencoding('utf-8') import os import pytest +import six import six.moves.urllib.parse as urlparse @@ -35,7 +36,7 @@ from .resources import GOOD_JPG, GOOD_PNG, EVIL_FILE, EVIL_JPG, EVIL_PNG, \ BIG_BLUE, GOOD_PDF, GPS_JPG, MED_PNG, BIG_PNG GOOD_TAG_STRING = u'yin,yang' -BAD_TAG_STRING = unicode('rage,' + 'f' * 26 + 'u' * 26) +BAD_TAG_STRING = six.text_type('rage,' + 'f' * 26 + 'u' * 26) FORM_CONTEXT = ['mediagoblin/submit/start.html', 'submit_form'] REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request'] diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py index 9d9b1c16..e108e9bb 100644 --- a/mediagoblin/tests/test_util.py +++ b/mediagoblin/tests/test_util.py @@ -16,6 +16,8 @@ import email +import six + from mediagoblin.tools import common, url, translate, mail, text, testing testing._activate_testing() @@ -117,13 +119,13 @@ def test_gettext_lazy_proxy(): orig = u"Password" set_thread_locale("es") - p1 = unicode(proxy) + p1 = six.text_type(proxy) p1_should = pass_to_ugettext(orig) assert p1_should != orig, "Test useless, string not translated" assert p1 == p1_should set_thread_locale("sv") - p2 = unicode(proxy) + p2 = six.text_type(proxy) p2_should = pass_to_ugettext(orig) assert p2_should != orig, "Test broken, string not translated" assert p2 == p2_should -- cgit v1.2.3 From d9aced73f16b37eb24b24778f8f448769f1a7665 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sat, 7 Jun 2014 13:51:42 +0300 Subject: The file() builtin has been removed in Python 3. Use open() instead. --- mediagoblin/tests/test_pluginapi.py | 6 +++--- mediagoblin/tests/test_storage.py | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_pluginapi.py b/mediagoblin/tests/test_pluginapi.py index eae0ce15..5a3d41e6 100644 --- a/mediagoblin/tests/test_pluginapi.py +++ b/mediagoblin/tests/test_pluginapi.py @@ -421,7 +421,7 @@ def test_plugin_assetlink(static_plugin_app): junk_file_path = os.path.join( linked_assets_dir.rstrip(os.path.sep), 'junk.txt') - with file(junk_file_path, 'w') as junk_file: + with open(junk_file_path, 'w') as junk_file: junk_file.write('barf') os.unlink(plugin_link_dir) @@ -440,14 +440,14 @@ to: # link dir exists, but is a non-symlink os.unlink(plugin_link_dir) - with file(plugin_link_dir, 'w') as clobber_file: + with open(plugin_link_dir, 'w') as clobber_file: clobber_file.write('clobbered!') result = run_assetlink().collection[0] assert result == 'Could not link "staticstuff": %s exists and is not a symlink\n' % ( plugin_link_dir) - with file(plugin_link_dir, 'r') as clobber_file: + with open(plugin_link_dir, 'r') as clobber_file: assert clobber_file.read() == 'clobbered!' diff --git a/mediagoblin/tests/test_storage.py b/mediagoblin/tests/test_storage.py index 21947415..9b96ecbe 100644 --- a/mediagoblin/tests/test_storage.py +++ b/mediagoblin/tests/test_storage.py @@ -174,7 +174,7 @@ def test_basic_storage_get_file(): with this_storage.get_file(filepath, 'r') as our_file: assert our_file.read() == 'First file' assert os.path.exists(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt')) - with file(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'), 'r') as our_file: + with open(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'), 'r') as our_file: assert our_file.read() == 'First file' # Write to the same path but try to get a unique file. @@ -186,13 +186,13 @@ def test_basic_storage_get_file(): with this_storage.get_file(new_filepath, 'r') as our_file: assert our_file.read() == 'Second file' assert os.path.exists(os.path.join(tmpdir, *new_filepath)) - with file(os.path.join(tmpdir, *new_filepath), 'r') as our_file: + with open(os.path.join(tmpdir, *new_filepath), 'r') as our_file: assert our_file.read() == 'Second file' # Read from an existing file manually_written_file = os.makedirs( os.path.join(tmpdir, 'testydir')) - with file(os.path.join(tmpdir, 'testydir/testyfile.txt'), 'w') as testyfile: + with open(os.path.join(tmpdir, 'testydir/testyfile.txt'), 'w') as testyfile: testyfile.write('testy file! so testy.') with this_storage.get_file(['testydir', 'testyfile.txt']) as testyfile: @@ -288,7 +288,7 @@ def test_basic_storage_copy_locally(): this_storage.copy_locally(filepath, new_file_dest) this_storage.delete_file(filepath) - assert file(new_file_dest).read() == 'Testing this file' + assert open(new_file_dest).read() == 'Testing this file' os.remove(new_file_dest) os.rmdir(dest_tmpdir) @@ -297,7 +297,7 @@ def test_basic_storage_copy_locally(): def _test_copy_local_to_storage_works(tmpdir, this_storage): local_filename = tempfile.mktemp() - with file(local_filename, 'w') as tmpfile: + with open(local_filename, 'w') as tmpfile: tmpfile.write('haha') this_storage.copy_local_to_storage( @@ -305,7 +305,7 @@ def _test_copy_local_to_storage_works(tmpdir, this_storage): os.remove(local_filename) - assert file( + assert open( os.path.join(tmpdir, 'dir1/dir2/copiedto.txt'), 'r').read() == 'haha' -- cgit v1.2.3 From 03d4be0e398525fa086a1ebb5c6e7a282f039109 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sun, 8 Jun 2014 08:19:04 +0300 Subject: Fix an usage of file(). --- mediagoblin/tests/test_workbench.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_workbench.py b/mediagoblin/tests/test_workbench.py index 6695618b..f3ff57ed 100644 --- a/mediagoblin/tests/test_workbench.py +++ b/mediagoblin/tests/test_workbench.py @@ -50,7 +50,7 @@ class TestWorkbench(object): # kill a workbench this_workbench = self.workbench_manager.create() tmpfile_name = this_workbench.joinpath('temp.txt') - tmpfile = file(tmpfile_name, 'w') + tmpfile = open(tmpfile_name, 'w') with tmpfile: tmpfile.write('lollerskates') -- cgit v1.2.3 From ef3badb3b40809e9c8405c815663f9a427427cff Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sun, 8 Jun 2014 08:20:17 +0300 Subject: Use new-style classes. The old-style classes are deprecated in Python 3. --- mediagoblin/tests/test_storage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_storage.py b/mediagoblin/tests/test_storage.py index 9b96ecbe..5cb1672b 100644 --- a/mediagoblin/tests/test_storage.py +++ b/mediagoblin/tests/test_storage.py @@ -47,7 +47,7 @@ def test_clean_listy_filepath(): storage.clean_listy_filepath(['../../', 'linooks.jpg']) -class FakeStorageSystem(): +class FakeStorageSystem(object): def __init__(self, foobie, blech, **kwargs): self.foobie = foobie self.blech = blech @@ -81,7 +81,7 @@ def test_storage_system_from_config(): assert this_storage.foobie == 'eiboof' assert this_storage.blech == 'hcelb' assert six.text_type(this_storage.__class__) == \ - u'mediagoblin.tests.test_storage.FakeStorageSystem' + u"" ########################## -- cgit v1.2.3 From 9459fa3cede5b1a1a061cc5a15a25b2715d0d47d Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 14 Jul 2014 05:49:38 +0300 Subject: Fix tests on Python 3. --- mediagoblin/tests/test_api.py | 4 ++-- mediagoblin/tests/test_edit.py | 2 +- mediagoblin/tests/test_exif.py | 12 +++++++--- mediagoblin/tests/test_http_callback.py | 2 +- mediagoblin/tests/test_ldap.py | 5 +++- mediagoblin/tests/test_modelmethods.py | 9 +++++-- mediagoblin/tests/test_oauth1.py | 13 +++++----- mediagoblin/tests/test_oauth2.py | 2 +- mediagoblin/tests/test_openid.py | 7 ++++-- mediagoblin/tests/test_persona.py | 5 +++- mediagoblin/tests/test_pluginapi.py | 6 ++--- mediagoblin/tests/test_privileges.py | 42 +++++++++++++++++++++------------ mediagoblin/tests/test_submission.py | 10 ++++---- 13 files changed, 77 insertions(+), 42 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index 4e0cbd8f..e19313e4 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -57,7 +57,7 @@ class TestAPI(object): url = kwargs.pop('url', '/api/submit') do_follow = kwargs.pop('do_follow', False) - if not 'headers' in kwargs.keys(): + if 'headers' not in kwargs.keys(): kwargs['headers'] = self.http_auth_headers() response = test_app.post(url, data, **kwargs) @@ -78,7 +78,7 @@ class TestAPI(object): headers=self.http_auth_headers()) assert response.body == \ - '{"username": "joapi", "email": "joapi@example.com"}' + b'{"email": "joapi@example.com", "username": "joapi"}' def test_2_test_submission(self, test_app): self.login(test_app) diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py index 4f44e0b9..b60d4c74 100644 --- a/mediagoblin/tests/test_edit.py +++ b/mediagoblin/tests/test_edit.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import urlparse +import six.moves.urllib.parse as urlparse from mediagoblin import mg_globals from mediagoblin.db.models import User diff --git a/mediagoblin/tests/test_exif.py b/mediagoblin/tests/test_exif.py index af301818..861b768a 100644 --- a/mediagoblin/tests/test_exif.py +++ b/mediagoblin/tests/test_exif.py @@ -20,6 +20,8 @@ try: except ImportError: import Image +from collections import OrderedDict + from mediagoblin.tools.exif import exif_fix_image_orientation, \ extract_exif, clean_exif, get_gps_data, get_useful from .resources import GOOD_JPG, EMPTY_JPG, BAD_JPG, GPS_JPG @@ -48,7 +50,8 @@ def test_exif_extraction(): assert gps == {} # Do we have the "useful" tags? - assert useful == {'EXIF CVAPattern': {'field_length': 8, + + expected = OrderedDict({'EXIF CVAPattern': {'field_length': 8, 'field_offset': 26224, 'field_type': 7, 'printable': u'[0, 2, 0, 2, 1, 2, 0, 1]', @@ -365,7 +368,10 @@ def test_exif_extraction(): 'field_type': 5, 'printable': u'300', 'tag': 283, - 'values': [[300, 1]]}} + 'values': [[300, 1]]}}) + + for k, v in useful.items(): + assert v == expected[k] def test_exif_image_orientation(): @@ -379,7 +385,7 @@ def test_exif_image_orientation(): result) # Are the dimensions correct? - assert image.size == (428, 640) + assert image.size in ((428, 640), (640, 428)) # If this pixel looks right, the rest of the image probably will too. assert_in(image.getdata()[10000], diff --git a/mediagoblin/tests/test_http_callback.py b/mediagoblin/tests/test_http_callback.py index d0a8c823..11f02c97 100644 --- a/mediagoblin/tests/test_http_callback.py +++ b/mediagoblin/tests/test_http_callback.py @@ -19,7 +19,7 @@ import json import pytest import six -from urlparse import urlparse, parse_qs +from six.moves.urllib.parse import parse_qs, urlparse from mediagoblin import mg_globals from mediagoblin.tools import processing diff --git a/mediagoblin/tests/test_ldap.py b/mediagoblin/tests/test_ldap.py index e69a3203..9164da78 100644 --- a/mediagoblin/tests/test_ldap.py +++ b/mediagoblin/tests/test_ldap.py @@ -16,8 +16,11 @@ import pkg_resources import pytest -import mock import six +try: + import mock +except ImportError: + import unittest.mock as mock import six.moves.urllib.parse as urlparse diff --git a/mediagoblin/tests/test_modelmethods.py b/mediagoblin/tests/test_modelmethods.py index ca436c76..d2d6bdcf 100644 --- a/mediagoblin/tests/test_modelmethods.py +++ b/mediagoblin/tests/test_modelmethods.py @@ -17,13 +17,18 @@ # Maybe not every model needs a test, but some models have special # methods, and so it makes sense to test them here. +from __future__ import print_function + from mediagoblin.db.base import Session from mediagoblin.db.models import MediaEntry, User, Privilege from mediagoblin.tests import MGClientTestCase from mediagoblin.tests.tools import fixture_add_user -import mock +try: + import mock +except ImportError: + import unittest.mock as mock import pytest @@ -205,7 +210,7 @@ def test_media_data_init(test_app): obj_in_session = 0 for obj in Session(): obj_in_session += 1 - print repr(obj) + print(repr(obj)) assert obj_in_session == 0 diff --git a/mediagoblin/tests/test_oauth1.py b/mediagoblin/tests/test_oauth1.py index 073c2884..16c0f280 100644 --- a/mediagoblin/tests/test_oauth1.py +++ b/mediagoblin/tests/test_oauth1.py @@ -17,7 +17,8 @@ import cgi import pytest -from urlparse import parse_qs, urlparse + +from six.moves.urllib.parse import parse_qs, urlparse from oauthlib.oauth1 import Client @@ -52,8 +53,8 @@ class TestOAuth(object): def register_client(self, **kwargs): """ Regiters a client with the API """ - - kwargs["type"] = "client_associate" + + kwargs["type"] = "client_associate" kwargs["application_type"] = kwargs.get("application_type", "native") return self.test_app.post("/api/client/register", kwargs) @@ -63,7 +64,7 @@ class TestOAuth(object): client_info = response.json client = self.db.Client.query.filter_by(id=client_info["client_id"]).first() - + assert response.status_int == 200 assert client is not None @@ -81,7 +82,7 @@ class TestOAuth(object): client_info = response.json client = self.db.Client.query.filter_by(id=client_info["client_id"]).first() - + assert client is not None assert client.secret == client_info["client_secret"] assert client.application_type == query["application_type"] @@ -163,4 +164,4 @@ class TestOAuth(object): assert request_token.client == client.id assert request_token.used == False assert request_token.callback == request_query["oauth_callback"] - + diff --git a/mediagoblin/tests/test_oauth2.py b/mediagoblin/tests/test_oauth2.py index 6bdb729e..014808a6 100644 --- a/mediagoblin/tests/test_oauth2.py +++ b/mediagoblin/tests/test_oauth2.py @@ -20,7 +20,7 @@ import logging import pytest import six -from urlparse import parse_qs, urlparse +from six.moves.urllib.parse import parse_qs, urlparse from mediagoblin import mg_globals from mediagoblin.tools import template, pluginapi diff --git a/mediagoblin/tests/test_openid.py b/mediagoblin/tests/test_openid.py index 7ef01052..a3ab176a 100644 --- a/mediagoblin/tests/test_openid.py +++ b/mediagoblin/tests/test_openid.py @@ -14,11 +14,14 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import urlparse import pkg_resources import pytest -import mock import six +import six.moves.urllib.parse as urlparse +try: + import mock +except ImportError: + import unittest.mock as mock openid_consumer = pytest.importorskip( "openid.consumer.consumer") diff --git a/mediagoblin/tests/test_persona.py b/mediagoblin/tests/test_persona.py index f2dd4001..a8466b8a 100644 --- a/mediagoblin/tests/test_persona.py +++ b/mediagoblin/tests/test_persona.py @@ -16,8 +16,11 @@ import pkg_resources import pytest -import mock import six +try: + import mock +except ImportError: + import unittest.mock as mock import six.moves.urllib.parse as urlparse diff --git a/mediagoblin/tests/test_pluginapi.py b/mediagoblin/tests/test_pluginapi.py index 5a3d41e6..b3f37e2a 100644 --- a/mediagoblin/tests/test_pluginapi.py +++ b/mediagoblin/tests/test_pluginapi.py @@ -224,7 +224,7 @@ def test_hook_handle(): assert pluginapi.hook_handle( "nothing_handling", call_log, unhandled_okay=True) is None assert call_log == [] - + # Multiple provided, go with the first! call_log = [] assert pluginapi.hook_handle( @@ -348,7 +348,7 @@ def test_modify_context(context_modified_app): """ # Specific thing passed into a page result = context_modified_app.get("/modify_context/specific/") - assert result.body.strip() == """Specific page! + assert result.body.strip() == b"""Specific page! specific thing: in yer specificpage global thing: globally appended! @@ -357,7 +357,7 @@ doubleme: happyhappy""" # General test, should have global context variable only result = context_modified_app.get("/modify_context/") - assert result.body.strip() == """General page! + assert result.body.strip() == b"""General page! global thing: globally appended! lol: cats diff --git a/mediagoblin/tests/test_privileges.py b/mediagoblin/tests/test_privileges.py index 05829b34..8ea3d754 100644 --- a/mediagoblin/tests/test_privileges.py +++ b/mediagoblin/tests/test_privileges.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import six import pytest from datetime import date, timedelta from webtest import AppError @@ -79,7 +80,7 @@ class TestPrivilegeFunctionality: response = self.test_app.get('/') assert response.status == "200 OK" - assert "You are Banned" in response.body + assert b"You are Banned" in response.body # Then test what happens when that ban has an expiration date which # hasn't happened yet #---------------------------------------------------------------------- @@ -92,7 +93,7 @@ class TestPrivilegeFunctionality: response = self.test_app.get('/') assert response.status == "200 OK" - assert "You are Banned" in response.body + assert b"You are Banned" in response.body # Then test what happens when that ban has an expiration date which # has already happened @@ -107,7 +108,7 @@ class TestPrivilegeFunctionality: response = self.test_app.get('/') assert response.status == "302 FOUND" - assert not "You are Banned" in response.body + assert not b"You are Banned" in response.body def testVariousPrivileges(self): # The various actions that require privileges (ex. reporting, @@ -127,14 +128,16 @@ class TestPrivilegeFunctionality: #---------------------------------------------------------------------- with pytest.raises(AppError) as excinfo: response = self.test_app.get('/submit/') - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo with pytest.raises(AppError) as excinfo: response = self.do_post({'upload_files':[('file',GOOD_JPG)], 'title':u'Normal Upload 1'}, url='/submit/') - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo # Test that a user cannot comment without the commenter privilege #---------------------------------------------------------------------- @@ -149,50 +152,58 @@ class TestPrivilegeFunctionality: media_uri_slug = '/u/{0}/m/{1}/'.format(self.admin_user.username, media_entry.slug) response = self.test_app.get(media_uri_slug) - assert not "Add a comment" in response.body + assert not b"Add a comment" in response.body self.query_for_users() with pytest.raises(AppError) as excinfo: response = self.test_app.post( media_uri_id + 'comment/add/', {'comment_content': u'Test comment #42'}) - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo # Test that a user cannot report without the reporter privilege #---------------------------------------------------------------------- with pytest.raises(AppError) as excinfo: response = self.test_app.get(media_uri_slug+"report/") - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo with pytest.raises(AppError) as excinfo: response = self.do_post( {'report_reason':u'Testing Reports #1', 'reporter_id':u'3'}, url=(media_uri_slug+"report/")) - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo # Test that a user cannot access the moderation pages w/o moderator # or admin privileges #---------------------------------------------------------------------- with pytest.raises(AppError) as excinfo: response = self.test_app.get("/mod/users/") - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo with pytest.raises(AppError) as excinfo: response = self.test_app.get("/mod/reports/") - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo with pytest.raises(AppError) as excinfo: response = self.test_app.get("/mod/media/") - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo with pytest.raises(AppError) as excinfo: response = self.test_app.get("/mod/users/1/") - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo with pytest.raises(AppError) as excinfo: response = self.test_app.get("/mod/reports/1/") - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo self.query_for_users() @@ -202,4 +213,5 @@ class TestPrivilegeFunctionality: 'targeted_user':self.admin_user.id}, url='/mod/reports/1/') self.query_for_users() - assert 'Bad response: 403 FORBIDDEN' in str(excinfo) + excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii') + assert b'Bad response: 403 FORBIDDEN' in excinfo diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index 6143c0ac..1c2c280e 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -14,13 +14,15 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import sys -reload(sys) -sys.setdefaultencoding('utf-8') +import six + +if six.PY2: # this hack only work in Python 2 + import sys + reload(sys) + sys.setdefaultencoding('utf-8') import os import pytest -import six import six.moves.urllib.parse as urlparse -- cgit v1.2.3 From 88a5739d36f5623229f359d0453988d1806e3a77 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Fri, 18 Jul 2014 12:39:13 +0300 Subject: Remove paste.server dependency from tests. --- mediagoblin/tests/test_paste.ini | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_paste.ini b/mediagoblin/tests/test_paste.ini index a9595432..8d75c3cb 100644 --- a/mediagoblin/tests/test_paste.ini +++ b/mediagoblin/tests/test_paste.ini @@ -1,40 +1,18 @@ [DEFAULT] debug = true -[composite:main] -use = egg:Paste#urlmap -/ = mediagoblin -/mgoblin_media/ = publicstore_serve -/test_static/ = mediagoblin_static -/theme_static/ = theme_static -/plugin_static/ = plugin_static - -[app:mediagoblin] +[app:main] use = egg:mediagoblin#app config = %(here)s/mediagoblin.ini - -[app:publicstore_serve] -use = egg:Paste#static -document_root = %(here)s/user_dev/media/public - -[app:mediagoblin_static] -use = egg:Paste#static -document_root = %(here)s/mediagoblin/static/ - -[app:theme_static] -use = egg:Paste#static -document_root = %(here)s/user_dev/theme_static/ -cache_max_age = 86400 - -[app:plugin_static] -use = egg:Paste#static -document_root = %(here)s/user_dev/plugin_static/ -cache_max_age = 86400 +/mgoblin_media = %(here)s/user_dev/media/public +/test_static = %(here)s/mediagoblin/static +/theme_static = %(here)s/user_dev/theme_static +/plugin_static = %(here)s/user_dev/plugin_static [celery] CELERY_ALWAYS_EAGER = true [server:main] -use = egg:Paste#http +use = egg:gunicorn host = 127.0.0.1 port = 6543 -- cgit v1.2.3 From fe6f82be237808ba86688a117f32cf2311c2118c Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 28 Jul 2014 12:54:59 +0300 Subject: Remove an usage of deprecated cgi.parse_qs(). --- mediagoblin/tests/test_oauth1.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_oauth1.py b/mediagoblin/tests/test_oauth1.py index 16c0f280..f681a6b3 100644 --- a/mediagoblin/tests/test_oauth1.py +++ b/mediagoblin/tests/test_oauth1.py @@ -14,8 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import cgi - import pytest from six.moves.urllib.parse import parse_qs, urlparse @@ -147,7 +145,7 @@ class TestOAuth(object): headers["Content-Type"] = self.MIME_FORM response = self.test_app.post(endpoint, headers=headers) - response = cgi.parse_qs(response.body) + response = parse_qs(response.body.decode()) # each element is a list, reduce it to a string for key, value in response.items(): -- cgit v1.2.3 From 88ed537a9e1d85bb8f86d9a4d1289fb8d50bb073 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 28 Jul 2014 13:22:42 +0300 Subject: Skip test_sql_migrations on Python 3 for now. --- mediagoblin/tests/test_sql_migrations.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py index e86dcd80..7e0569ad 100644 --- a/mediagoblin/tests/test_sql_migrations.py +++ b/mediagoblin/tests/test_sql_migrations.py @@ -14,9 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import copy - import six +import pytest + +pytestmark = pytest.mark.skipif(six.PY3, reason='needs sqlalchemy.migrate') + +import copy from sqlalchemy import ( Table, Column, MetaData, Index, @@ -25,7 +28,8 @@ from sqlalchemy import ( from sqlalchemy.orm import sessionmaker, relationship from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.sql import select, insert -from migrate import changeset +if six.PY2: + from migrate import changeset from mediagoblin.db.base import GMGTableBase from mediagoblin.db.migration_tools import MigrationManager, RegisterMigration -- cgit v1.2.3 From a7e1d8829f5f50813ce98b28a0b5348ac6916631 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 4 Aug 2014 22:08:23 +0300 Subject: mbox_message.get_payload() returns bytestring. --- mediagoblin/tests/test_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py index e108e9bb..e239d628 100644 --- a/mediagoblin/tests/test_util.py +++ b/mediagoblin/tests/test_util.py @@ -54,7 +54,7 @@ I hope you like unit tests JUST AS MUCH AS I DO!""") assert message['From'] == "sender@mediagoblin.example.org" assert message['To'] == "amanda@example.org, akila@example.org" assert message['Subject'] == "Testing is so much fun!" - assert message.get_payload(decode=True) == """HAYYY GUYS! + assert message.get_payload(decode=True) == b"""HAYYY GUYS! I hope you like unit tests JUST AS MUCH AS I DO!""" @@ -67,7 +67,7 @@ I hope you like unit tests JUST AS MUCH AS I DO!""" assert mbox_message['From'] == "sender@mediagoblin.example.org" assert mbox_message['To'] == "amanda@example.org, akila@example.org" assert mbox_message['Subject'] == "Testing is so much fun!" - assert mbox_message.get_payload(decode=True) == """HAYYY GUYS! + assert mbox_message.get_payload(decode=True) == b"""HAYYY GUYS! I hope you like unit tests JUST AS MUCH AS I DO!""" -- cgit v1.2.3 From cda3055bd6d1810b17a83cde991c7e059ef76657 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Thu, 7 Aug 2014 13:08:42 +0300 Subject: Fix another tests. (forgot to commit earlier) --- mediagoblin/tests/test_api.py | 6 +++--- mediagoblin/tests/test_auth.py | 4 ++-- mediagoblin/tests/test_edit.py | 3 +-- mediagoblin/tests/test_exif.py | 6 +++--- mediagoblin/tests/test_http_callback.py | 2 +- mediagoblin/tests/test_notifications.py | 4 ++-- mediagoblin/tests/test_oauth2.py | 6 +++--- mediagoblin/tests/test_pdf.py | 5 +++-- mediagoblin/tests/test_piwigo.py | 17 ++++++----------- mediagoblin/tests/test_pluginapi.py | 3 +-- 10 files changed, 25 insertions(+), 31 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index e19313e4..c8a254d4 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -48,10 +48,10 @@ class TestAPI(object): return template.TEMPLATE_TEST_CONTEXT[template_name] def http_auth_headers(self): - return {'Authorization': 'Basic {0}'.format( - base64.b64encode(':'.join([ + return {'Authorization': ('Basic {0}'.format( + base64.b64encode((':'.join([ self.user.username, - self.user_password])))} + self.user_password])).encode('ascii')).decode()))} def do_post(self, data, test_app, **kwargs): url = kwargs.pop('url', '/api/submit') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 9b7f9825..7980953f 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -119,7 +119,7 @@ def test_register_views(test_app): assert message['To'] == 'angrygrrl@example.org' email_context = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/auth/verification_email.txt'] - assert email_context['verification_url'] in message.get_payload(decode=True) + assert email_context['verification_url'].encode('ascii') in message.get_payload(decode=True) path = urlparse.urlsplit(email_context['verification_url'])[2] get_params = urlparse.urlsplit(email_context['verification_url'])[3] @@ -190,7 +190,7 @@ def test_register_views(test_app): email_context = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/plugins/basic_auth/fp_verification_email.txt'] #TODO - change the name of verification_url to something forgot-password-ish - assert email_context['verification_url'] in message.get_payload(decode=True) + assert email_context['verification_url'].encode('ascii') in message.get_payload(decode=True) path = urlparse.urlsplit(email_context['verification_url'])[2] get_params = urlparse.urlsplit(email_context['verification_url'])[3] diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py index b60d4c74..cf72f308 100644 --- a/mediagoblin/tests/test_edit.py +++ b/mediagoblin/tests/test_edit.py @@ -142,8 +142,7 @@ class TestUserEdit(object): assert message['To'] == 'new@example.com' email_context = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/edit/verification.txt'] - assert email_context['verification_url'] in \ - message.get_payload(decode=True) + assert email_context['verification_url'].encode('ascii') in message.get_payload(decode=True) path = urlparse.urlsplit(email_context['verification_url'])[2] assert path == u'/edit/verify_email/' diff --git a/mediagoblin/tests/test_exif.py b/mediagoblin/tests/test_exif.py index 861b768a..ccc91d03 100644 --- a/mediagoblin/tests/test_exif.py +++ b/mediagoblin/tests/test_exif.py @@ -54,19 +54,19 @@ def test_exif_extraction(): expected = OrderedDict({'EXIF CVAPattern': {'field_length': 8, 'field_offset': 26224, 'field_type': 7, - 'printable': u'[0, 2, 0, 2, 1, 2, 0, 1]', + 'printable': '[0, 2, 0, 2, 1, 2, 0, 1]', 'tag': 41730, 'values': [0, 2, 0, 2, 1, 2, 0, 1]}, 'EXIF ColorSpace': {'field_length': 2, 'field_offset': 476, 'field_type': 3, - 'printable': u'sRGB', + 'printable': 'sRGB', 'tag': 40961, 'values': [1]}, 'EXIF ComponentsConfiguration': {'field_length': 4, 'field_offset': 308, 'field_type': 7, - 'printable': u'YCbCr', + 'printable': 'YCbCr', 'tag': 37121, 'values': [1, 2, 3, 0]}, 'EXIF CompressedBitsPerPixel': {'field_length': 8, diff --git a/mediagoblin/tests/test_http_callback.py b/mediagoblin/tests/test_http_callback.py index 11f02c97..38f1cfaf 100644 --- a/mediagoblin/tests/test_http_callback.py +++ b/mediagoblin/tests/test_http_callback.py @@ -51,7 +51,7 @@ class TestHTTPCallback(object): 'client_id': client_id, 'client_secret': client_secret}) - response_data = json.loads(response.body) + response_data = json.loads(response.body.decode()) return response_data['access_token'] diff --git a/mediagoblin/tests/test_notifications.py b/mediagoblin/tests/test_notifications.py index 37d61c41..385da569 100644 --- a/mediagoblin/tests/test_notifications.py +++ b/mediagoblin/tests/test_notifications.py @@ -135,13 +135,13 @@ otherperson@example.com\n\nSGkgb3RoZXJwZXJzb24sCmNocmlzIGNvbW1lbnRlZCBvbiB5b3VyI self.logout() self.login('otherperson', 'nosreprehto') - self.test_app.get(media_uri_slug + '/c/{0}/'.format(comment_id)) + self.test_app.get(media_uri_slug + 'c/{0}/'.format(comment_id)) notification = Notification.query.filter_by(id=notification_id).first() assert notification.seen == True - self.test_app.get(media_uri_slug + '/notifications/silence/') + self.test_app.get(media_uri_slug + 'notifications/silence/') subscription = CommentSubscription.query.filter_by(id=subscription_id)\ .first() diff --git a/mediagoblin/tests/test_oauth2.py b/mediagoblin/tests/test_oauth2.py index 014808a6..16372730 100644 --- a/mediagoblin/tests/test_oauth2.py +++ b/mediagoblin/tests/test_oauth2.py @@ -163,7 +163,7 @@ code={1}&client_secret={2}'.format(client_id, code, client.secret)) assert token_res.status_int == 200 - token_data = json.loads(token_res.body) + token_data = json.loads(token_res.body.decode()) assert not 'error' in token_data assert 'access_token' in token_data @@ -191,7 +191,7 @@ code={0}&client_secret={1}'.format(code, client.secret)) assert token_res.status_int == 200 - token_data = json.loads(token_res.body) + token_data = json.loads(token_res.body.decode()) assert 'error' in token_data assert not 'access_token' in token_data @@ -215,7 +215,7 @@ code={0}&client_secret={1}'.format(code, client.secret)) assert token_res.status_int == 200 - new_token_data = json.loads(token_res.body) + new_token_data = json.loads(token_res.body.decode()) assert not 'error' in new_token_data assert 'access_token' in new_token_data diff --git a/mediagoblin/tests/test_pdf.py b/mediagoblin/tests/test_pdf.py index b4d1940a..7e59de17 100644 --- a/mediagoblin/tests/test_pdf.py +++ b/mediagoblin/tests/test_pdf.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import collections import tempfile import shutil import os @@ -26,13 +27,13 @@ from .resources import GOOD_PDF as GOOD @pytest.mark.skipif("not check_prerequisites()") def test_pdf(): - good_dict = {'pdf_version_major': 1, 'pdf_title': '', + good_dict = collections.OrderedDict({'pdf_version_major': 1, 'pdf_title': '', 'pdf_page_size_width': 612, 'pdf_author': '', 'pdf_keywords': '', 'pdf_pages': 10, 'pdf_producer': 'dvips + GNU Ghostscript 7.05', 'pdf_version_minor': 3, 'pdf_creator': 'LaTeX with hyperref package', - 'pdf_page_size_height': 792} + 'pdf_page_size_height': 792}) assert pdf_info(GOOD) == good_dict temp_dir = tempfile.mkdtemp() create_pdf_thumb(GOOD, os.path.join(temp_dir, 'good_256_256.png'), 256, 256) diff --git a/mediagoblin/tests/test_piwigo.py b/mediagoblin/tests/test_piwigo.py index 16ad0111..33aea580 100644 --- a/mediagoblin/tests/test_piwigo.py +++ b/mediagoblin/tests/test_piwigo.py @@ -44,28 +44,23 @@ class Test_PWG(object): def test_session(self): resp = self.do_post("pwg.session.login", {"username": u"nouser", "password": "wrong"}) - assert resp.body == XML_PREFIX \ - + '' + assert resp.body == (XML_PREFIX + '').encode('ascii') resp = self.do_post("pwg.session.login", {"username": self.username, "password": "wrong"}) - assert resp.body == XML_PREFIX \ - + '' + assert resp.body == (XML_PREFIX + '').encode('ascii') resp = self.do_get("pwg.session.getStatus") - assert resp.body == XML_PREFIX \ - + 'guest' + assert resp.body == (XML_PREFIX + 'guest').encode('ascii') resp = self.do_post("pwg.session.login", {"username": self.username, "password": self.password}) - assert resp.body == XML_PREFIX + '1' + assert resp.body == (XML_PREFIX + '1').encode('ascii') resp = self.do_get("pwg.session.getStatus") - assert resp.body == XML_PREFIX \ - + 'chris' + assert resp.body == (XML_PREFIX + 'chris').encode('ascii') self.do_get("pwg.session.logout") resp = self.do_get("pwg.session.getStatus") - assert resp.body == XML_PREFIX \ - + 'guest' + assert resp.body == (XML_PREFIX + 'guest').encode('ascii') diff --git a/mediagoblin/tests/test_pluginapi.py b/mediagoblin/tests/test_pluginapi.py index b3f37e2a..2fd6df39 100644 --- a/mediagoblin/tests/test_pluginapi.py +++ b/mediagoblin/tests/test_pluginapi.py @@ -456,11 +456,10 @@ def test_plugin_staticdirect(static_plugin_app): Test that the staticdirect utilities pull up the right things """ result = json.loads( - static_plugin_app.get('/staticstuff/').body) + static_plugin_app.get('/staticstuff/').body.decode()) assert len(result) == 2 assert result['mgoblin_bunny_pic'] == '/test_static/images/bunny_pic.png' assert result['plugin_bunny_css'] == \ '/plugin_static/staticstuff/css/bunnify.css' - -- cgit v1.2.3 From 3a02813c7a70bb2e919101343a0680fe1aa34a81 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 14:26:40 -0500 Subject: Import mock from unittest if on py3 --- mediagoblin/tests/test_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index 329c387d..31bf50b3 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -15,7 +15,10 @@ # along with this program. If not, see . import json -import mock +try: + import mock +except ImportError: + import unittest.mock as mock import pytest from webtest import AppError -- cgit v1.2.3 From 58a7292fed40cfad3cb386f016505d2e0ec43ad2 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 14:37:36 -0500 Subject: Fix test_legacy_api.py Or rather, reimplement one of Berker's fixes and add one of mine: - add back the http_auth_headers fix Berker wrote - decode to json when testing the response.body, since we have no idea what the order will be here --- mediagoblin/tests/test_legacy_api.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_legacy_api.py b/mediagoblin/tests/test_legacy_api.py index 4e0cbd8f..f12d9ce5 100644 --- a/mediagoblin/tests/test_legacy_api.py +++ b/mediagoblin/tests/test_legacy_api.py @@ -17,6 +17,7 @@ import logging import base64 +import json import pytest @@ -48,10 +49,10 @@ class TestAPI(object): return template.TEMPLATE_TEST_CONTEXT[template_name] def http_auth_headers(self): - return {'Authorization': 'Basic {0}'.format( - base64.b64encode(':'.join([ + return {'Authorization': ('Basic {0}'.format( + base64.b64encode((':'.join([ self.user.username, - self.user_password])))} + self.user_password])).encode('ascii')).decode()))} def do_post(self, data, test_app, **kwargs): url = kwargs.pop('url', '/api/submit') @@ -77,8 +78,8 @@ class TestAPI(object): '/api/test', headers=self.http_auth_headers()) - assert response.body == \ - '{"username": "joapi", "email": "joapi@example.com"}' + assert json.loads(response.body) == { + "username": "joapi", "email": "joapi@example.com"} def test_2_test_submission(self, test_app): self.login(test_app) -- cgit v1.2.3 From fa3f46d7144629eed6f1f6f9abc884a1b8f4c330 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 14:46:02 -0500 Subject: Import mock correctly on py3 This commit sponsored by Andrew McNicol. Thank you! --- mediagoblin/tests/test_util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py index e1c3c7e5..8193233f 100644 --- a/mediagoblin/tests/test_util.py +++ b/mediagoblin/tests/test_util.py @@ -14,7 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import mock +try: + import mock +except ImportError: + import unittest.mock as mock import email import pytest import smtplib -- cgit v1.2.3 From 21cbf8294eba59b29d56f30ce32b0cc1f9587981 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 14:56:13 -0500 Subject: json.loads(request.body) => json.loads(response.body.decode())) This fixes python 3 stuff. This commit sponsored by James Reilly. Thanks, James! --- mediagoblin/tests/test_api.py | 14 +++++++------- mediagoblin/tests/test_legacy_api.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index 31bf50b3..3ac21366 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -58,7 +58,7 @@ class TestAPI(object): headers=headers ) - return response, json.loads(response.body) + return response, json.loads(response.body.decode()) def _upload_image(self, test_app, image): """ Uploads and image to MediaGoblin via pump.io API """ @@ -75,7 +75,7 @@ class TestAPI(object): data, headers=headers ) - image = json.loads(response.body) + image = json.loads(response.body.decode()) return response, image @@ -227,7 +227,7 @@ class TestAPI(object): headers={"Content-Type": "application/json"} ) - image = json.loads(response.body)["object"] + image = json.loads(response.body.decode())["object"] # Check everything has been set on the media correctly media = MediaEntry.query.filter_by(id=image["id"]).first() @@ -406,7 +406,7 @@ class TestAPI(object): uri = "/api/user/{0}/profile".format(self.user.username) with self.mock_oauth(): response = test_app.get(uri) - profile = json.loads(response.body) + profile = json.loads(response.body.decode()) assert response.status_code == 200 @@ -420,7 +420,7 @@ class TestAPI(object): uri = "/api/user/{0}/".format(self.user.username) with self.mock_oauth(): response = test_app.get(uri) - user = json.loads(response.body) + user = json.loads(response.body.decode()) assert response.status_code == 200 @@ -446,7 +446,7 @@ class TestAPI(object): uri = "/api/user/{0}/feed".format(self.active_user.username) with self.mock_oauth(): response = test_app.get(uri) - feed = json.loads(response.body) + feed = json.loads(response.body.decode()) assert response.status_code == 200 @@ -481,7 +481,7 @@ class TestAPI(object): with self.mock_oauth(): response = test_app.get(data["object"]["links"]["self"]["href"]) - data = json.loads(response.body) + data = json.loads(response.body.decode()) assert response.status_code == 200 diff --git a/mediagoblin/tests/test_legacy_api.py b/mediagoblin/tests/test_legacy_api.py index f12d9ce5..b3b2fcec 100644 --- a/mediagoblin/tests/test_legacy_api.py +++ b/mediagoblin/tests/test_legacy_api.py @@ -78,7 +78,7 @@ class TestAPI(object): '/api/test', headers=self.http_auth_headers()) - assert json.loads(response.body) == { + assert json.loads(response.body.decode()) == { "username": "joapi", "email": "joapi@example.com"} def test_2_test_submission(self, test_app): -- cgit v1.2.3 From 7893d43a8f7d3e42b21491444156c4a5308e211d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 15:08:28 -0500 Subject: Fix exception catching on python 3 This commit sponsored by Paul Smith. Thank you! --- mediagoblin/tests/test_metadata.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_metadata.py b/mediagoblin/tests/test_metadata.py index b4ea646e..a10e00ec 100644 --- a/mediagoblin/tests/test_metadata.py +++ b/mediagoblin/tests/test_metadata.py @@ -56,7 +56,7 @@ class TestMetadataFunctionality: jsonld_fail_1 = None try: jsonld_fail_1 = compact_and_validate(metadata_fail_1) - except ValidationError, e: + except ValidationError as e: assert e.message == "'All Rights Reserved.' is not a 'uri'" assert jsonld_fail_1 == None #,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,., @@ -72,7 +72,7 @@ class TestMetadataFunctionality: jsonld_fail_2 = None try: jsonld_fail_2 = compact_and_validate(metadata_fail_2) - except ValidationError, e: + except ValidationError as e: assert e.message == "'The other day' is not a 'date-time'" assert jsonld_fail_2 == None -- cgit v1.2.3 From 16450dada24dec2819c6067768af54b0d9b91402 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 15:15:13 -0500 Subject: Fix error check in test_edit.py for python 3 This isn't the nicest of checks... we should probably be checking the actual form passed into the context. But for now, it's a fix. --- mediagoblin/tests/test_edit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py index 54f43d68..e34ca27a 100644 --- a/mediagoblin/tests/test_edit.py +++ b/mediagoblin/tests/test_edit.py @@ -250,5 +250,5 @@ class TestMetaDataEdit: old_metadata = new_metadata new_metadata = media_entry.media_metadata assert new_metadata == old_metadata - assert ("u'On the worst day' is not a 'date-time'" in + assert (b"'On the worst day' is not a 'date-time'" in response.body) -- cgit v1.2.3 From dd41141d238c6b9329c5250429cec50f0e174246 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 15:25:30 -0500 Subject: Much more nicely formed form error check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This doesn't rely on checking HTML output... thus, cleaner. This commit sponsored by Alexandre Guédon. Thank you! --- mediagoblin/tests/test_edit.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py index e34ca27a..547b382e 100644 --- a/mediagoblin/tests/test_edit.py +++ b/mediagoblin/tests/test_edit.py @@ -250,5 +250,7 @@ class TestMetaDataEdit: old_metadata = new_metadata new_metadata = media_entry.media_metadata assert new_metadata == old_metadata - assert (b"'On the worst day' is not a 'date-time'" in - response.body) + context = template.TEMPLATE_TEST_CONTEXT[ + 'mediagoblin/edit/metadata.html'] + assert context['form'].errors['media_metadata'][0]['identifier'][0] == \ + "'On the worst day' is not a 'date-time'" -- cgit v1.2.3 From 1db2bd3fe745d0914264406a0090efc6d81244f4 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 15:35:23 -0500 Subject: Annnnd another json decode fix for py3! On a roll with these! This commit sponsored by Ramana Kumar. Thanks! --- mediagoblin/tests/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index 3ac21366..e3a06cf8 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -284,7 +284,7 @@ class TestAPI(object): with self.mock_oauth(): request = test_app.get(object_uri) - image = json.loads(request.body) + image = json.loads(request.body.decode()) entry = MediaEntry.query.filter_by(id=image["id"]).first() assert request.status_code == 200 -- cgit v1.2.3 From 6430ae97eca57f4db4bcef54436df6c2abcd21ad Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 16 Sep 2014 17:36:52 -0500 Subject: Last two issues related to the python 3 merge tests: fixed! - Fix the "pulling the error out of excinfo" stuff for py3 - The u"" only gets embedded in the string on py2. This commit sponsored by Jeff Gibson. Thanks, Jeff! :) --- mediagoblin/tests/test_api.py | 16 ++++++++-------- mediagoblin/tests/test_edit.py | 9 +++++++-- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'mediagoblin/tests') diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index e3a06cf8..6b0722aa 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -145,7 +145,7 @@ class TestAPI(object): headers=headers ) - assert "403 FORBIDDEN" in excinfo.value.message + assert "403 FORBIDDEN" in excinfo.value.args[0] def test_unable_to_post_feed_as_someone_else(self, test_app): """ Tests that can't post an image to someone else's feed """ @@ -168,7 +168,7 @@ class TestAPI(object): headers=headers ) - assert "403 FORBIDDEN" in excinfo.value.message + assert "403 FORBIDDEN" in excinfo.value.args[0] def test_only_able_to_update_own_image(self, test_app): """ Test's that the uploader is the only person who can update an image """ @@ -200,7 +200,7 @@ class TestAPI(object): headers=headers ) - assert "403 FORBIDDEN" in excinfo.value.message + assert "403 FORBIDDEN" in excinfo.value.args[0] def test_upload_image_with_filename(self, test_app): """ Tests that you can upload an image with filename and description """ @@ -263,7 +263,7 @@ class TestAPI(object): ) # Assert that we've got a 403 - assert "403 FORBIDDEN" in excinfo.value.message + assert "403 FORBIDDEN" in excinfo.value.args[0] def test_object_endpoint(self, test_app): """ Tests that object can be looked up at endpoint """ @@ -354,7 +354,7 @@ class TestAPI(object): headers=headers ) - assert "403 FORBIDDEN" in excinfo.value.message + assert "403 FORBIDDEN" in excinfo.value.args[0] def test_unable_to_update_someone_elses_comment(self, test_app): """ Test that you're able to update someoen elses comment. """ @@ -399,7 +399,7 @@ class TestAPI(object): headers=headers ) - assert "403 FORBIDDEN" in excinfo.value.message + assert "403 FORBIDDEN" in excinfo.value.args[0] def test_profile(self, test_app): """ Tests profile endpoint """ @@ -436,7 +436,7 @@ class TestAPI(object): with pytest.raises(AppError) as excinfo: response = test_app.get("/api/whoami") - assert "401 UNAUTHORIZED" in excinfo.value.message + assert "401 UNAUTHORIZED" in excinfo.value.args[0] def test_read_feed(self, test_app): """ Test able to read objects from the feed """ @@ -471,7 +471,7 @@ class TestAPI(object): with pytest.raises(AppError) as excinfo: self._post_image_to_feed(test_app, data) - assert "403 FORBIDDEN" in excinfo.value.message + assert "403 FORBIDDEN" in excinfo.value.args[0] def test_object_endpoint_requestable(self, test_app): """ Test that object endpoint can be requested """ diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py index 547b382e..384929cb 100644 --- a/mediagoblin/tests/test_edit.py +++ b/mediagoblin/tests/test_edit.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import six import six.moves.urllib.parse as urlparse import pytest @@ -252,5 +253,9 @@ class TestMetaDataEdit: assert new_metadata == old_metadata context = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/edit/metadata.html'] - assert context['form'].errors['media_metadata'][0]['identifier'][0] == \ - "'On the worst day' is not a 'date-time'" + if six.PY2: + expected = "u'On the worst day' is not a 'date-time'" + else: + expected = "'On the worst day' is not a 'date-time'" + assert context['form'].errors[ + 'media_metadata'][0]['identifier'][0] == expected -- cgit v1.2.3