aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests
diff options
context:
space:
mode:
authorBen Sturmfels <ben@sturm.com.au>2021-03-05 23:12:19 +1100
committerBen Sturmfels <ben@sturm.com.au>2021-03-05 23:12:19 +1100
commitdec47c7102cf0aa3a4debf002928db8e460c0d71 (patch)
tree47631fc15c7af172aa699506adf3d76d3a71976c /mediagoblin/tests
parent5f3a782fef4855e10b7259624a14d8afb0f7be93 (diff)
downloadmediagoblin-dec47c7102cf0aa3a4debf002928db8e460c0d71.tar.lz
mediagoblin-dec47c7102cf0aa3a4debf002928db8e460c0d71.tar.xz
mediagoblin-dec47c7102cf0aa3a4debf002928db8e460c0d71.zip
Apply `pyupgrade --py3-plus` to remove Python 2 compatibility code.
Diffstat (limited to 'mediagoblin/tests')
-rw-r--r--mediagoblin/tests/test_api.py38
-rw-r--r--mediagoblin/tests/test_auth.py86
-rw-r--r--mediagoblin/tests/test_basic_auth.py12
-rw-r--r--mediagoblin/tests/test_config.py3
-rw-r--r--mediagoblin/tests/test_edit.py50
-rw-r--r--mediagoblin/tests/test_exif.py120
-rw-r--r--mediagoblin/tests/test_globals.py2
-rw-r--r--mediagoblin/tests/test_ldap.py36
-rw-r--r--mediagoblin/tests/test_legacy_api.py12
-rw-r--r--mediagoblin/tests/test_metadata.py2
-rw-r--r--mediagoblin/tests/test_misc.py14
-rw-r--r--mediagoblin/tests/test_modelmethods.py99
-rw-r--r--mediagoblin/tests/test_moderation.py90
-rw-r--r--mediagoblin/tests/test_notifications.py32
-rw-r--r--mediagoblin/tests/test_oauth1.py4
-rw-r--r--mediagoblin/tests/test_openid.py62
-rw-r--r--mediagoblin/tests/test_persona.py36
-rw-r--r--mediagoblin/tests/test_piwigo.py6
-rw-r--r--mediagoblin/tests/test_pluginapi.py10
-rw-r--r--mediagoblin/tests/test_privileges.py46
-rw-r--r--mediagoblin/tests/test_processing.py6
-rw-r--r--mediagoblin/tests/test_reporting.py54
-rw-r--r--mediagoblin/tests/test_response.py5
-rw-r--r--mediagoblin/tests/test_sql_migrations.py266
-rw-r--r--mediagoblin/tests/test_storage.py21
-rw-r--r--mediagoblin/tests/test_submission.py134
-rw-r--r--mediagoblin/tests/test_subtitles.py12
-rw-r--r--mediagoblin/tests/test_tags.py20
-rw-r--r--mediagoblin/tests/test_tools.py7
-rw-r--r--mediagoblin/tests/test_util.py38
-rw-r--r--mediagoblin/tests/test_workbench.py2
-rw-r--r--mediagoblin/tests/tools.py18
32 files changed, 669 insertions, 674 deletions
diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py
index f4741fd1..23548f23 100644
--- a/mediagoblin/tests/test_api.py
+++ b/mediagoblin/tests/test_api.py
@@ -16,7 +16,7 @@
import json
try:
- import mock
+ from unittest import mock
except ImportError:
import unittest.mock as mock
import pytest
@@ -30,7 +30,7 @@ from mediagoblin.tests.tools import fixture_add_user
from mediagoblin.moderation.tools import take_away_privileges
-class TestAPI(object):
+class TestAPI:
""" Test mediagoblin's pump.io complient APIs """
@pytest.fixture(autouse=True)
@@ -38,11 +38,11 @@ class TestAPI(object):
self.test_app = test_app
self.db = mg_globals.database
- self.user = fixture_add_user(privileges=[u'active', u'uploader',
- u'commenter'])
+ self.user = fixture_add_user(privileges=['active', 'uploader',
+ 'commenter'])
self.other_user = fixture_add_user(
username="otheruser",
- privileges=[u'active', u'uploader', u'commenter']
+ privileges=['active', 'uploader', 'commenter']
)
self.active_user = self.user
@@ -55,7 +55,7 @@ class TestAPI(object):
with self.mock_oauth():
response = test_app.post(
- "/api/user/{0}/feed".format(self.active_user.username),
+ "/api/user/{}/feed".format(self.active_user.username),
json.dumps(activity),
headers=headers
)
@@ -75,7 +75,7 @@ class TestAPI(object):
with self.mock_oauth():
response = test_app.post(
- "/api/user/{0}/uploads".format(self.active_user.username),
+ "/api/user/{}/uploads".format(self.active_user.username),
data,
headers=headers
)
@@ -183,7 +183,7 @@ class TestAPI(object):
# Will be self.user trying to upload as self.other_user
with pytest.raises(AppError) as excinfo:
test_app.post(
- "/api/user/{0}/uploads".format(self.other_user.username),
+ "/api/user/{}/uploads".format(self.other_user.username),
data,
headers=headers
)
@@ -206,7 +206,7 @@ class TestAPI(object):
with self.mock_oauth():
with pytest.raises(AppError) as excinfo:
test_app.post(
- "/api/user/{0}/feed".format(self.other_user.username),
+ "/api/user/{}/feed".format(self.other_user.username),
json.dumps(activity),
headers=headers
)
@@ -241,7 +241,7 @@ class TestAPI(object):
with self.mock_oauth():
with pytest.raises(AppError) as excinfo:
test_app.post(
- "/api/user/{0}/feed".format(self.user.username),
+ "/api/user/{}/feed".format(self.user.username),
json.dumps(activity),
headers=headers
)
@@ -268,7 +268,7 @@ class TestAPI(object):
with self.mock_oauth():
response = test_app.post(
- "/api/user/{0}/feed".format(self.user.username),
+ "/api/user/{}/feed".format(self.user.username),
json.dumps(activity),
headers={"Content-Type": "application/json"}
)
@@ -290,7 +290,7 @@ class TestAPI(object):
def test_only_uploaders_post_image(self, test_app):
""" Test that only uploaders can upload images """
# Remove uploader permissions from user
- take_away_privileges(self.user.username, u"uploader")
+ take_away_privileges(self.user.username, "uploader")
# Now try and upload a image
data = open(GOOD_JPG, "rb").read()
@@ -302,7 +302,7 @@ class TestAPI(object):
with self.mock_oauth():
with pytest.raises(AppError) as excinfo:
test_app.post(
- "/api/user/{0}/uploads".format(self.user.username),
+ "/api/user/{}/uploads".format(self.user.username),
data,
headers=headers
)
@@ -397,7 +397,7 @@ class TestAPI(object):
with self.mock_oauth():
with pytest.raises(AppError) as excinfo:
test_app.post(
- "/api/user/{0}/feed".format(self.other_user.username),
+ "/api/user/{}/feed".format(self.other_user.username),
json.dumps(activity),
headers=headers
)
@@ -443,7 +443,7 @@ class TestAPI(object):
with self.mock_oauth():
with pytest.raises(AppError) as excinfo:
test_app.post(
- "/api/user/{0}/feed".format(self.user.username),
+ "/api/user/{}/feed".format(self.user.username),
json.dumps(activity),
headers=headers
)
@@ -452,7 +452,7 @@ class TestAPI(object):
def test_profile(self, test_app):
""" Tests profile endpoint """
- uri = "/api/user/{0}/profile".format(self.user.username)
+ uri = "/api/user/{}/profile".format(self.user.username)
with self.mock_oauth():
response = test_app.get(uri)
profile = json.loads(response.body.decode())
@@ -466,7 +466,7 @@ class TestAPI(object):
def test_user(self, test_app):
""" Test the user endpoint """
- uri = "/api/user/{0}/".format(self.user.username)
+ uri = "/api/user/{}/".format(self.user.username)
with self.mock_oauth():
response = test_app.get(uri)
user = json.loads(response.body.decode())
@@ -492,7 +492,7 @@ class TestAPI(object):
response, image_data = self._upload_image(test_app, GOOD_JPG)
response, data = self._post_image_to_feed(test_app, image_data)
- uri = "/api/user/{0}/feed".format(self.active_user.username)
+ uri = "/api/user/{}/feed".format(self.active_user.username)
with self.mock_oauth():
response = test_app.get(uri)
feed = json.loads(response.body.decode())
@@ -565,7 +565,7 @@ class TestAPI(object):
self.active_user = self.other_user
# Fetch the feed
- url = "/api/user/{0}/feed".format(self.user.username)
+ url = "/api/user/{}/feed".format(self.user.username)
with self.mock_oauth():
response = test_app.get(url)
feed = json.loads(response.body.decode())
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py
index 9cf5ccb0..dafaa1e7 100644
--- a/mediagoblin/tests/test_auth.py
+++ b/mediagoblin/tests/test_auth.py
@@ -47,9 +47,9 @@ def test_register_views(test_app):
'/auth/register/', {})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
form = context['register_form']
- assert form.username.errors == [u'This field is required.']
- assert form.password.errors == [u'This field is required.']
- assert form.email.errors == [u'This field is required.']
+ assert form.username.errors == ['This field is required.']
+ assert form.password.errors == ['This field is required.']
+ assert form.email.errors == ['This field is required.']
# Try to register with fields that are known to be invalid
# --------------------------------------------------------
@@ -64,8 +64,8 @@ def test_register_views(test_app):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
form = context['register_form']
- assert form.username.errors == [u'Field must be between 3 and 30 characters long.']
- assert form.password.errors == [u'Field must be between 5 and 1024 characters long.']
+ assert form.username.errors == ['Field must be between 3 and 30 characters long.']
+ assert form.password.errors == ['Field must be between 5 and 1024 characters long.']
## bad form
template.clear_test_template_context()
@@ -76,8 +76,8 @@ def test_register_views(test_app):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
form = context['register_form']
- assert form.username.errors == [u'This field does not take email addresses.']
- assert form.email.errors == [u'This field requires an email address.']
+ assert form.username.errors == ['This field does not take email addresses.']
+ assert form.email.errors == ['This field requires an email address.']
## invalid characters
template.clear_test_template_context()
@@ -88,7 +88,7 @@ def test_register_views(test_app):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
form = context['register_form']
- assert form.username.errors == [u'Invalid input.']
+ assert form.username.errors == ['Invalid input.']
## At this point there should be no users in the database ;)
assert User.query.count() == 0
@@ -109,7 +109,7 @@ def test_register_views(test_app):
template.clear_test_template_context()
response = test_app.post(
'/auth/register/', {
- 'username': u'angrygirl',
+ 'username': 'angrygirl',
'password': 'iamsoangry',
'email': 'angrygrrl@example.org'})
response.follow()
@@ -120,20 +120,20 @@ def test_register_views(test_app):
## Make sure user is in place
new_user = mg_globals.database.LocalUser.query.filter(
- LocalUser.username==u'angrygirl'
+ LocalUser.username=='angrygirl'
).first()
assert new_user
## Make sure that the proper privileges are granted on registration
- assert new_user.has_privilege(u'commenter')
- assert new_user.has_privilege(u'uploader')
- assert new_user.has_privilege(u'reporter')
- assert not new_user.has_privilege(u'active')
+ assert new_user.has_privilege('commenter')
+ assert new_user.has_privilege('uploader')
+ assert new_user.has_privilege('reporter')
+ assert not new_user.has_privilege('active')
## Make sure user is logged in
request = template.TEMPLATE_TEST_CONTEXT[
'mediagoblin/user_pages/user_nonactive.html']['request']
- assert request.session['user_id'] == six.text_type(new_user.id)
+ assert request.session['user_id'] == str(new_user.id)
## Make sure we get email confirmation, and try verifying
assert len(mail.EMAIL_TEST_INBOX) == 2
@@ -145,7 +145,7 @@ def test_register_views(test_app):
path = urlparse.urlsplit(email_context['verification_url'])[2]
get_params = urlparse.urlsplit(email_context['verification_url'])[3]
- assert path == u'/auth/verify_email/'
+ assert path == '/auth/verify_email/'
parsed_get_params = urlparse.parse_qs(get_params)
## Try verifying with bs verification key, shouldn't work
@@ -160,20 +160,20 @@ 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.LocalUser.query.filter(
- LocalUser.username==u'angrygirl'
+ LocalUser.username=='angrygirl'
).first()
assert new_user
## Verify the email activation works
template.clear_test_template_context()
- response = test_app.get("%s?%s" % (path, get_params))
+ response = test_app.get("{}?{}".format(path, get_params))
response.follow()
context = template.TEMPLATE_TEST_CONTEXT[
'mediagoblin/user_pages/user.html']
# assert context['verification_successful'] == True
# TODO: Would be good to test messages here when we can do so...
new_user = mg_globals.database.LocalUser.query.filter(
- LocalUser.username==u'angrygirl'
+ LocalUser.username=='angrygirl'
).first()
assert new_user
@@ -183,7 +183,7 @@ def test_register_views(test_app):
template.clear_test_template_context()
response = test_app.post(
'/auth/register/', {
- 'username': u'angrygirl',
+ 'username': 'angrygirl',
'password': 'iamsoangry2',
'email': 'angrygrrl2@example.org'})
@@ -191,7 +191,7 @@ def test_register_views(test_app):
'mediagoblin/auth/register.html']
form = context['register_form']
assert form.username.errors == [
- u'Sorry, a user with that name already exists.']
+ 'Sorry, a user with that name already exists.']
## TODO: Also check for double instances of an email address?
@@ -200,7 +200,7 @@ def test_register_views(test_app):
template.clear_test_template_context()
response = test_app.post(
'/auth/forgot_password/',
- {'username': u'angrygirl'})
+ {'username': 'angrygirl'})
response.follow()
## Did we redirect to the proper page? Use the right template?
@@ -219,7 +219,7 @@ def test_register_views(test_app):
path = urlparse.urlsplit(email_context['verification_url'])[2]
get_params = urlparse.urlsplit(email_context['verification_url'])[3]
parsed_get_params = urlparse.parse_qs(get_params)
- assert path == u'/auth/forgot_password/verify/'
+ assert path == '/auth/forgot_password/verify/'
## Try using a bs password-changing verification key, shouldn't work
template.clear_test_template_context()
@@ -232,7 +232,7 @@ def test_register_views(test_app):
## Verify step 1 of password-change works -- can see form to change password
template.clear_test_template_context()
- response = test_app.get("%s?%s" % (path, get_params))
+ response = test_app.get("{}?{}".format(path, get_params))
assert 'mediagoblin/plugins/basic_auth/change_fp.html' in \
template.TEMPLATE_TEST_CONTEXT
@@ -249,7 +249,7 @@ def test_register_views(test_app):
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'username': u'angrygirl',
+ 'username': 'angrygirl',
'password': 'iamveryveryangry'})
# User should be redirected
@@ -276,24 +276,24 @@ def test_authentication_views(test_app):
response = test_app.post('/auth/login/')
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
form = context['login_form']
- assert form.username.errors == [u'This field is required.']
+ assert form.username.errors == ['This field is required.']
# Failed login - blank user
# -------------------------
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'password': u'toast'})
+ 'password': 'toast'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
form = context['login_form']
- assert form.username.errors == [u'This field is required.']
+ assert form.username.errors == ['This field is required.']
# Failed login - blank password
# -----------------------------
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'username': u'chris'})
+ 'username': 'chris'})
assert 'mediagoblin/auth/login.html' in template.TEMPLATE_TEST_CONTEXT
# Failed login - bad user
@@ -301,7 +301,7 @@ def test_authentication_views(test_app):
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'username': u'steve',
+ 'username': 'steve',
'password': 'toast'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
assert context['login_failed']
@@ -311,7 +311,7 @@ def test_authentication_views(test_app):
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'username': u'chris',
+ 'username': 'chris',
'password': 'jam_and_ham'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
assert context['login_failed']
@@ -321,7 +321,7 @@ def test_authentication_views(test_app):
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'username': u'chris',
+ 'username': 'chris',
'password': 'toast'})
# User should be redirected
@@ -332,7 +332,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'] == six.text_type(test_user.id)
+ assert session['user_id'] == str(test_user.id)
# Successful logout
# -----------------
@@ -354,7 +354,7 @@ def test_authentication_views(test_app):
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'username': u'chris',
+ 'username': 'chris',
'password': 'toast',
'next' : '/u/chris/'})
assert urlparse.urlsplit(response.location)[2] == '/u/chris/'
@@ -363,22 +363,22 @@ def test_authentication_views(test_app):
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'username': u'ANDREW',
+ 'username': 'ANDREW',
'password': 'fuselage'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
form = context['login_form']
# Username should no longer be uppercased; it should be lowercased
- assert not form.username.data == u'ANDREW'
- assert form.username.data == u'andrew'
+ assert not form.username.data == 'ANDREW'
+ assert form.username.data == 'andrew'
# Successful login with short user
# --------------------------------
- short_user = fixture_add_user(username=u'me', password=u'sho')
+ short_user = fixture_add_user(username='me', password='sho')
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'username': u'me',
+ 'username': 'me',
'password': 'sho'})
# User should be redirected
@@ -390,7 +390,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'] == six.text_type(short_user.id)
+ assert session['user_id'] == str(short_user.id)
# Must logout
template.clear_test_template_context()
@@ -399,11 +399,11 @@ def test_authentication_views(test_app):
# Successful login with long user
# ----------------
long_user = fixture_add_user(
- username=u'realllylonguser@reallylongdomain.com.co', password=u'sho')
+ username='realllylonguser@reallylongdomain.com.co', password='sho')
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
- 'username': u'realllylonguser@reallylongdomain.com.co',
+ 'username': 'realllylonguser@reallylongdomain.com.co',
'password': 'sho'})
# User should be redirected
@@ -414,7 +414,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'] == six.text_type(long_user.id)
+ assert session['user_id'] == str(long_user.id)
template.clear_test_template_context()
response = test_app.get('/auth/logout/')
diff --git a/mediagoblin/tests/test_basic_auth.py b/mediagoblin/tests/test_basic_auth.py
index 3a42e407..f7553fe1 100644
--- a/mediagoblin/tests/test_basic_auth.py
+++ b/mediagoblin/tests/test_basic_auth.py
@@ -68,13 +68,13 @@ def test_bcrypt_gen_password_hash():
def test_change_password(test_app):
"""Test changing password correctly and incorrectly"""
test_user = fixture_add_user(
- password=u'toast',
- privileges=[u'active'])
+ password='toast',
+ privileges=['active'])
test_app.post(
'/auth/login/', {
- 'username': u'chris',
- 'password': u'toast'})
+ 'username': 'chris',
+ 'password': 'toast'})
# test that the password can be changed
res = test_app.post(
@@ -88,7 +88,7 @@ def test_change_password(test_app):
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
# test_user has to be fetched again in order to have the current values
- test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
+ test_user = LocalUser.query.filter(LocalUser.username=='chris').first()
assert auth_tools.bcrypt_check_password('123456', test_user.pw_hash)
# test that the password cannot be changed if the given
@@ -100,5 +100,5 @@ def test_change_password(test_app):
'new_password': '098765',
})
- test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
+ test_user = LocalUser.query.filter(LocalUser.username=='chris').first()
assert not auth_tools.bcrypt_check_password('098765', test_user.pw_hash)
diff --git a/mediagoblin/tests/test_config.py b/mediagoblin/tests/test_config.py
index c3527418..bff2fc51 100644
--- a/mediagoblin/tests/test_config.py
+++ b/mediagoblin/tests/test_config.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
#
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
@@ -49,7 +48,7 @@ def test_read_mediagoblin_config():
assert this_conf['carrotapp']['num_carrots'] == 88
assert this_conf['carrotapp']['encouragement_phrase'] == \
"I'd love it if you eat your carrots!"
- assert this_conf['carrotapp']['blah_blah'] == u"blæh!"
+ assert this_conf['carrotapp']['blah_blah'] == "blæh!"
assert this_conf['celery']['EAT_CELERY_WITH_CARROTS'] == False
# A bad file
diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py
index 5c109be6..c2cee048 100644
--- a/mediagoblin/tests/test_edit.py
+++ b/mediagoblin/tests/test_edit.py
@@ -25,12 +25,12 @@ from mediagoblin import auth
from mediagoblin.tools import template, mail
-class TestUserEdit(object):
+class TestUserEdit:
def setup(self):
# set up new user
- self.user_password = u'toast'
+ self.user_password = 'toast'
self.user = fixture_add_user(password = self.user_password,
- privileges=[u'active'])
+ privileges=['active'])
def login(self, test_app):
test_app.post(
@@ -44,19 +44,19 @@ class TestUserEdit(object):
self.login(test_app)
# Make sure user exists
- assert LocalUser.query.filter(LocalUser.username==u'chris').first()
+ assert LocalUser.query.filter(LocalUser.username=='chris').first()
res = test_app.post('/edit/account/delete/', {'confirmed': 'y'})
# Make sure user has been deleted
- assert LocalUser.query.filter(LocalUser.username==u'chris').first() == None
+ assert LocalUser.query.filter(LocalUser.username=='chris').first() == None
#TODO: make sure all corresponding items comments etc have been
# deleted too. Perhaps in submission test?
#Restore user at end of test
self.user = fixture_add_user(password = self.user_password,
- privileges=[u'active'])
+ privileges=['active'])
self.login(test_app)
@@ -67,8 +67,8 @@ class TestUserEdit(object):
# Test if legacy profile editing URL redirects correctly
res = test_app.post(
'/edit/profile/', {
- 'bio': u'I love toast!',
- 'url': u'http://dustycloud.org/'}, expect_errors=True)
+ 'bio': 'I love toast!',
+ 'url': 'http://dustycloud.org/'}, expect_errors=True)
# Should redirect to /u/chris/edit/
assert res.status_int == 302
@@ -76,20 +76,20 @@ class TestUserEdit(object):
res = test_app.post(
'/u/chris/edit/', {
- 'bio': u'I love toast!',
- 'url': u'http://dustycloud.org/'})
+ 'bio': 'I love toast!',
+ 'url': 'http://dustycloud.org/'})
- test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
- assert test_user.bio == u'I love toast!'
- assert test_user.url == u'http://dustycloud.org/'
+ test_user = LocalUser.query.filter(LocalUser.username=='chris').first()
+ assert test_user.bio == 'I love toast!'
+ assert test_user.url == 'http://dustycloud.org/'
# change a different user than the logged in (should fail with 403)
- fixture_add_user(username=u"foo",
- privileges=[u'active'])
+ fixture_add_user(username="foo",
+ privileges=['active'])
res = test_app.post(
'/u/foo/edit/', {
- 'bio': u'I love toast!',
- 'url': u'http://dustycloud.org/'}, expect_errors=True)
+ 'bio': 'I love toast!',
+ 'url': 'http://dustycloud.org/'}, expect_errors=True)
assert res.status_int == 403
# test changing the bio and the URL inproperly
@@ -107,9 +107,9 @@ class TestUserEdit(object):
form = context['form']
assert form.bio.errors == [
- u'Field must be between 0 and 500 characters long.']
+ 'Field must be between 0 and 500 characters long.']
assert form.url.errors == [
- u'This address contains errors']
+ 'This address contains errors']
def test_email_change(self, test_app):
self.login(test_app)
@@ -125,7 +125,7 @@ class TestUserEdit(object):
context = template.TEMPLATE_TEST_CONTEXT[
'mediagoblin/edit/change_email.html']
assert context['form'].new_email.errors == [
- u'Sorry, a user with that email address already exists.']
+ 'Sorry, a user with that email address already exists.']
# Test successful email change
template.clear_test_template_context()
@@ -147,7 +147,7 @@ class TestUserEdit(object):
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/'
+ assert path == '/edit/verify_email/'
## Try verifying with bs verification key, shouldn't work
template.clear_test_template_context()
@@ -169,7 +169,7 @@ class TestUserEdit(object):
# Verify email activation works
template.clear_test_template_context()
get_params = urlparse.urlsplit(email_context['verification_url'])[3]
- res = test_app.get('%s?%s' % (path, get_params))
+ res = test_app.get('{}?{}'.format(path, get_params))
res.follow()
# New email saved?
@@ -181,10 +181,10 @@ class TestMetaDataEdit:
@pytest.fixture(autouse=True)
def setup(self, test_app):
# set up new user
- self.user_password = u'toast'
+ self.user_password = 'toast'
self.user = fixture_add_user(
password = self.user_password,
- privileges=[u'active',u'admin']
+ privileges=['active','admin']
)
self.test_app = test_app
@@ -209,7 +209,7 @@ class TestMetaDataEdit:
@pytest.mark.skipif(six.PY2, reason='Breaks in Python 2 but seems non-critical')
def test_edit_metadata(self, test_app):
media_entry = fixture_media_entry(uploader=self.user.id,
- state=u'processed')
+ state='processed')
media_slug = "/u/{username}/m/{media_id}/metadata/".format(
username = str(self.user.username),
media_id = str(media_entry.id))
diff --git a/mediagoblin/tests/test_exif.py b/mediagoblin/tests/test_exif.py
index ad771cca..0074e862 100644
--- a/mediagoblin/tests/test_exif.py
+++ b/mediagoblin/tests/test_exif.py
@@ -28,7 +28,7 @@ from .resources import GOOD_JPG, EMPTY_JPG, BAD_JPG, GPS_JPG, BAD_GPS_JPG
def assert_in(a, b):
- assert a in b, "%r not in %r" % (a, b)
+ assert a in b, "{!r} not in {!r}".format(a, b)
def test_exif_extraction():
@@ -72,301 +72,301 @@ def test_exif_extraction():
'EXIF CompressedBitsPerPixel': {'field_length': 8,
'field_offset': 756,
'field_type': 5,
- 'printable': u'4',
+ 'printable': '4',
'tag': 37122,
'values': [[4, 1]]},
'EXIF Contrast': {'field_length': 2,
'field_offset': 656,
'field_type': 3,
- 'printable': u'Soft',
+ 'printable': 'Soft',
'tag': 41992,
'values': [1]},
'EXIF CustomRendered': {'field_length': 2,
'field_offset': 572,
'field_type': 3,
- 'printable': u'Normal',
+ 'printable': 'Normal',
'tag': 41985,
'values': [0]},
'EXIF DateTimeDigitized': {'field_length': 20,
'field_offset': 736,
'field_type': 2,
- 'printable': u'2011:06:22 12:20:33',
+ 'printable': '2011:06:22 12:20:33',
'tag': 36868,
- 'values': u'2011:06:22 12:20:33'},
+ 'values': '2011:06:22 12:20:33'},
'EXIF DateTimeOriginal': {'field_length': 20,
'field_offset': 716,
'field_type': 2,
- 'printable': u'2011:06:22 12:20:33',
+ 'printable': '2011:06:22 12:20:33',
'tag': 36867,
- 'values': u'2011:06:22 12:20:33'},
+ 'values': '2011:06:22 12:20:33'},
'EXIF DigitalZoomRatio': {'field_length': 8,
'field_offset': 26232,
'field_type': 5,
- 'printable': u'1',
+ 'printable': '1',
'tag': 41988,
'values': [[1, 1]]},
'EXIF ExifImageLength': {'field_length': 2,
'field_offset': 500,
'field_type': 3,
- 'printable': u'2592',
+ 'printable': '2592',
'tag': 40963,
'values': [2592]},
'EXIF ExifImageWidth': {'field_length': 2,
'field_offset': 488,
'field_type': 3,
- 'printable': u'3872',
+ 'printable': '3872',
'tag': 40962,
'values': [3872]},
'EXIF ExifVersion': {'field_length': 4,
'field_offset': 272,
'field_type': 7,
- 'printable': u'0221',
+ 'printable': '0221',
'tag': 36864,
'values': [48, 50, 50, 49]},
'EXIF ExposureBiasValue': {'field_length': 8,
'field_offset': 764,
'field_type': 10,
- 'printable': u'0',
+ 'printable': '0',
'tag': 37380,
'values': [[0, 1]]},
'EXIF ExposureMode': {'field_length': 2,
'field_offset': 584,
'field_type': 3,
- 'printable': u'Manual Exposure',
+ 'printable': 'Manual Exposure',
'tag': 41986,
'values': [1]},
'EXIF ExposureProgram': {'field_length': 2,
'field_offset': 248,
'field_type': 3,
- 'printable': u'Manual',
+ 'printable': 'Manual',
'tag': 34850,
'values': [1]},
'EXIF ExposureTime': {'field_length': 8,
'field_offset': 700,
'field_type': 5,
- 'printable': u'1/125',
+ 'printable': '1/125',
'tag': 33434,
'values': [[1, 125]]},
'EXIF FNumber': {'field_length': 8,
'field_offset': 708,
'field_type': 5,
- 'printable': u'10',
+ 'printable': '10',
'tag': 33437,
'values': [[10, 1]]},
'EXIF FileSource': {'field_length': 1,
'field_offset': 536,
'field_type': 7,
- 'printable': u'Digital Camera',
+ 'printable': 'Digital Camera',
'tag': 41728,
'values': [3]},
'EXIF Flash': {'field_length': 2,
'field_offset': 380,
'field_type': 3,
- 'printable': u'Flash did not fire',
+ 'printable': 'Flash did not fire',
'tag': 37385,
'values': [0]},
'EXIF FlashPixVersion': {'field_length': 4,
'field_offset': 464,
'field_type': 7,
- 'printable': u'0100',
+ 'printable': '0100',
'tag': 40960,
'values': [48, 49, 48, 48]},
'EXIF FocalLength': {'field_length': 8,
'field_offset': 780,
'field_type': 5,
- 'printable': u'18',
+ 'printable': '18',
'tag': 37386,
'values': [[18, 1]]},
'EXIF FocalLengthIn35mmFilm': {'field_length': 2,
'field_offset': 620,
'field_type': 3,
- 'printable': u'27',
+ 'printable': '27',
'tag': 41989,
'values': [27]},
'EXIF GainControl': {'field_length': 2,
'field_offset': 644,
'field_type': 3,
- 'printable': u'None',
+ 'printable': 'None',
'tag': 41991,
'values': [0]},
'EXIF ISOSpeedRatings': {'field_length': 2,
'field_offset': 260,
'field_type': 3,
- 'printable': u'100',
+ 'printable': '100',
'tag': 34855,
'values': [100]},
'EXIF InteroperabilityOffset': {'field_length': 4,
'field_offset': 512,
'field_type': 4,
- 'printable': u'26240',
+ 'printable': '26240',
'tag': 40965,
'values': [26240]},
'EXIF LightSource': {'field_length': 2,
'field_offset': 368,
'field_type': 3,
- 'printable': u'Unknown',
+ 'printable': 'Unknown',
'tag': 37384,
'values': [0]},
'EXIF MaxApertureValue': {'field_length': 8,
'field_offset': 772,
'field_type': 5,
- 'printable': u'18/5',
+ 'printable': '18/5',
'tag': 37381,
'values': [[18, 5]]},
'EXIF MeteringMode': {'field_length': 2,
'field_offset': 356,
'field_type': 3,
- 'printable': u'Pattern',
+ 'printable': 'Pattern',
'tag': 37383,
'values': [5]},
'EXIF Saturation': {'field_length': 2,
'field_offset': 668,
'field_type': 3,
- 'printable': u'Normal',
+ 'printable': 'Normal',
'tag': 41993,
'values': [0]},
'EXIF SceneCaptureType': {'field_length': 2,
'field_offset': 632,
'field_type': 3,
- 'printable': u'Standard',
+ 'printable': 'Standard',
'tag': 41990,
'values': [0]},
'EXIF SceneType': {'field_length': 1,
'field_offset': 548,
'field_type': 7,
- 'printable': u'Directly Photographed',
+ 'printable': 'Directly Photographed',
'tag': 41729,
'values': [1]},
'EXIF SensingMethod': {'field_length': 2,
'field_offset': 524,
'field_type': 3,
- 'printable': u'One-chip color area',
+ 'printable': 'One-chip color area',
'tag': 41495,
'values': [2]},
'EXIF Sharpness': {'field_length': 2,
'field_offset': 680,
'field_type': 3,
- 'printable': u'Normal',
+ 'printable': 'Normal',
'tag': 41994,
'values': [0]},
'EXIF SubSecTime': {'field_length': 3,
'field_offset': 428,
'field_type': 2,
- 'printable': u'10',
+ 'printable': '10',
'tag': 37520,
- 'values': u'10'},
+ 'values': '10'},
'EXIF SubSecTimeDigitized': {'field_length': 3,
'field_offset': 452,
'field_type': 2,
- 'printable': u'10',
+ 'printable': '10',
'tag': 37522,
- 'values': u'10'},
+ 'values': '10'},
'EXIF SubSecTimeOriginal': {'field_length': 3,
'field_offset': 440,
'field_type': 2,
- 'printable': u'10',
+ 'printable': '10',
'tag': 37521,
- 'values': u'10'},
+ 'values': '10'},
'EXIF SubjectDistanceRange': {'field_length': 2,
'field_offset': 692,
'field_type': 3,
- 'printable': u'0',
+ 'printable': '0',
'tag': 41996,
'values': [0]},
'EXIF WhiteBalance': {'field_length': 2,
'field_offset': 596,
'field_type': 3,
- 'printable': u'Auto',
+ 'printable': 'Auto',
'tag': 41987,
'values': [0]},
'Image DateTime': {'field_length': 20,
'field_offset': 194,
'field_type': 2,
- 'printable': u'2011:06:22 12:20:33',
+ 'printable': '2011:06:22 12:20:33',
'tag': 306,
- 'values': u'2011:06:22 12:20:33'},
+ 'values': '2011:06:22 12:20:33'},
'Image ExifOffset': {'field_length': 4,
'field_offset': 126,
'field_type': 4,
- 'printable': u'214',
+ 'printable': '214',
'tag': 34665,
'values': [214]},
'Image Make': {'field_length': 18,
'field_offset': 134,
'field_type': 2,
- 'printable': u'NIKON CORPORATION',
+ 'printable': 'NIKON CORPORATION',
'tag': 271,
- 'values': u'NIKON CORPORATION'},
+ 'values': 'NIKON CORPORATION'},
'Image Model': {'field_length': 10,
'field_offset': 152,
'field_type': 2,
- 'printable': u'NIKON D80',
+ 'printable': 'NIKON D80',
'tag': 272,
- 'values': u'NIKON D80'},
+ 'values': 'NIKON D80'},
'Image Orientation': {'field_length': 2,
'field_offset': 42,
'field_type': 3,
- 'printable': u'Rotated 90 CW',
+ 'printable': 'Rotated 90 CW',
'tag': 274,
'values': [6]},
'Image ResolutionUnit': {'field_length': 2,
'field_offset': 78,
'field_type': 3,
- 'printable': u'Pixels/Inch',
+ 'printable': 'Pixels/Inch',
'tag': 296,
'values': [2]},
'Image Software': {'field_length': 15,
'field_offset': 178,
'field_type': 2,
- 'printable': u'Shotwell 0.9.3',
+ 'printable': 'Shotwell 0.9.3',
'tag': 305,
- 'values': u'Shotwell 0.9.3'},
+ 'values': 'Shotwell 0.9.3'},
'Image XResolution': {'field_length': 8,
'field_offset': 162,
'field_type': 5,
- 'printable': u'300',
+ 'printable': '300',
'tag': 282,
'values': [[300, 1]]},
'Image YCbCrPositioning': {'field_length': 2,
'field_offset': 114,
'field_type': 3,
- 'printable': u'Co-sited',
+ 'printable': 'Co-sited',
'tag': 531,
'values': [2]},
'Image YResolution': {'field_length': 8,
'field_offset': 170,
'field_type': 5,
- 'printable': u'300',
+ 'printable': '300',
'tag': 283,
'values': [[300, 1]]},
'Thumbnail Compression': {'field_length': 2,
'field_offset': 26280,
'field_type': 3,
- 'printable': u'JPEG (old-style)',
+ 'printable': 'JPEG (old-style)',
'tag': 259,
'values': [6]},
'Thumbnail ResolutionUnit': {'field_length': 2,
'field_offset': 26316,
'field_type': 3,
- 'printable': u'Pixels/Inch',
+ 'printable': 'Pixels/Inch',
'tag': 296,
'values': [2]},
'Thumbnail XResolution': {'field_length': 8,
'field_offset': 26360,
'field_type': 5,
- 'printable': u'300',
+ 'printable': '300',
'tag': 282,
'values': [[300, 1]]},
'Thumbnail YCbCrPositioning': {'field_length': 2,
'field_offset': 26352,
'field_type': 3,
- 'printable': u'Co-sited',
+ 'printable': 'Co-sited',
'tag': 531,
'values': [2]},
'Thumbnail YResolution': {'field_length': 8,
'field_offset': 26368,
'field_type': 5,
- 'printable': u'300',
+ 'printable': '300',
'tag': 283,
'values': [[300, 1]]}})
diff --git a/mediagoblin/tests/test_globals.py b/mediagoblin/tests/test_globals.py
index fe3088f8..2b7212e9 100644
--- a/mediagoblin/tests/test_globals.py
+++ b/mediagoblin/tests/test_globals.py
@@ -19,7 +19,7 @@ import pytest
from mediagoblin import mg_globals
-class TestGlobals(object):
+class TestGlobals:
def setup(self):
self.old_database = mg_globals.database
diff --git a/mediagoblin/tests/test_ldap.py b/mediagoblin/tests/test_ldap.py
index 6ac0fc46..0af1b7f5 100644
--- a/mediagoblin/tests/test_ldap.py
+++ b/mediagoblin/tests/test_ldap.py
@@ -18,7 +18,7 @@ import pkg_resources
import pytest
import six
try:
- import mock
+ from unittest import mock
except ImportError:
import unittest.mock as mock
@@ -43,7 +43,7 @@ def ldap_plugin_app(request):
def return_value():
- return u'chris', u'chris@example.com'
+ return 'chris', 'chris@example.com'
def test_ldap_plugin(ldap_plugin_app):
@@ -65,8 +65,8 @@ def test_ldap_plugin(ldap_plugin_app):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
form = context['login_form']
- assert form.username.errors == [u'This field is required.']
- assert form.password.errors == [u'This field is required.']
+ assert form.username.errors == ['This field is required.']
+ assert form.password.errors == ['This field is required.']
@mock.patch('mediagoblin.plugins.ldap.tools.LDAP.login',
mock.Mock(return_value=return_value()))
@@ -74,21 +74,21 @@ def test_ldap_plugin(ldap_plugin_app):
template.clear_test_template_context()
res = ldap_plugin_app.post(
'/auth/ldap/login/',
- {'username': u'chris',
- 'password': u'toast'})
+ {'username': 'chris',
+ 'password': 'toast'})
context = template.TEMPLATE_TEST_CONTEXT[
'mediagoblin/auth/register.html']
register_form = context['register_form']
- assert register_form.username.data == u'chris'
- assert register_form.email.data == u'chris@example.com'
+ assert register_form.username.data == 'chris'
+ assert register_form.email.data == 'chris@example.com'
template.clear_test_template_context()
res = ldap_plugin_app.post(
'/auth/ldap/register/',
- {'username': u'chris',
- 'email': u'chris@example.com'})
+ {'username': 'chris',
+ 'email': 'chris@example.com'})
res.follow()
assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
@@ -99,24 +99,24 @@ def test_ldap_plugin(ldap_plugin_app):
template.clear_test_template_context()
res = ldap_plugin_app.post(
'/auth/ldap/register/',
- {'username': u'chris',
- 'email': u'chris@example.com'})
+ {'username': 'chris',
+ 'email': 'chris@example.com'})
context = template.TEMPLATE_TEST_CONTEXT[
'mediagoblin/auth/register.html']
register_form = context['register_form']
assert register_form.email.errors == [
- u'Sorry, a user with that email address already exists.']
+ 'Sorry, a user with that email address already exists.']
assert register_form.username.errors == [
- u'Sorry, a user with that name already exists.']
+ 'Sorry, a user with that name already exists.']
# Log out
ldap_plugin_app.get('/auth/logout/')
# Get user and detach from session
test_user = mg_globals.database.LocalUser.query.filter(
- LocalUser.username==u'chris'
+ LocalUser.username=='chris'
).first()
Session.expunge(test_user)
@@ -124,8 +124,8 @@ def test_ldap_plugin(ldap_plugin_app):
template.clear_test_template_context()
res = ldap_plugin_app.post(
'/auth/ldap/login/',
- {'username': u'chris',
- 'password': u'toast'})
+ {'username': 'chris',
+ 'password': 'toast'})
res.follow()
assert urlparse.urlsplit(res.location)[2] == '/'
@@ -134,6 +134,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'] == six.text_type(test_user.id)
+ assert session['user_id'] == str(test_user.id)
_test_authentication()
diff --git a/mediagoblin/tests/test_legacy_api.py b/mediagoblin/tests/test_legacy_api.py
index b3b2fcec..93f016a3 100644
--- a/mediagoblin/tests/test_legacy_api.py
+++ b/mediagoblin/tests/test_legacy_api.py
@@ -31,13 +31,13 @@ from .resources import GOOD_JPG, GOOD_PNG, EVIL_FILE, EVIL_JPG, EVIL_PNG, \
_log = logging.getLogger(__name__)
-class TestAPI(object):
+class TestAPI:
def setup(self):
self.db = mg_globals.database
- self.user_password = u'4cc355_70k3N'
- self.user = fixture_add_user(u'joapi', self.user_password,
- privileges=[u'active',u'uploader'])
+ self.user_password = '4cc355_70k3N'
+ self.user = fixture_add_user('joapi', self.user_password,
+ privileges=['active','uploader'])
def login(self, test_app):
test_app.post(
@@ -49,7 +49,7 @@ class TestAPI(object):
return template.TEMPLATE_TEST_CONTEXT[template_name]
def http_auth_headers(self):
- return {'Authorization': ('Basic {0}'.format(
+ return {'Authorization': ('Basic {}'.format(
base64.b64encode((':'.join([
self.user.username,
self.user_password])).encode('ascii')).decode()))}
@@ -91,4 +91,4 @@ class TestAPI(object):
assert response.status_int == 200
- assert self.db.MediaEntry.query.filter_by(title=u'Great JPG!').first()
+ assert self.db.MediaEntry.query.filter_by(title='Great JPG!').first()
diff --git a/mediagoblin/tests/test_metadata.py b/mediagoblin/tests/test_metadata.py
index a10e00ec..b185e605 100644
--- a/mediagoblin/tests/test_metadata.py
+++ b/mediagoblin/tests/test_metadata.py
@@ -39,7 +39,7 @@ class TestMetadataFunctionality:
# Free floating nodes should be removed
assert jsonld_metadata.get('location') is None
assert jsonld_metadata.get('@context') == \
- u"http://www.w3.org/2013/json-ld-context/rdfa11"
+ "http://www.w3.org/2013/json-ld-context/rdfa11"
# Next, make sure that various badly formatted metadata
# will be rejected.
diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py
index 5500a0d7..fc1057a3 100644
--- a/mediagoblin/tests/test_misc.py
+++ b/mediagoblin/tests/test_misc.py
@@ -34,8 +34,8 @@ def test_404_for_non_existent(test_app):
def test_user_deletes_other_comments(test_app):
- user_a = fixture_add_user(u"chris_a")
- user_b = fixture_add_user(u"chris_b")
+ user_a = fixture_add_user("chris_a")
+ user_b = fixture_add_user("chris_b")
media_a = fixture_media_entry(uploader=user_a.id, save=False,
expunge=False, fake_upload=False)
@@ -50,7 +50,7 @@ def test_user_deletes_other_comments(test_app):
for m in (media_a, media_b):
cmt = TextComment()
cmt.actor = u.id
- cmt.content = u"Some Comment"
+ cmt.content = "Some Comment"
Session.add(cmt)
# think i need this to get the command ID
Session.flush()
@@ -94,12 +94,12 @@ def test_user_deletes_other_comments(test_app):
def test_media_deletes_broken_attachment(test_app):
- user_a = fixture_add_user(u"chris_a")
+ user_a = fixture_add_user("chris_a")
media = fixture_media_entry(uploader=user_a.id, save=False, expunge=False)
media.attachment_files.append(dict(
- name=u"some name",
- filepath=[u"does", u"not", u"exist"],
+ name="some name",
+ filepath=["does", "not", "exist"],
))
Session.add(media)
Session.flush()
@@ -151,7 +151,7 @@ def test_comments_removed_when_graveyarded(test_app):
# Add the TextComment
comment = TextComment()
comment.actor = user.id
- comment.content = u"This is a comment that will be deleted."
+ comment.content = "This is a comment that will be deleted."
comment.save()
# Add a link for the comment
diff --git a/mediagoblin/tests/test_modelmethods.py b/mediagoblin/tests/test_modelmethods.py
index 4c66e27b..63c38660 100644
--- a/mediagoblin/tests/test_modelmethods.py
+++ b/mediagoblin/tests/test_modelmethods.py
@@ -17,7 +17,6 @@
# 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, LocalUser, Privilege, \
@@ -28,13 +27,13 @@ from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry, \
fixture_add_activity
try:
- import mock
+ from unittest import mock
except ImportError:
import unittest.mock as mock
import pytest
-class FakeUUID(object):
+class FakeUUID:
hex = 'testtest-test-test-test-testtesttest'
UUID_MOCK = mock.Mock(return_value=FakeUUID())
@@ -42,22 +41,22 @@ UUID_MOCK = mock.Mock(return_value=FakeUUID())
REQUEST_CONTEXT = ['mediagoblin/root.html', 'request']
-class TestMediaEntrySlugs(object):
+class TestMediaEntrySlugs:
def _setup(self):
- self.chris_user = fixture_add_user(u'chris')
- self.emily_user = fixture_add_user(u'emily')
+ self.chris_user = fixture_add_user('chris')
+ self.emily_user = fixture_add_user('emily')
self.existing_entry = self._insert_media_entry_fixture(
- title=u"Beware, I exist!",
- slug=u"beware-i-exist")
+ title="Beware, I exist!",
+ slug="beware-i-exist")
def _insert_media_entry_fixture(self, title=None, slug=None, this_id=None,
uploader=None, save=True):
entry = MediaEntry()
- entry.title = title or u"Some title"
+ entry.title = title or "Some title"
entry.slug = slug
entry.id = this_id
entry.actor = uploader or self.chris_user.id
- entry.media_type = u'image'
+ entry.media_type = 'image'
if save:
entry.save()
@@ -67,33 +66,33 @@ class TestMediaEntrySlugs(object):
def test_unique_slug_from_title(self, test_app):
self._setup()
- entry = self._insert_media_entry_fixture(u"Totally unique slug!", save=False)
+ entry = self._insert_media_entry_fixture("Totally unique slug!", save=False)
entry.generate_slug()
- assert entry.slug == u'totally-unique-slug'
+ assert entry.slug == 'totally-unique-slug'
def test_old_good_unique_slug(self, test_app):
self._setup()
entry = self._insert_media_entry_fixture(
- u"A title here", u"a-different-slug-there", save=False)
+ "A title here", "a-different-slug-there", save=False)
entry.generate_slug()
- assert entry.slug == u"a-different-slug-there"
+ assert entry.slug == "a-different-slug-there"
def test_old_weird_slug(self, test_app):
self._setup()
entry = self._insert_media_entry_fixture(
- slug=u"wowee!!!!!", save=False)
+ slug="wowee!!!!!", save=False)
entry.generate_slug()
- assert entry.slug == u"wowee"
+ assert entry.slug == "wowee"
def test_existing_slug_use_id(self, test_app):
self._setup()
entry = self._insert_media_entry_fixture(
- u"Beware, I exist!!", this_id=9000, save=False)
+ "Beware, I exist!!", this_id=9000, save=False)
entry.generate_slug()
- assert entry.slug == u"beware-i-exist-9000"
+ assert entry.slug == "beware-i-exist-9000"
def test_existing_slug_cant_use_id(self, test_app):
self._setup()
@@ -104,12 +103,12 @@ class TestMediaEntrySlugs(object):
def _real_test():
# This one grabs the nine thousand slug
self._insert_media_entry_fixture(
- slug=u"beware-i-exist-9000")
+ slug="beware-i-exist-9000")
entry = self._insert_media_entry_fixture(
- u"Beware, I exist!!", this_id=9000, save=False)
+ "Beware, I exist!!", this_id=9000, save=False)
entry.generate_slug()
- assert entry.slug == u"beware-i-exist-test"
+ assert entry.slug == "beware-i-exist-test"
_real_test()
@@ -122,16 +121,16 @@ class TestMediaEntrySlugs(object):
def _real_test():
# This one grabs the nine thousand slug
self._insert_media_entry_fixture(
- slug=u"beware-i-exist-9000")
+ slug="beware-i-exist-9000")
# This one grabs makes sure the annoyance doesn't stop
self._insert_media_entry_fixture(
- slug=u"beware-i-exist-test")
+ slug="beware-i-exist-test")
entry = self._insert_media_entry_fixture(
- u"Beware, I exist!!", this_id=9000, save=False)
+ "Beware, I exist!!", this_id=9000, save=False)
entry.generate_slug()
- assert entry.slug == u"beware-i-exist-testtest"
+ assert entry.slug == "beware-i-exist-testtest"
_real_test()
@@ -141,42 +140,42 @@ class TestMediaEntrySlugs(object):
all. We'll just reference them by id.
,
- / \ (@!#?@!)
- |\,/| ,-, /
+ / \\ (@!#?@!)
+ |\\,/| ,-, /
| |#| ( ")~
- / \|/ \ L L
- |\,/|\,/|
+ / \\|/ \\ L L
+ |\\,/|\\,/|
| |#, |#|
- / \|/ \|/ \
- |\,/|\,/|\,/|
+ / \\|/ \\|/ \
+ |\\,/|\\,/|\\,/|
| |#| |#| |#|
- / \|/ \|/ \|/ \
- |\,/|\,/|\,/|\,/|
+ / \\|/ \\|/ \\|/ \
+ |\\,/|\\,/|\\,/|\\,/|
| |#| |#| |#| |#|
- \|/ \|/ \|/ \|/
+ \\|/ \\|/ \\|/ \\|/
"""
self._setup()
qbert_entry = self._insert_media_entry_fixture(
- u"@!#?@!", save=False)
+ "@!#?@!", save=False)
qbert_entry.generate_slug()
assert qbert_entry.slug is None
class TestUserHasPrivilege:
def _setup(self):
- fixture_add_user(u'natalie',
- privileges=[u'admin',u'moderator',u'active'])
- fixture_add_user(u'aeva',
- privileges=[u'moderator',u'active'])
+ fixture_add_user('natalie',
+ privileges=['admin','moderator','active'])
+ fixture_add_user('aeva',
+ privileges=['moderator','active'])
self.natalie_user = LocalUser.query.filter(
- LocalUser.username==u'natalie').first()
+ LocalUser.username=='natalie').first()
self.aeva_user = LocalUser.query.filter(
- LocalUser.username==u'aeva').first()
+ LocalUser.username=='aeva').first()
def test_privilege_added_correctly(self, test_app):
self._setup()
admin = Privilege.query.filter(
- Privilege.privilege_name == u'admin').one()
+ Privilege.privilege_name == 'admin').one()
# first make sure the privileges were added successfully
assert admin in self.natalie_user.all_privileges
@@ -186,23 +185,23 @@ class TestUserHasPrivilege:
self._setup()
# then test out the user.has_privilege method for one privilege
- assert not self.aeva_user.has_privilege(u'admin')
- assert self.natalie_user.has_privilege(u'active')
+ assert not self.aeva_user.has_privilege('admin')
+ assert self.natalie_user.has_privilege('active')
def test_allow_admin(self, test_app):
self._setup()
# This should work because she is an admin.
- assert self.natalie_user.has_privilege(u'commenter')
+ assert self.natalie_user.has_privilege('commenter')
# Test that we can look this out ignoring that she's an admin
- assert not self.natalie_user.has_privilege(u'commenter', allow_admin=False)
+ assert not self.natalie_user.has_privilege('commenter', allow_admin=False)
def test_media_data_init(test_app):
Session.rollback()
Session.remove()
media = MediaEntry()
- media.media_type = u"mediagoblin.media_types.image"
+ media.media_type = "mediagoblin.media_types.image"
assert media.media_data is None
media.media_data_init()
assert media.media_data is not None
@@ -215,12 +214,12 @@ def test_media_data_init(test_app):
class TestUserUrlForSelf(MGClientTestCase):
- usernames = [(u'lindsay', dict(privileges=[u'active']))]
+ usernames = [('lindsay', dict(privileges=['active']))]
def test_url_for_self(self):
_, request = self.do_get('/', *REQUEST_CONTEXT)
- assert self.user(u'lindsay').url_for_self(request.urlgen) == '/u/lindsay/'
+ assert self.user('lindsay').url_for_self(request.urlgen) == '/u/lindsay/'
def test_url_for_self_not_callable(self):
_, request = self.do_get('/', *REQUEST_CONTEXT)
@@ -229,6 +228,6 @@ class TestUserUrlForSelf(MGClientTestCase):
pass
with pytest.raises(TypeError) as excinfo:
- self.user(u'lindsay').url_for_self(fake_urlgen())
+ self.user('lindsay').url_for_self(fake_urlgen())
assert excinfo.errisinstance(TypeError)
assert 'object is not callable' in str(excinfo)
diff --git a/mediagoblin/tests/test_moderation.py b/mediagoblin/tests/test_moderation.py
index 55bb4c4b..c262a768 100644
--- a/mediagoblin/tests/test_moderation.py
+++ b/mediagoblin/tests/test_moderation.py
@@ -28,12 +28,12 @@ class TestModerationViews:
def _setup(self, test_app):
self.test_app = test_app
- fixture_add_user(u'admin',
- privileges=[u'admin',u'active'])
- fixture_add_user(u'moderator',
- privileges=[u'moderator',u'active'])
- fixture_add_user(u'regular',
- privileges=[u'active',u'commenter'])
+ fixture_add_user('admin',
+ privileges=['admin','active'])
+ fixture_add_user('moderator',
+ privileges=['moderator','active'])
+ fixture_add_user('regular',
+ privileges=['active','commenter'])
self.query_for_users()
def login(self, username):
@@ -48,9 +48,9 @@ class TestModerationViews:
self.query_for_users()
def query_for_users(self):
- self.admin_user = LocalUser.query.filter(LocalUser.username==u'admin').first()
- self.mod_user = LocalUser.query.filter(LocalUser.username==u'moderator').first()
- self.user = LocalUser.query.filter(LocalUser.username==u'regular').first()
+ self.admin_user = LocalUser.query.filter(LocalUser.username=='admin').first()
+ self.mod_user = LocalUser.query.filter(LocalUser.username=='moderator').first()
+ self.user = LocalUser.query.filter(LocalUser.username=='regular').first()
def do_post(self, data, *context_keys, **kwargs):
url = kwargs.pop('url', '/submit/')
@@ -65,39 +65,39 @@ class TestModerationViews:
return response, context_data
def testGiveOrTakeAwayPrivileges(self):
- self.login(u'admin')
+ self.login('admin')
# First, test an admin taking away a privilege from a user
#----------------------------------------------------------------------
- response, context = self.do_post({'privilege_name':u'commenter'},
- url='/mod/users/{0}/privilege/'.format(self.user.username))
+ response, context = self.do_post({'privilege_name':'commenter'},
+ url='/mod/users/{}/privilege/'.format(self.user.username))
assert response.status == '302 FOUND'
self.query_for_users()
- assert not self.user.has_privilege(u'commenter')
+ assert not self.user.has_privilege('commenter')
# Then, test an admin giving a privilege to a user
#----------------------------------------------------------------------
- response, context = self.do_post({'privilege_name':u'commenter'},
- url='/mod/users/{0}/privilege/'.format(self.user.username))
+ response, context = self.do_post({'privilege_name':'commenter'},
+ url='/mod/users/{}/privilege/'.format(self.user.username))
assert response.status == '302 FOUND'
self.query_for_users()
- assert self.user.has_privilege(u'commenter')
+ assert self.user.has_privilege('commenter')
# Then, test a mod trying to take away a privilege from a user
# they are not allowed to do this, so this will raise an error
#----------------------------------------------------------------------
self.logout()
- self.login(u'moderator')
+ self.login('moderator')
with pytest.raises(AppError) as excinfo:
- response, context = self.do_post({'privilege_name':u'commenter'},
- url='/mod/users/{0}/privilege/'.format(self.user.username))
+ response, context = self.do_post({'privilege_name':'commenter'},
+ url='/mod/users/{}/privilege/'.format(self.user.username))
assert 'Bad response: 403 FORBIDDEN' in str(excinfo)
self.query_for_users()
- assert self.user.has_privilege(u'commenter')
+ assert self.user.has_privilege('commenter')
def testReportResolution(self):
- self.login(u'moderator')
+ self.login('moderator')
# First, test a moderators taking away a user's privilege in response
# to a reported comment
@@ -106,23 +106,23 @@ class TestModerationViews:
comment_report = Report.query.filter(
Report.reported_user==self.user).first()
- response = self.test_app.get('/mod/reports/{0}/'.format(
+ response = self.test_app.get('/mod/reports/{}/'.format(
comment_report.id))
assert response.status == '200 OK'
self.query_for_users()
comment_report = Report.query.filter(
Report.reported_user==self.user).first()
- response, context = self.do_post({'action_to_resolve':[u'takeaway'],
- 'take_away_privileges':[u'commenter'],
+ response, context = self.do_post({'action_to_resolve':['takeaway'],
+ 'take_away_privileges':['commenter'],
'targeted_user':self.user.id},
- url='/mod/reports/{0}/'.format(comment_report.id))
+ url='/mod/reports/{}/'.format(comment_report.id))
self.query_for_users()
comment_report = Report.query.filter(
Report.reported_user==self.user).first()
assert response.status == '302 FOUND'
- assert not self.user.has_privilege(u'commenter')
+ assert not self.user.has_privilege('commenter')
assert comment_report.is_archived_report() is True
fixture_add_comment_report(reported_user=self.user)
@@ -134,16 +134,16 @@ class TestModerationViews:
#----------------------------------------------------------------------
self.query_for_users()
- response, context = self.do_post({'action_to_resolve':[u'sendmessage'],
+ response, context = self.do_post({'action_to_resolve':['sendmessage'],
'message_to_user':'This is your last warning, regular....',
'targeted_user':self.user.id},
- url='/mod/reports/{0}/'.format(comment_report.id))
+ url='/mod/reports/{}/'.format(comment_report.id))
self.query_for_users()
comment_report = Report.query.filter(
Report.reported_user==self.user).first()
assert response.status == '302 FOUND'
- assert mail.EMAIL_TEST_MBOX_INBOX == [{'to': [u'regular@example.com'],
+ assert mail.EMAIL_TEST_MBOX_INBOX == [{'to': ['regular@example.com'],
'message': 'Content-Type: text/plain; charset="utf-8"\n\
MIME-Version: 1.0\nContent-Transfer-Encoding: base64\nSubject: Warning from- \
moderator \nFrom: notice@mediagoblin.example.org\nTo: regular@example.com\n\n\
@@ -157,7 +157,7 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
#----------------------------------------------------------------------
self.query_for_users()
fixture_add_comment(author=self.user.id,
- comment=u'Comment will be removed')
+ comment='Comment will be removed')
test_comment = TextComment.query.filter(
TextComment.actor==self.user.id).first()
fixture_add_comment_report(comment=test_comment,
@@ -171,11 +171,11 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
Report.resolved==None).first()
response, context = self.do_post(
- {'action_to_resolve':[u'userban', u'delete'],
+ {'action_to_resolve':['userban', 'delete'],
'targeted_user':self.user.id,
- 'why_user_was_banned':u'',
- 'user_banned_until':u''},
- url='/mod/reports/{0}/'.format(comment_report.id))
+ 'why_user_was_banned':'',
+ 'user_banned_until':''},
+ url='/mod/reports/{}/'.format(comment_report.id))
assert response.status == '302 FOUND'
self.query_for_users()
test_user_ban = UserBan.query.filter(
@@ -193,17 +193,17 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
Report.reported_user==self.admin_user).filter(
Report.resolved==None).first()
- response, context = self.do_post({'action_to_resolve':[u'takeaway'],
- 'take_away_privileges':[u'active'],
+ response, context = self.do_post({'action_to_resolve':['takeaway'],
+ 'take_away_privileges':['active'],
'targeted_user':self.admin_user.id},
- url='/mod/reports/{0}/'.format(comment_report.id))
+ url='/mod/reports/{}/'.format(comment_report.id))
self.query_for_users()
assert response.status == '200 OK'
- assert self.admin_user.has_privilege(u'active')
+ assert self.admin_user.has_privilege('active')
def testAllModerationViews(self):
- self.login(u'moderator')
+ self.login('moderator')
username = self.user.username
self.query_for_users()
fixture_add_comment_report(reported_user=self.admin_user)
@@ -216,7 +216,7 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
response = self.test_app.get('/mod/users/')
assert response.status == "200 OK"
- user_page_url = '/mod/users/{0}/'.format(username)
+ user_page_url = '/mod/users/{}/'.format(username)
response = self.test_app.get(user_page_url)
assert response.status == "200 OK"
@@ -224,20 +224,20 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
assert response.status == "200 OK"
def testBanUnBanUser(self):
- self.login(u'admin')
+ self.login('admin')
username = self.user.username
user_id = self.user.id
- ban_url = '/mod/users/{0}/ban/'.format(username)
+ ban_url = '/mod/users/{}/ban/'.format(username)
response, context = self.do_post({
- 'user_banned_until':u'',
- 'why_user_was_banned':u'Because I said so'},
+ 'user_banned_until':'',
+ 'why_user_was_banned':'Because I said so'},
url=ban_url)
assert response.status == "302 FOUND"
user_banned = UserBan.query.filter(UserBan.user_id==user_id).first()
assert user_banned is not None
assert user_banned.expiration_date is None
- assert user_banned.reason == u'Because I said so'
+ assert user_banned.reason == 'Because I said so'
response, context = self.do_post({},
url=ban_url)
diff --git a/mediagoblin/tests/test_notifications.py b/mediagoblin/tests/test_notifications.py
index 776bfc71..2bdc4223 100644
--- a/mediagoblin/tests/test_notifications.py
+++ b/mediagoblin/tests/test_notifications.py
@@ -37,13 +37,13 @@ class TestNotifications:
# TODO: Possibly abstract into a decorator like:
# @as_authenticated_user('chris')
- self.test_user = fixture_add_user(privileges=[u'active',u'commenter'])
+ self.test_user = fixture_add_user(privileges=['active','commenter'])
self.current_user = None
self.login()
- def login(self, username=u'chris', password=u'toast'):
+ def login(self, username='chris', password='toast'):
response = self.test_app.post(
'/auth/login/', {
'username': username,
@@ -75,13 +75,13 @@ class TestNotifications:
'''
user = fixture_add_user('otherperson', password='nosreprehto',
wants_comment_notification=wants_email,
- privileges=[u'active',u'commenter'])
+ privileges=['active','commenter'])
assert user.wants_comment_notification == wants_email
user_id = user.id
- media_entry = fixture_media_entry(uploader=user.id, state=u'processed')
+ media_entry = fixture_media_entry(uploader=user.id, state='processed')
media_entry_id = media_entry.id
@@ -89,15 +89,15 @@ class TestNotifications:
subscription_id = subscription.id
- media_uri_id = '/u/{0}/m/{1}/'.format(user.username,
+ media_uri_id = '/u/{}/m/{}/'.format(user.username,
media_entry.id)
- media_uri_slug = '/u/{0}/m/{1}/'.format(user.username,
+ media_uri_slug = '/u/{}/m/{}/'.format(user.username,
media_entry.slug)
self.test_app.post(
media_uri_id + 'comment/add/',
{
- 'comment_content': u'Test comment #42'
+ 'comment_content': 'Test comment #42'
}
)
@@ -111,7 +111,7 @@ class TestNotifications:
assert notification.seen == False
assert notification.user_id == user.id
assert notification.obj().comment().get_actor.id == self.test_user.id
- assert notification.obj().comment().content == u'Test comment #42'
+ assert notification.obj().comment().content == 'Test comment #42'
if wants_email == True:
# Why the `or' here? In Werkzeug 0.11.0 and above
@@ -127,7 +127,7 @@ charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: \
base64\nSubject: GNU MediaGoblin - chris commented on your \
post\nFrom: notice@mediagoblin.example.org\nTo: \
otherperson@example.com\n\nSGkgb3RoZXJwZXJzb24sCmNocmlzIGNvbW1lbnRlZCBvbiB5b3VyIHBvc3QgKGh0dHA6Ly9sb2Nh\nbGhvc3Q6ODAvdS9vdGhlcnBlcnNvbi9tL3NvbWUtdGl0bGUvYy8xLyNjb21tZW50KSBhdCBHTlUg\nTWVkaWFHb2JsaW4KClRlc3QgY29tbWVudCAjNDIKCkdOVSBNZWRpYUdvYmxpbg==\n',
- 'to': [u'otherperson@example.com']}]
+ 'to': ['otherperson@example.com']}]
or mail.EMAIL_TEST_MBOX_INBOX == [
{'from': 'notice@mediagoblin.example.org',
'message': 'Content-Type: text/plain; \
@@ -135,7 +135,7 @@ charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: \
base64\nSubject: GNU MediaGoblin - chris commented on your \
post\nFrom: notice@mediagoblin.example.org\nTo: \
otherperson@example.com\n\nSGkgb3RoZXJwZXJzb24sCmNocmlzIGNvbW1lbnRlZCBvbiB5b3VyIHBvc3QgKGh0dHA6Ly9sb2Nh\nbGhvc3QvdS9vdGhlcnBlcnNvbi9tL3NvbWUtdGl0bGUvYy8xLyNjb21tZW50KSBhdCBHTlUgTWVk\naWFHb2JsaW4KClRlc3QgY29tbWVudCAjNDIKCkdOVSBNZWRpYUdvYmxpbg==\n',
- 'to': [u'otherperson@example.com']}])
+ 'to': ['otherperson@example.com']}])
else:
assert mail.EMAIL_TEST_MBOX_INBOX == []
@@ -147,7 +147,7 @@ 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/{}/'.format(comment_id))
notification = Notification.query.filter_by(id=notification_id).first()
@@ -170,27 +170,27 @@ otherperson@example.com\n\nSGkgb3RoZXJwZXJzb24sCmNocmlzIGNvbW1lbnRlZCBvbiB5b3VyI
""" Test that mark_all_comments_seen works"""
user = fixture_add_user('otherperson', password='nosreprehto',
- privileges=[u'active'])
+ privileges=['active'])
- media_entry = fixture_media_entry(uploader=user.id, state=u'processed')
+ media_entry = fixture_media_entry(uploader=user.id, state='processed')
fixture_comment_subscription(media_entry)
- media_uri_id = '/u/{0}/m/{1}/'.format(user.username,
+ media_uri_id = '/u/{}/m/{}/'.format(user.username,
media_entry.id)
# add 2 comments
self.test_app.post(
media_uri_id + 'comment/add/',
{
- 'comment_content': u'Test comment #43'
+ 'comment_content': 'Test comment #43'
}
)
self.test_app.post(
media_uri_id + 'comment/add/',
{
- 'comment_content': u'Test comment #44'
+ 'comment_content': 'Test comment #44'
}
)
diff --git a/mediagoblin/tests/test_oauth1.py b/mediagoblin/tests/test_oauth1.py
index e41a68c7..fc4a2b01 100644
--- a/mediagoblin/tests/test_oauth1.py
+++ b/mediagoblin/tests/test_oauth1.py
@@ -25,7 +25,7 @@ from mediagoblin.tools import template, pluginapi
from mediagoblin.tests.tools import fixture_add_user
-class TestOAuth(object):
+class TestOAuth:
MIME_FORM = "application/x-www-form-urlencoded"
MIME_JSON = "application/json"
@@ -123,7 +123,7 @@ class TestOAuth(object):
def to_authorize_headers(self, data):
headers = ""
for key, value in data.items():
- headers += '{0}="{1}",'.format(key, value)
+ headers += '{}="{}",'.format(key, value)
return {"Authorization": "OAuth " + headers[:-1]}
def test_request_token(self):
diff --git a/mediagoblin/tests/test_openid.py b/mediagoblin/tests/test_openid.py
index 71767032..a0d129a9 100644
--- a/mediagoblin/tests/test_openid.py
+++ b/mediagoblin/tests/test_openid.py
@@ -19,7 +19,7 @@ import pytest
import six
import six.moves.urllib.parse as urlparse
try:
- import mock
+ from unittest import mock
except ImportError:
import unittest.mock as mock
@@ -44,14 +44,14 @@ def openid_plugin_app(request):
'openid_appconfig.ini'))
-class TestOpenIDPlugin(object):
+class TestOpenIDPlugin:
def _setup(self, openid_plugin_app, value=True, edit=False, delete=False):
if value:
response = openid_consumer.SuccessResponse(mock.Mock(), mock.Mock())
if edit or delete:
- response.identity_url = u'http://add.myopenid.com'
+ response.identity_url = 'http://add.myopenid.com'
else:
- response.identity_url = u'http://real.myopenid.com'
+ response.identity_url = 'http://real.myopenid.com'
self._finish_verification = mock.Mock(return_value=response)
else:
self._finish_verification = mock.Mock(return_value=False)
@@ -113,7 +113,7 @@ class TestOpenIDPlugin(object):
'/auth/openid/login/', {})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/openid/login.html']
form = context['login_form']
- assert form.openid.errors == [u'This field is required.']
+ assert form.openid.errors == ['This field is required.']
# Try to login with wrong form values
template.clear_test_template_context()
@@ -122,7 +122,7 @@ class TestOpenIDPlugin(object):
'openid': 'not_a_url.com'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/openid/login.html']
form = context['login_form']
- assert form.openid.errors == [u'Please enter a valid url.']
+ assert form.openid.errors == ['Please enter a valid url.']
# Should be no users in the db
assert User.query.count() == 0
@@ -134,7 +134,7 @@ class TestOpenIDPlugin(object):
'openid': 'http://phoney.myopenid.com/'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/openid/login.html']
form = context['login_form']
- assert form.openid.errors == [u'Sorry, the OpenID server could not be found']
+ assert form.openid.errors == ['Sorry, the OpenID server could not be found']
def test_login(self, openid_plugin_app):
"""Tests that test login and registion with openid"""
@@ -165,7 +165,7 @@ class TestOpenIDPlugin(object):
def _test_new_user():
openid_plugin_app.post(
'/auth/openid/login/', {
- 'openid': u'http://real.myopenid.com'})
+ 'openid': 'http://real.myopenid.com'})
# Right place?
assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
@@ -176,8 +176,8 @@ class TestOpenIDPlugin(object):
res = openid_plugin_app.post(
'/auth/openid/register/', {
'openid': register_form.openid.data,
- 'username': u'chris',
- 'email': u'chris@example.com'})
+ 'username': 'chris',
+ 'email': 'chris@example.com'})
res.follow()
# Correct place?
@@ -193,7 +193,7 @@ class TestOpenIDPlugin(object):
# Get user and detach from session
test_user = mg_globals.database.LocalUser.query.filter(
- LocalUser.username==u'chris'
+ LocalUser.username=='chris'
).first()
Session.expunge(test_user)
@@ -202,7 +202,7 @@ class TestOpenIDPlugin(object):
template.clear_test_template_context()
res = openid_plugin_app.post(
'/auth/openid/login/finish/', {
- 'openid': u'http://real.myopenid.com'})
+ 'openid': 'http://real.myopenid.com'})
res.follow()
assert urlparse.urlsplit(res.location)[2] == '/'
@@ -211,7 +211,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'] == six.text_type(test_user.id)
+ assert session['user_id'] == str(test_user.id)
_test_new_user()
@@ -222,9 +222,9 @@ class TestOpenIDPlugin(object):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
register_form = context['register_form']
- assert register_form.openid.errors == [u'This field is required.']
- assert register_form.email.errors == [u'This field is required.']
- assert register_form.username.errors == [u'This field is required.']
+ assert register_form.openid.errors == ['This field is required.']
+ assert register_form.email.errors == ['This field is required.']
+ assert register_form.username.errors == ['This field is required.']
# Try to register with existing username and email
template.clear_test_template_context()
@@ -236,14 +236,14 @@ class TestOpenIDPlugin(object):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
register_form = context['register_form']
- assert register_form.username.errors == [u'Sorry, a user with that name already exists.']
- assert register_form.email.errors == [u'Sorry, a user with that email address already exists.']
- assert register_form.openid.errors == [u'Sorry, an account is already registered to that OpenID.']
+ assert register_form.username.errors == ['Sorry, a user with that name already exists.']
+ assert register_form.email.errors == ['Sorry, a user with that email address already exists.']
+ assert register_form.openid.errors == ['Sorry, an account is already registered to that OpenID.']
def test_add_delete(self, openid_plugin_app):
"""Test adding and deleting openids"""
# Add user
- test_user = fixture_add_user(password='', privileges=[u'active'])
+ test_user = fixture_add_user(password='', privileges=['active'])
openid = OpenIDUserURL()
openid.openid_url = 'http://real.myopenid.com'
openid.user_id = test_user.id
@@ -258,7 +258,7 @@ class TestOpenIDPlugin(object):
def _login_user():
openid_plugin_app.post(
'/auth/openid/login/finish/', {
- 'openid': u'http://real.myopenid.com'})
+ 'openid': 'http://real.myopenid.com'})
_login_user()
@@ -276,16 +276,16 @@ class TestOpenIDPlugin(object):
'/edit/openid/', {})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/openid/add.html']
form = context['form']
- assert form.openid.errors == [u'This field is required.']
+ assert form.openid.errors == ['This field is required.']
# Try with a bad url
template.clear_test_template_context()
openid_plugin_app.post(
'/edit/openid/', {
- 'openid': u'not_a_url.com'})
+ 'openid': 'not_a_url.com'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/openid/add.html']
form = context['form']
- assert form.openid.errors == [u'Please enter a valid url.']
+ assert form.openid.errors == ['Please enter a valid url.']
# Try with a url that's already registered
template.clear_test_template_context()
@@ -294,7 +294,7 @@ class TestOpenIDPlugin(object):
'openid': 'http://real.myopenid.com'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/openid/add.html']
form = context['form']
- assert form.openid.errors == [u'Sorry, an account is already registered to that OpenID.']
+ assert form.openid.errors == ['Sorry, an account is already registered to that OpenID.']
# Test adding openid to account
# Need to clear_test_template_context before calling _setup
@@ -303,7 +303,7 @@ class TestOpenIDPlugin(object):
# Need to remove openid_url from db because it was added at setup
openid = OpenIDUserURL.query.filter_by(
- openid_url=u'http://add.myopenid.com')
+ openid_url='http://add.myopenid.com')
openid.delete()
@mock.patch('mediagoblin.plugins.openid.views._finish_verification', self._finish_verification)
@@ -313,7 +313,7 @@ class TestOpenIDPlugin(object):
template.clear_test_template_context()
res = openid_plugin_app.post(
'/edit/openid/', {
- 'openid': u'http://add.myopenid.com'})
+ 'openid': 'http://add.myopenid.com'})
res.follow()
# Correct place?
@@ -322,7 +322,7 @@ class TestOpenIDPlugin(object):
# OpenID Added?
new_openid = mg_globals.database.OpenIDUserURL.query.filter_by(
- openid_url=u'http://add.myopenid.com').first()
+ openid_url='http://add.myopenid.com').first()
assert new_openid
_test_add()
@@ -357,14 +357,14 @@ class TestOpenIDPlugin(object):
'openid': 'http://realfake.myopenid.com/'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/openid/delete.html']
form = context['form']
- assert form.openid.errors == [u'That OpenID is not registered to this account.']
+ assert form.openid.errors == ['That OpenID is not registered to this account.']
# Delete OpenID
# Kind of weird to POST to delete/finish
template.clear_test_template_context()
res = openid_plugin_app.post(
'/edit/openid/delete/finish/', {
- 'openid': u'http://add.myopenid.com'})
+ 'openid': 'http://add.myopenid.com'})
res.follow()
# Correct place?
@@ -373,7 +373,7 @@ class TestOpenIDPlugin(object):
# OpenID deleted?
new_openid = mg_globals.database.OpenIDUserURL.query.filter_by(
- openid_url=u'http://add.myopenid.com').first()
+ openid_url='http://add.myopenid.com').first()
assert not new_openid
_test_delete(self, test_user)
diff --git a/mediagoblin/tests/test_persona.py b/mediagoblin/tests/test_persona.py
index 437cb7a1..25f0ca1e 100644
--- a/mediagoblin/tests/test_persona.py
+++ b/mediagoblin/tests/test_persona.py
@@ -18,7 +18,7 @@ import pkg_resources
import pytest
import six
try:
- import mock
+ from unittest import mock
except ImportError:
import unittest.mock as mock
@@ -43,7 +43,7 @@ def persona_plugin_app(request):
'persona_appconfig.ini'))
-class TestPersonaPlugin(object):
+class TestPersonaPlugin:
def test_authentication_views(self, persona_plugin_app):
res = persona_plugin_app.get('/auth/login/')
@@ -61,7 +61,7 @@ class TestPersonaPlugin(object):
assert urlparse.urlsplit(res.location)[2] == '/auth/login/'
- @mock.patch('mediagoblin.plugins.persona.views._get_response', mock.Mock(return_value=u'test@example.com'))
+ @mock.patch('mediagoblin.plugins.persona.views._get_response', mock.Mock(return_value='test@example.com'))
def _test_registration():
# No register users
template.clear_test_template_context()
@@ -72,8 +72,8 @@ class TestPersonaPlugin(object):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
register_form = context['register_form']
- assert register_form.email.data == u'test@example.com'
- assert register_form.persona_email.data == u'test@example.com'
+ assert register_form.email.data == 'test@example.com'
+ assert register_form.persona_email.data == 'test@example.com'
template.clear_test_template_context()
res = persona_plugin_app.post(
@@ -83,9 +83,9 @@ class TestPersonaPlugin(object):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
register_form = context['register_form']
- assert register_form.username.errors == [u'This field is required.']
- assert register_form.email.errors == [u'This field is required.']
- assert register_form.persona_email.errors == [u'This field is required.']
+ assert register_form.username.errors == ['This field is required.']
+ assert register_form.email.errors == ['This field is required.']
+ assert register_form.persona_email.errors == ['This field is required.']
# Successful register
template.clear_test_template_context()
@@ -111,21 +111,21 @@ class TestPersonaPlugin(object):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
register_form = context['register_form']
- assert register_form.persona_email.errors == [u'Sorry, an account is already registered to that Persona email.']
+ assert register_form.persona_email.errors == ['Sorry, an account is already registered to that Persona email.']
# Logout
persona_plugin_app.get('/auth/logout/')
# Get user and detach from session
test_user = mg_globals.database.LocalUser.query.filter(
- LocalUser.username==u'chris'
+ LocalUser.username=='chris'
).first()
active_privilege = Privilege.query.filter(
- Privilege.privilege_name==u'active').first()
+ Privilege.privilege_name=='active').first()
test_user.all_privileges.append(active_privilege)
test_user.save()
test_user = mg_globals.database.LocalUser.query.filter(
- LocalUser.username==u'chris'
+ LocalUser.username=='chris'
).first()
Session.expunge(test_user)
@@ -148,11 +148,11 @@ 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'] == six.text_type(test_user.id)
+ assert session['user_id'] == str(test_user.id)
_test_registration()
- @mock.patch('mediagoblin.plugins.persona.views._get_response', mock.Mock(return_value=u'new@example.com'))
+ @mock.patch('mediagoblin.plugins.persona.views._get_response', mock.Mock(return_value='new@example.com'))
def _test_edit_persona():
# Try and delete only Persona email address
template.clear_test_template_context()
@@ -164,7 +164,7 @@ class TestPersonaPlugin(object):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/persona/edit.html']
form = context['form']
- assert form.email.errors == [u"You can't delete your only Persona email address unless you have a password set."]
+ assert form.email.errors == ["You can't delete your only Persona email address unless you have a password set."]
template.clear_test_template_context()
res = persona_plugin_app.post(
@@ -174,7 +174,7 @@ class TestPersonaPlugin(object):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/persona/edit.html']
form = context['form']
- assert form.email.errors == [u'This field is required.']
+ assert form.email.errors == ['This field is required.']
# Try and delete Persona not owned by the user
template.clear_test_template_context()
@@ -186,7 +186,7 @@ class TestPersonaPlugin(object):
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/persona/edit.html']
form = context['form']
- assert form.email.errors == [u'That Persona email address is not registered to this account.']
+ assert form.email.errors == ['That Persona email address is not registered to this account.']
res = persona_plugin_app.get('/edit/persona/add/')
@@ -210,7 +210,7 @@ class TestPersonaPlugin(object):
_test_edit_persona()
- @mock.patch('mediagoblin.plugins.persona.views._get_response', mock.Mock(return_value=u'test1@example.com'))
+ @mock.patch('mediagoblin.plugins.persona.views._get_response', mock.Mock(return_value='test1@example.com'))
def _test_add_existing():
template.clear_test_template_context()
res = persona_plugin_app.post(
diff --git a/mediagoblin/tests/test_piwigo.py b/mediagoblin/tests/test_piwigo.py
index 33aea580..c530d457 100644
--- a/mediagoblin/tests/test_piwigo.py
+++ b/mediagoblin/tests/test_piwigo.py
@@ -21,14 +21,14 @@ from .tools import fixture_add_user
XML_PREFIX = "<?xml version='1.0' encoding='utf-8'?>\n"
-class Test_PWG(object):
+class Test_PWG:
@pytest.fixture(autouse=True)
def setup(self, test_app):
self.test_app = test_app
fixture_add_user()
- self.username = u"chris"
+ self.username = "chris"
self.password = "toast"
def do_post(self, method, params):
@@ -43,7 +43,7 @@ class Test_PWG(object):
def test_session(self):
resp = self.do_post("pwg.session.login",
- {"username": u"nouser", "password": "wrong"})
+ {"username": "nouser", "password": "wrong"})
assert resp.body == (XML_PREFIX + '<rsp stat="fail"><err code="999" msg="Invalid username/password"/></rsp>').encode('ascii')
resp = self.do_post("pwg.session.login",
diff --git a/mediagoblin/tests/test_pluginapi.py b/mediagoblin/tests/test_pluginapi.py
index 2fd6df39..4762f3f8 100644
--- a/mediagoblin/tests/test_pluginapi.py
+++ b/mediagoblin/tests/test_pluginapi.py
@@ -402,7 +402,7 @@ def test_plugin_assetlink(static_plugin_app):
# link dir doesn't exist, link it
result = run_assetlink().collection[0]
assert result == \
- 'Linked asset directory for plugin "staticstuff":\n %s\nto:\n %s\n' % (
+ 'Linked asset directory for plugin "staticstuff":\n {}\nto:\n {}\n'.format(
plugin_static.file_path.rstrip(os.path.sep),
plugin_link_dir)
assert os.path.lexists(plugin_link_dir)
@@ -430,10 +430,10 @@ def test_plugin_assetlink(static_plugin_app):
result = run_assetlink().combined_string
assert result == """Old link found for "staticstuff"; removing.
Linked asset directory for plugin "staticstuff":
- %s
+ {}
to:
- %s
-""" % (plugin_static.file_path.rstrip(os.path.sep), plugin_link_dir)
+ {}
+""".format(plugin_static.file_path.rstrip(os.path.sep), plugin_link_dir)
assert os.path.lexists(plugin_link_dir)
assert os.path.islink(plugin_link_dir)
assert os.path.realpath(plugin_link_dir) == plugin_static.file_path
@@ -447,7 +447,7 @@ to:
assert result == 'Could not link "staticstuff": %s exists and is not a symlink\n' % (
plugin_link_dir)
- with open(plugin_link_dir, 'r') as clobber_file:
+ with open(plugin_link_dir) as clobber_file:
assert clobber_file.read() == 'clobbered!'
diff --git a/mediagoblin/tests/test_privileges.py b/mediagoblin/tests/test_privileges.py
index 2e0b7347..b7a9ff3b 100644
--- a/mediagoblin/tests/test_privileges.py
+++ b/mediagoblin/tests/test_privileges.py
@@ -32,12 +32,12 @@ class TestPrivilegeFunctionality:
def _setup(self, test_app):
self.test_app = test_app
- fixture_add_user(u'alex',
- privileges=[u'admin',u'active'])
- fixture_add_user(u'meow',
- privileges=[u'moderator',u'active',u'reporter'])
- fixture_add_user(u'natalie',
- privileges=[u'active'])
+ fixture_add_user('alex',
+ privileges=['admin','active'])
+ fixture_add_user('meow',
+ privileges=['moderator','active','reporter'])
+ fixture_add_user('natalie',
+ privileges=['active'])
self.query_for_users()
def login(self, username):
@@ -64,17 +64,17 @@ class TestPrivilegeFunctionality:
return response, context_data
def query_for_users(self):
- self.admin_user = LocalUser.query.filter(LocalUser.username==u'alex').first()
- self.mod_user = LocalUser.query.filter(LocalUser.username==u'meow').first()
- self.user = LocalUser.query.filter(LocalUser.username==u'natalie').first()
+ self.admin_user = LocalUser.query.filter(LocalUser.username=='alex').first()
+ self.mod_user = LocalUser.query.filter(LocalUser.username=='meow').first()
+ self.user = LocalUser.query.filter(LocalUser.username=='natalie').first()
def testUserBanned(self):
- self.login(u'natalie')
+ self.login('natalie')
uid = self.user.id
# First, test what happens when a user is banned indefinitely
#----------------------------------------------------------------------
user_ban = UserBan(user_id=uid,
- reason=u'Testing whether user is banned',
+ reason='Testing whether user is banned',
expiration_date=None)
user_ban.save()
@@ -87,7 +87,7 @@ class TestPrivilegeFunctionality:
user_ban = UserBan.query.get(uid)
user_ban.delete()
user_ban = UserBan(user_id=uid,
- reason=u'Testing whether user is banned',
+ reason='Testing whether user is banned',
expiration_date= date.today() + timedelta(days=20))
user_ban.save()
@@ -102,7 +102,7 @@ class TestPrivilegeFunctionality:
user_ban.delete()
exp_date = date.today() - timedelta(days=20)
user_ban = UserBan(user_id=uid,
- reason=u'Testing whether user is banned',
+ reason='Testing whether user is banned',
expiration_date= exp_date)
user_ban.save()
@@ -122,7 +122,7 @@ class TestPrivilegeFunctionality:
# tests/test_reporting.py reporter
# tests/test_submission.py uploader
#----------------------------------------------------------------------
- self.login(u'natalie')
+ self.login('natalie')
# First test the get and post requests of submission/uploading
#----------------------------------------------------------------------
@@ -134,7 +134,7 @@ class TestPrivilegeFunctionality:
with pytest.raises(AppError) as excinfo:
response = self.do_post({'upload_files':[('file',GOOD_JPG)],
- 'title':u'Normal Upload 1'},
+ 'title':'Normal Upload 1'},
url='/submit/')
excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii')
assert b'Bad response: 403 FORBIDDEN' in excinfo
@@ -144,12 +144,12 @@ class TestPrivilegeFunctionality:
self.query_for_users()
media_entry = fixture_media_entry(uploader=self.admin_user.id,
- state=u'processed')
+ state='processed')
media_entry_id = media_entry.id
- media_uri_id = '/u/{0}/m/{1}/'.format(self.admin_user.username,
+ media_uri_id = '/u/{}/m/{}/'.format(self.admin_user.username,
media_entry.id)
- media_uri_slug = '/u/{0}/m/{1}/'.format(self.admin_user.username,
+ media_uri_slug = '/u/{}/m/{}/'.format(self.admin_user.username,
media_entry.slug)
response = self.test_app.get(media_uri_slug)
assert not b"Add a comment" in response.body
@@ -158,7 +158,7 @@ class TestPrivilegeFunctionality:
with pytest.raises(AppError) as excinfo:
response = self.test_app.post(
media_uri_id + 'comment/add/',
- {'comment_content': u'Test comment #42'})
+ {'comment_content': 'Test comment #42'})
excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii')
assert b'Bad response: 403 FORBIDDEN' in excinfo
@@ -171,8 +171,8 @@ class TestPrivilegeFunctionality:
with pytest.raises(AppError) as excinfo:
response = self.do_post(
- {'report_reason':u'Testing Reports #1',
- 'reporter_id':u'3'},
+ {'report_reason':'Testing Reports #1',
+ 'reporter_id':'3'},
url=(media_uri_slug+"report/"))
excinfo = str(excinfo) if six.PY2 else str(excinfo).encode('ascii')
assert b'Bad response: 403 FORBIDDEN' in excinfo
@@ -208,8 +208,8 @@ class TestPrivilegeFunctionality:
self.query_for_users()
with pytest.raises(AppError) as excinfo:
- response, context = self.do_post({'action_to_resolve':[u'takeaway'],
- 'take_away_privileges':[u'active'],
+ response, context = self.do_post({'action_to_resolve':['takeaway'],
+ 'take_away_privileges':['active'],
'targeted_user':self.admin_user.id},
url='/mod/reports/1/')
self.query_for_users()
diff --git a/mediagoblin/tests/test_processing.py b/mediagoblin/tests/test_processing.py
index 591add96..ffbdbbc2 100644
--- a/mediagoblin/tests/test_processing.py
+++ b/mediagoblin/tests/test_processing.py
@@ -2,7 +2,7 @@
from mediagoblin import processing
-class TestProcessing(object):
+class TestProcessing:
def run_fill(self, input, format, output=None):
builder = processing.FilenameBuilder(input)
result = builder.fill(format)
@@ -14,5 +14,5 @@ class TestProcessing(object):
self.run_fill('/home/user/foo.TXT', '{basename}bar{ext}', 'foobar.txt')
def test_long_filename_fill(self):
- self.run_fill('{0}.png'.format('A' * 300), 'image-{basename}{ext}',
- 'image-{0}.png'.format('A' * 245))
+ self.run_fill('{}.png'.format('A' * 300), 'image-{basename}{ext}',
+ 'image-{}.png'.format('A' * 245))
diff --git a/mediagoblin/tests/test_reporting.py b/mediagoblin/tests/test_reporting.py
index 803fc849..a59ea28e 100644
--- a/mediagoblin/tests/test_reporting.py
+++ b/mediagoblin/tests/test_reporting.py
@@ -28,10 +28,10 @@ class TestReportFiling:
def _setup(self, test_app):
self.test_app = test_app
- fixture_add_user(u'allie',
- privileges=[u'reporter',u'active'])
- fixture_add_user(u'natalie',
- privileges=[u'active', u'moderator'])
+ fixture_add_user('allie',
+ privileges=['reporter','active'])
+ fixture_add_user('natalie',
+ privileges=['active', 'moderator'])
def login(self, username):
self.test_app.post(
@@ -55,27 +55,27 @@ class TestReportFiling:
return response, context_data
def query_for_users(self):
- return (LocalUser.query.filter(LocalUser.username==u'allie').first(),
- LocalUser.query.filter(LocalUser.username==u'natalie').first())
+ return (LocalUser.query.filter(LocalUser.username=='allie').first(),
+ LocalUser.query.filter(LocalUser.username=='natalie').first())
def testMediaReports(self):
- self.login(u'allie')
+ self.login('allie')
allie_user, natalie_user = self.query_for_users()
allie_id = allie_user.id
media_entry = fixture_media_entry(uploader=natalie_user.id,
- state=u'processed')
+ state='processed')
mid = media_entry.id
- media_uri_slug = '/u/{0}/m/{1}/'.format(natalie_user.username,
+ media_uri_slug = '/u/{}/m/{}/'.format(natalie_user.username,
media_entry.slug)
response = self.test_app.get(media_uri_slug + "report/")
assert response.status == "200 OK"
response, context = self.do_post(
- {'report_reason':u'Testing Media Report',
- 'reporter_id':six.text_type(allie_id)},url= media_uri_slug + "report/")
+ {'report_reason':'Testing Media Report',
+ 'reporter_id':str(allie_id)},url= media_uri_slug + "report/")
assert response.status == "302 FOUND"
@@ -83,18 +83,18 @@ class TestReportFiling:
allie_user, natalie_user = self.query_for_users()
assert media_report is not None
- assert media_report.report_content == u'Testing Media Report'
+ assert media_report.report_content == 'Testing Media Report'
assert media_report.reporter_id == allie_id
assert media_report.reported_user_id == natalie_user.id
assert media_report.created is not None
def testCommentReports(self):
- self.login(u'allie')
+ self.login('allie')
allie_user, natalie_user = self.query_for_users()
allie_id = allie_user.id
media_entry = fixture_media_entry(uploader=natalie_user.id,
- state=u'processed')
+ state='processed')
mid = media_entry.id
fixture_add_comment(
media_entry=media_entry,
@@ -102,7 +102,7 @@ class TestReportFiling:
)
comment = TextComment.query.first()
- comment_uri_slug = '/u/{0}/m/{1}/c/{2}/'.format(natalie_user.username,
+ comment_uri_slug = '/u/{}/m/{}/c/{}/'.format(natalie_user.username,
media_entry.slug,
comment.id)
@@ -110,8 +110,8 @@ class TestReportFiling:
assert response.status == "200 OK"
response, context = self.do_post({
- 'report_reason':u'Testing Comment Report',
- 'reporter_id':six.text_type(allie_id)},url= comment_uri_slug + "report/")
+ 'report_reason':'Testing Comment Report',
+ 'reporter_id':str(allie_id)},url= comment_uri_slug + "report/")
assert response.status == "302 FOUND"
@@ -119,33 +119,33 @@ class TestReportFiling:
allie_user, natalie_user = self.query_for_users()
assert comment_report is not None
- assert comment_report.report_content == u'Testing Comment Report'
+ assert comment_report.report_content == 'Testing Comment Report'
assert comment_report.reporter_id == allie_id
assert comment_report.reported_user_id == natalie_user.id
assert comment_report.created is not None
def testArchivingReports(self):
- self.login(u'natalie')
+ self.login('natalie')
allie_user, natalie_user = self.query_for_users()
allie_id, natalie_id = allie_user.id, natalie_user.id
fixture_add_comment(author=allie_user.id,
- comment=u'Comment will be removed')
+ comment='Comment will be removed')
test_comment = TextComment.query.filter(
TextComment.actor==allie_user.id).first()
fixture_add_comment_report(comment=test_comment,
reported_user=allie_user,
- report_content=u'Testing Archived Reports #1',
+ report_content='Testing Archived Reports #1',
reporter=natalie_user)
comment_report = Report.query.filter(
Report.reported_user==allie_user).first()
- assert comment_report.report_content == u'Testing Archived Reports #1'
+ assert comment_report.report_content == 'Testing Archived Reports #1'
response, context = self.do_post(
- {'action_to_resolve':[u'userban', u'delete'],
+ {'action_to_resolve':['userban', 'delete'],
'targeted_user':allie_user.id,
- 'resolution_content':u'This is a test of archiving reports.'},
- url='/mod/reports/{0}/'.format(comment_report.id))
+ 'resolution_content':'This is a test of archiving reports.'},
+ url='/mod/reports/{}/'.format(comment_report.id))
assert response.status == "302 FOUND"
allie_user, natalie_user = self.query_for_users()
@@ -155,11 +155,11 @@ class TestReportFiling:
assert Report.query.count() != 0
assert archived_report is not None
- assert archived_report.report_content == u'Testing Archived Reports #1'
+ assert archived_report.report_content == 'Testing Archived Reports #1'
assert archived_report.reporter_id == natalie_id
assert archived_report.reported_user_id == allie_id
assert archived_report.created is not None
assert archived_report.resolved is not None
- assert archived_report.result == u'''This is a test of archiving reports.
+ assert archived_report.result == '''This is a test of archiving reports.
natalie banned user allie indefinitely.
natalie deleted the comment.'''
diff --git a/mediagoblin/tests/test_response.py b/mediagoblin/tests/test_response.py
index 7f929155..27a69d72 100644
--- a/mediagoblin/tests/test_response.py
+++ b/mediagoblin/tests/test_response.py
@@ -14,13 +14,12 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from __future__ import absolute_import, unicode_literals
from werkzeug.wrappers import Request
from ..tools.response import redirect, redirect_obj
-class TestRedirect(object):
+class TestRedirect:
def test_redirect_respects_location(self):
"""Test that redirect returns a 302 to location specified."""
request = Request({})
@@ -54,7 +53,7 @@ class TestRedirect(object):
# Using a mock obj here so that we're only testing redirect_obj itself,
# rather than also testing the url_for_self implementation.
- class Foo(object):
+ class Foo:
def url_for_self(*args, **kwargs):
return '/foo'
diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py
index ef6a9f5b..9bc9d8c4 100644
--- a/mediagoblin/tests/test_sql_migrations.py
+++ b/mediagoblin/tests/test_sql_migrations.py
@@ -195,7 +195,7 @@ def level_exits_new_table(db_conn):
for level in result:
- for exit_name, to_level in six.iteritems(level['exits']):
+ for exit_name, to_level in level['exits'].items():
# Insert the level exit
db_conn.execute(
level_exits.insert().values(
@@ -270,7 +270,7 @@ def creature_num_legs_to_num_limbs(db_conn):
creature_table = Table(
'creature', metadata,
autoload=True, autoload_with=db_conn.bind)
- creature_table.c.num_legs.alter(name=u"num_limbs")
+ creature_table.c.num_legs.alter(name="num_limbs")
@RegisterMigration(5, FULL_MIGRATIONS)
@@ -359,34 +359,34 @@ def _insert_migration1_objects(session):
"""
# Insert creatures
session.add_all(
- [Creature1(name=u'centipede',
+ [Creature1(name='centipede',
num_legs=100,
is_demon=False),
- Creature1(name=u'wolf',
+ Creature1(name='wolf',
num_legs=4,
is_demon=False),
# don't ask me what a wizardsnake is.
- Creature1(name=u'wizardsnake',
+ Creature1(name='wizardsnake',
num_legs=0,
is_demon=True)])
# Insert levels
session.add_all(
- [Level1(id=u'necroplex',
- name=u'The Necroplex',
- description=u'A complex full of pure deathzone.',
+ [Level1(id='necroplex',
+ name='The Necroplex',
+ description='A complex full of pure deathzone.',
exits={
- 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.',
+ 'deathwell': 'evilstorm',
+ 'portal': 'central_park'}),
+ Level1(id='evilstorm',
+ name='Evil Storm',
+ description='A storm full of pure evil.',
exits={}), # you can't escape the evilstorm
- Level1(id=u'central_park',
- name=u'Central Park, NY, NY',
- description=u"New York's friendly Central Park.",
+ Level1(id='central_park',
+ name='Central Park, NY, NY',
+ description="New York's friendly Central Park.",
exits={
- u'portal': u'necroplex'})])
+ 'portal': 'necroplex'})])
session.commit()
@@ -398,71 +398,71 @@ def _insert_migration2_objects(session):
# Insert creatures
session.add_all(
[Creature2(
- name=u'centipede',
+ name='centipede',
num_legs=100),
Creature2(
- name=u'wolf',
+ name='wolf',
num_legs=4,
magical_powers = [
CreaturePower2(
- name=u"ice breath",
- description=u"A blast of icy breath!",
+ name="ice breath",
+ description="A blast of icy breath!",
hitpower=20),
CreaturePower2(
- name=u"death stare",
- description=u"A frightening stare, for sure!",
+ name="death stare",
+ description="A frightening stare, for sure!",
hitpower=45)]),
Creature2(
- name=u'wizardsnake',
+ name='wizardsnake',
num_legs=0,
magical_powers=[
CreaturePower2(
- name=u'death_rattle',
- description=u'A rattle... of DEATH!',
+ name='death_rattle',
+ description='A rattle... of DEATH!',
hitpower=1000),
CreaturePower2(
- name=u'sneaky_stare',
- description=u"The sneakiest stare you've ever seen!",
+ name='sneaky_stare',
+ description="The sneakiest stare you've ever seen!",
hitpower=300),
CreaturePower2(
- name=u'slithery_smoke',
- description=u"A blast of slithery, slithery smoke.",
+ name='slithery_smoke',
+ description="A blast of slithery, slithery smoke.",
hitpower=10),
CreaturePower2(
- name=u'treacherous_tremors',
- description=u"The ground shakes beneath footed animals!",
+ name='treacherous_tremors',
+ description="The ground shakes beneath footed animals!",
hitpower=0)])])
# Insert levels
session.add_all(
- [Level2(id=u'necroplex',
- name=u'The Necroplex',
- description=u'A complex full of pure deathzone.'),
- Level2(id=u'evilstorm',
- name=u'Evil Storm',
- description=u'A storm full of pure evil.',
+ [Level2(id='necroplex',
+ name='The Necroplex',
+ description='A complex full of pure deathzone.'),
+ Level2(id='evilstorm',
+ name='Evil Storm',
+ description='A storm full of pure evil.',
exits=[]), # you can't escape the evilstorm
- Level2(id=u'central_park',
- name=u'Central Park, NY, NY',
- description=u"New York's friendly Central Park.")])
+ Level2(id='central_park',
+ name='Central Park, NY, NY',
+ description="New York's friendly Central Park.")])
# necroplex exits
session.add_all(
- [LevelExit2(name=u'deathwell',
- from_level=u'necroplex',
- to_level=u'evilstorm'),
- LevelExit2(name=u'portal',
- from_level=u'necroplex',
- to_level=u'central_park')])
+ [LevelExit2(name='deathwell',
+ from_level='necroplex',
+ to_level='evilstorm'),
+ LevelExit2(name='portal',
+ from_level='necroplex',
+ to_level='central_park')])
# there are no evilstorm exits because there is no exit from the
# evilstorm
# central park exits
session.add_all(
- [LevelExit2(name=u'portal',
- from_level=u'central_park',
- to_level=u'necroplex')])
+ [LevelExit2(name='portal',
+ from_level='central_park',
+ to_level='necroplex')])
session.commit()
@@ -474,80 +474,80 @@ def _insert_migration3_objects(session):
# Insert creatures
session.add_all(
[Creature3(
- name=u'centipede',
+ name='centipede',
num_limbs=100),
Creature3(
- name=u'wolf',
+ name='wolf',
num_limbs=4,
magical_powers = [
CreaturePower3(
- name=u"ice breath",
- description=u"A blast of icy breath!",
+ name="ice breath",
+ description="A blast of icy breath!",
hitpower=20.0),
CreaturePower3(
- name=u"death stare",
- description=u"A frightening stare, for sure!",
+ name="death stare",
+ description="A frightening stare, for sure!",
hitpower=45.0)]),
Creature3(
- name=u'wizardsnake',
+ name='wizardsnake',
num_limbs=0,
magical_powers=[
CreaturePower3(
- name=u'death_rattle',
- description=u'A rattle... of DEATH!',
+ name='death_rattle',
+ description='A rattle... of DEATH!',
hitpower=1000.0),
CreaturePower3(
- name=u'sneaky_stare',
- description=u"The sneakiest stare you've ever seen!",
+ name='sneaky_stare',
+ description="The sneakiest stare you've ever seen!",
hitpower=300.0),
CreaturePower3(
- name=u'slithery_smoke',
- description=u"A blast of slithery, slithery smoke.",
+ name='slithery_smoke',
+ description="A blast of slithery, slithery smoke.",
hitpower=10.0),
CreaturePower3(
- name=u'treacherous_tremors',
- description=u"The ground shakes beneath footed animals!",
+ name='treacherous_tremors',
+ description="The ground shakes beneath footed animals!",
hitpower=0.0)])],
# annnnnd one more to test a floating point hitpower
Creature3(
- name=u'deity',
+ name='deity',
numb_limbs=30,
magical_powers=[
CreaturePower3(
- name=u'smite',
- description=u'Smitten by holy wrath!',
+ name='smite',
+ description='Smitten by holy wrath!',
hitpower=9999.9)]))
# Insert levels
session.add_all(
- [Level3(id=u'necroplex',
- name=u'The Necroplex',
- description=u'A complex full of pure deathzone.'),
- Level3(id=u'evilstorm',
- name=u'Evil Storm',
- description=u'A storm full of pure evil.',
+ [Level3(id='necroplex',
+ name='The Necroplex',
+ description='A complex full of pure deathzone.'),
+ Level3(id='evilstorm',
+ name='Evil Storm',
+ description='A storm full of pure evil.',
exits=[]), # you can't escape the evilstorm
- Level3(id=u'central_park',
- name=u'Central Park, NY, NY',
- description=u"New York's friendly Central Park.")])
+ Level3(id='central_park',
+ name='Central Park, NY, NY',
+ description="New York's friendly Central Park.")])
# necroplex exits
session.add_all(
- [LevelExit3(name=u'deathwell',
- from_level=u'necroplex',
- to_level=u'evilstorm'),
- LevelExit3(name=u'portal',
- from_level=u'necroplex',
- to_level=u'central_park')])
+ [LevelExit3(name='deathwell',
+ from_level='necroplex',
+ to_level='evilstorm'),
+ LevelExit3(name='portal',
+ from_level='necroplex',
+ to_level='central_park')])
# there are no evilstorm exits because there is no exit from the
# evilstorm
# central park exits
session.add_all(
- [LevelExit3(name=u'portal',
- from_level=u'central_park',
- to_level=u'necroplex')])
+ [LevelExit3(name='portal',
+ from_level='central_park',
+ to_level='necroplex')])
session.commit()
@@ -563,10 +563,10 @@ def assert_col_type(column, this_class):
def _get_level3_exits(session, level):
- return dict(
- [(level_exit.name, level_exit.to_level)
+ return {
+ level_exit.name: level_exit.to_level
for level_exit in
- session.query(LevelExit3).filter_by(from_level=level.id)])
+ session.query(LevelExit3).filter_by(from_level=level.id)}
@pytest.mark.skipif(six.PY2, reason='Breaks in Python 2 but migrations seem to run ok')
@@ -581,7 +581,7 @@ def test_set1_to_set3():
printer = CollectingPrinter()
migration_manager = MigrationManager(
- u'__main__', SET1_MODELS, SET1_MIGRATIONS, Session(),
+ '__main__', SET1_MODELS, SET1_MIGRATIONS, Session(),
printer)
# Check latest migration and database current migration
@@ -591,7 +591,7 @@ def test_set1_to_set3():
result = migration_manager.init_or_migrate()
# Make sure output was "inited"
- assert result == u'inited'
+ assert result == 'inited'
# Check output
assert printer.combined_string == (
"-> Initializing main mediagoblin tables... done.\n")
@@ -607,7 +607,7 @@ def test_set1_to_set3():
# Try to "re-migrate" with same manager settings... nothing should happen
migration_manager = MigrationManager(
- u'__main__', SET1_MODELS, SET1_MIGRATIONS,
+ '__main__', SET1_MODELS, SET1_MIGRATIONS,
Session(), printer)
assert migration_manager.init_or_migrate() == None
@@ -622,8 +622,8 @@ def test_set1_to_set3():
creature_table = Table(
'creature', metadata,
autoload=True, autoload_with=engine)
- assert set(creature_table.c.keys()) == set(
- ['id', 'name', 'num_legs', 'is_demon'])
+ assert set(creature_table.c.keys()) == {
+ 'id', 'name', 'num_legs', 'is_demon'}
assert_col_type(creature_table.c.id, Integer)
assert_col_type(creature_table.c.name, VARCHAR)
assert creature_table.c.name.nullable is False
@@ -637,8 +637,8 @@ def test_set1_to_set3():
level_table = Table(
'level', metadata,
autoload=True, autoload_with=engine)
- assert set(level_table.c.keys()) == set(
- ['id', 'name', 'description', 'exits'])
+ assert set(level_table.c.keys()) == {
+ 'id', 'name', 'description', 'exits'}
assert_col_type(level_table.c.id, VARCHAR)
assert level_table.c.id.primary_key is True
assert_col_type(level_table.c.name, VARCHAR)
@@ -652,38 +652,38 @@ def test_set1_to_set3():
# Check the creation of the inserted rows on the creature and levels tables
creature = session.query(Creature1).filter_by(
- name=u'centipede').one()
+ name='centipede').one()
assert creature.num_legs == 100
assert creature.is_demon == False
creature = session.query(Creature1).filter_by(
- name=u'wolf').one()
+ name='wolf').one()
assert creature.num_legs == 4
assert creature.is_demon == False
creature = session.query(Creature1).filter_by(
- name=u'wizardsnake').one()
+ name='wizardsnake').one()
assert creature.num_legs == 0
assert creature.is_demon == True
level = session.query(Level1).filter_by(
- id=u'necroplex').one()
- assert level.name == u'The Necroplex'
- assert level.description == u'A complex full of pure deathzone.'
+ id='necroplex').one()
+ assert level.name == 'The Necroplex'
+ assert level.description == 'A complex full of pure deathzone.'
assert level.exits == {
'deathwell': 'evilstorm',
'portal': 'central_park'}
level = session.query(Level1).filter_by(
- id=u'evilstorm').one()
- assert level.name == u'Evil Storm'
- assert level.description == u'A storm full of pure evil.'
+ id='evilstorm').one()
+ assert level.name == 'Evil Storm'
+ assert level.description == 'A storm full of pure evil.'
assert level.exits == {} # You still can't escape the evilstorm!
level = session.query(Level1).filter_by(
- id=u'central_park').one()
- assert level.name == u'Central Park, NY, NY'
- assert level.description == u"New York's friendly Central Park."
+ id='central_park').one()
+ assert level.name == 'Central Park, NY, NY'
+ assert level.description == "New York's friendly Central Park."
assert level.exits == {
'portal': 'necroplex'}
@@ -691,7 +691,7 @@ def test_set1_to_set3():
# isn't said to be updated yet
printer = CollectingPrinter()
migration_manager = MigrationManager(
- u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(),
+ '__main__', SET3_MODELS, SET3_MIGRATIONS, Session(),
printer)
assert migration_manager.latest_migration == 8
@@ -701,7 +701,7 @@ def test_set1_to_set3():
result = migration_manager.init_or_migrate()
# Make sure result was "migrated"
- assert result == u'migrated'
+ assert result == 'migrated'
# TODO: Check output to user
assert printer.combined_string == """\
@@ -718,7 +718,7 @@ def test_set1_to_set3():
# Make sure version matches expected
migration_manager = MigrationManager(
- u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(),
+ '__main__', SET3_MODELS, SET3_MIGRATIONS, Session(),
printer)
assert migration_manager.latest_migration == 8
assert migration_manager.database_current_migration == 8
@@ -732,8 +732,8 @@ def test_set1_to_set3():
autoload=True, autoload_with=engine)
# assert set(creature_table.c.keys()) == set(
# ['id', 'name', 'num_limbs'])
- assert set(creature_table.c.keys()) == set(
- [u'id', 'name', u'num_limbs', u'is_demon'])
+ assert set(creature_table.c.keys()) == {
+ 'id', 'name', 'num_limbs', 'is_demon'}
assert_col_type(creature_table.c.id, Integer)
assert_col_type(creature_table.c.name, VARCHAR)
assert creature_table.c.name.nullable is False
@@ -746,8 +746,8 @@ def test_set1_to_set3():
creature_power_table = Table(
'creature_power', metadata,
autoload=True, autoload_with=engine)
- assert set(creature_power_table.c.keys()) == set(
- ['id', 'creature', 'name', 'description', 'hitpower'])
+ assert set(creature_power_table.c.keys()) == {
+ 'id', 'creature', 'name', 'description', 'hitpower'}
assert_col_type(creature_power_table.c.id, Integer)
assert_col_type(creature_power_table.c.creature, Integer)
assert creature_power_table.c.creature.nullable is False
@@ -760,8 +760,8 @@ def test_set1_to_set3():
level_table = Table(
'level', metadata,
autoload=True, autoload_with=engine)
- assert set(level_table.c.keys()) == set(
- ['id', 'name', 'description'])
+ assert set(level_table.c.keys()) == {
+ 'id', 'name', 'description'}
assert_col_type(level_table.c.id, VARCHAR)
assert level_table.c.id.primary_key is True
assert_col_type(level_table.c.name, VARCHAR)
@@ -771,8 +771,8 @@ def test_set1_to_set3():
level_exit_table = Table(
'level_exit', metadata,
autoload=True, autoload_with=engine)
- assert set(level_exit_table.c.keys()) == set(
- ['id', 'name', 'from_level', 'to_level'])
+ assert set(level_exit_table.c.keys()) == {
+ 'id', 'name', 'from_level', 'to_level'}
assert_col_type(level_exit_table.c.id, Integer)
assert_col_type(level_exit_table.c.name, VARCHAR)
assert_col_type(level_exit_table.c.from_level, VARCHAR)
@@ -788,40 +788,40 @@ def test_set1_to_set3():
# Then make sure the models have been migrated correctly
creature = session.query(Creature3).filter_by(
- name=u'centipede').one()
+ name='centipede').one()
assert creature.num_limbs == 100.0
assert creature.magical_powers == []
creature = session.query(Creature3).filter_by(
- name=u'wolf').one()
+ name='wolf').one()
assert creature.num_limbs == 4.0
assert creature.magical_powers == []
creature = session.query(Creature3).filter_by(
- name=u'wizardsnake').one()
+ name='wizardsnake').one()
assert creature.num_limbs == 0.0
assert creature.magical_powers == []
level = session.query(Level3).filter_by(
- id=u'necroplex').one()
- assert level.name == u'The Necroplex'
- assert level.description == u'A complex full of pure deathzone.'
+ id='necroplex').one()
+ assert level.name == 'The Necroplex'
+ assert level.description == 'A complex full of pure deathzone.'
level_exits = _get_level3_exits(session, level)
assert level_exits == {
- u'deathwell': u'evilstorm',
- u'portal': u'central_park'}
+ 'deathwell': 'evilstorm',
+ 'portal': 'central_park'}
level = session.query(Level3).filter_by(
- id=u'evilstorm').one()
- assert level.name == u'Evil Storm'
- assert level.description == u'A storm full of pure evil.'
+ id='evilstorm').one()
+ assert level.name == 'Evil Storm'
+ assert level.description == 'A storm full of pure evil.'
level_exits = _get_level3_exits(session, level)
assert level_exits == {} # You still can't escape the evilstorm!
level = session.query(Level3).filter_by(
- id=u'central_park').one()
- assert level.name == u'Central Park, NY, NY'
- assert level.description == u"New York's friendly Central Park."
+ id='central_park').one()
+ assert level.name == 'Central Park, NY, NY'
+ assert level.description == "New York's friendly Central Park."
level_exits = _get_level3_exits(session, level)
assert level_exits == {
'portal': 'necroplex'}
diff --git a/mediagoblin/tests/test_storage.py b/mediagoblin/tests/test_storage.py
index a4c3e4eb..4591cbdf 100644
--- a/mediagoblin/tests/test_storage.py
+++ b/mediagoblin/tests/test_storage.py
@@ -31,15 +31,15 @@ from mediagoblin import storage
################
def test_clean_listy_filepath():
- expected = [u'dir1', u'dir2', u'linooks.jpg']
+ expected = ['dir1', 'dir2', 'linooks.jpg']
assert storage.clean_listy_filepath(
['dir1', 'dir2', 'linooks.jpg']) == expected
- expected = [u'dir1', u'foo_.._nasty', u'linooks.jpg']
+ expected = ['dir1', 'foo_.._nasty', 'linooks.jpg']
assert storage.clean_listy_filepath(
['/dir1/', 'foo/../nasty', 'linooks.jpg']) == expected
- expected = [u'etc', u'passwd']
+ expected = ['etc', 'passwd']
assert storage.clean_listy_filepath(
['../../../etc/', 'passwd']) == expected
@@ -47,7 +47,7 @@ def test_clean_listy_filepath():
storage.clean_listy_filepath(['../../', 'linooks.jpg'])
-class FakeStorageSystem(object):
+class FakeStorageSystem:
def __init__(self, foobie, blech, **kwargs):
self.foobie = foobie
self.blech = blech
@@ -80,8 +80,8 @@ def test_storage_system_from_config():
'mediagoblin.tests.test_storage:FakeStorageSystem'})
assert this_storage.foobie == 'eiboof'
assert this_storage.blech == 'hcelb'
- assert six.text_type(this_storage.__class__) == \
- u"<class 'mediagoblin.tests.test_storage.FakeStorageSystem'>"
+ assert str(this_storage.__class__) == \
+ "<class 'mediagoblin.tests.test_storage.FakeStorageSystem'>"
##########################
@@ -152,7 +152,7 @@ def test_basic_storage_get_unique_filepath():
# now we want something new, with the same name!
new_filepath = this_storage.get_unique_filepath(
['dir1', 'dir2', 'filename.txt'])
- assert new_filepath[:-1] == [u'dir1', u'dir2']
+ assert new_filepath[:-1] == ['dir1', 'dir2']
new_filename = new_filepath[-1]
assert new_filename.endswith('filename.txt')
@@ -174,7 +174,7 @@ def test_basic_storage_get_file():
with this_storage.get_file(filepath, 'r') as our_file:
assert our_file.read() == b'First file'
assert os.path.exists(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'))
- with open(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'), 'r') as our_file:
+ with open(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt')) as our_file:
assert our_file.read() == 'First file'
# Write to the same path but try to get a unique file.
@@ -186,7 +186,7 @@ def test_basic_storage_get_file():
with this_storage.get_file(new_filepath, 'r') as our_file:
assert our_file.read() == b'Second file'
assert os.path.exists(os.path.join(tmpdir, *new_filepath))
- with open(os.path.join(tmpdir, *new_filepath), 'r') as our_file:
+ with open(os.path.join(tmpdir, *new_filepath)) as our_file:
assert our_file.read() == 'Second file'
# Read from an existing file
@@ -306,8 +306,7 @@ def _test_copy_local_to_storage_works(tmpdir, this_storage):
os.remove(local_filename)
assert open(
- os.path.join(tmpdir, 'dir1/dir2/copiedto.txt'),
- 'r').read() == 'haha'
+ os.path.join(tmpdir, 'dir1/dir2/copiedto.txt')).read() == 'haha'
this_storage.delete_file(['dir1', 'dir2', 'copiedto.txt'])
cleanup_storage(this_storage, tmpdir, ['dir1', 'dir2'])
diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
index a7661e85..72faf1b9 100644
--- a/mediagoblin/tests/test_submission.py
+++ b/mediagoblin/tests/test_submission.py
@@ -48,7 +48,7 @@ import pytest
import webtest.forms
import pkg_resources
try:
- import mock
+ from unittest import mock
except ImportError:
import unittest.mock as mock
@@ -72,8 +72,8 @@ from mediagoblin.submit.lib import new_upload_entry, run_process_media
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 = six.text_type('rage,' + 'f' * 26 + 'u' * 26)
+GOOD_TAG_STRING = 'yin,yang'
+BAD_TAG_STRING = str('rage,' + 'f' * 26 + 'u' * 26)
FORM_CONTEXT = ['mediagoblin/submit/start.html', 'submit_form']
REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request']
@@ -115,7 +115,7 @@ def get_sample_entry(user, media_type):
entry = new_upload_entry(user)
entry.media_type = media_type
entry.title = 'testentry'
- entry.description = u""
+ entry.description = ""
entry.license = None
entry.media_metadata = {}
entry.save()
@@ -129,7 +129,7 @@ class BaseTestSubmission:
# TODO: Possibly abstract into a decorator like:
# @as_authenticated_user('chris')
- fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
+ fixture_add_user(privileges=['active','uploader', 'commenter'])
self.login()
@@ -143,12 +143,12 @@ class BaseTestSubmission:
#### totally stupid.
#### Also if we found a way to make this run it should be a
#### property.
- return LocalUser.query.filter(LocalUser.username==u'chris').first()
+ return LocalUser.query.filter(LocalUser.username=='chris').first()
def login(self):
self.test_app.post(
'/auth/login/', {
- 'username': u'chris',
+ 'username': 'chris',
'password': 'toast'})
def logout(self):
@@ -185,10 +185,10 @@ class BaseTestSubmission:
def check_normal_upload(self, title, filename):
response, context = self.do_post({'title': title}, do_follow=True,
**self.upload_data(filename))
- self.check_url(response, '/u/{0}/'.format(self.our_user().username))
+ self.check_url(response, '/u/{}/'.format(self.our_user().username))
assert 'mediagoblin/user_pages/user.html' in context
# Make sure the media view is at least reachable, logged in...
- url = '/u/{0}/m/{1}/'.format(self.our_user().username,
+ url = '/u/{}/m/{}/'.format(self.our_user().username,
title.lower().replace(' ', '-'))
self.test_app.get(url)
# ... and logged out too.
@@ -212,38 +212,38 @@ class TestSubmissionBasics(BaseTestSubmission):
# Test blank form
# ---------------
response, form = self.do_post({}, *FORM_CONTEXT)
- assert form.file.errors == [u'You must provide a file.']
+ assert form.file.errors == ['You must provide a file.']
# Test blank file
# ---------------
- response, form = self.do_post({'title': u'test title'}, *FORM_CONTEXT)
- assert form.file.errors == [u'You must provide a file.']
+ response, form = self.do_post({'title': 'test title'}, *FORM_CONTEXT)
+ assert form.file.errors == ['You must provide a file.']
def test_normal_jpg(self):
# User uploaded should be 0
assert self.our_user().uploaded == 0
- self.check_normal_upload(u'Normal upload 1', GOOD_JPG)
+ self.check_normal_upload('Normal upload 1', GOOD_JPG)
# User uploaded should be the same as GOOD_JPG size in Mb
file_size = os.stat(GOOD_JPG).st_size / (1024.0 * 1024)
- file_size = float('{0:.2f}'.format(file_size))
+ file_size = float('{:.2f}'.format(file_size))
# Reload user
assert self.our_user().uploaded == file_size
def test_public_id_populated(self):
# Upload the image first.
- response, request = self.do_post({'title': u'Balanced Goblin'},
+ response, request = self.do_post({'title': 'Balanced Goblin'},
*REQUEST_CONTEXT, do_follow=True,
**self.upload_data(GOOD_JPG))
- media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
+ media = self.check_media(request, {'title': 'Balanced Goblin'}, 1)
# Now check that the public_id attribute is set.
assert media.public_id != None
def test_normal_png(self):
- self.check_normal_upload(u'Normal upload 2', GOOD_PNG)
+ self.check_normal_upload('Normal upload 2', GOOD_PNG)
def test_default_upload_limits(self):
self.user_upload_limits(uploaded=500)
@@ -251,10 +251,10 @@ class TestSubmissionBasics(BaseTestSubmission):
# User uploaded should be 500
assert self.our_user().uploaded == 500
- response, context = self.do_post({'title': u'Normal upload 4'},
+ response, context = self.do_post({'title': 'Normal upload 4'},
do_follow=True,
**self.upload_data(GOOD_JPG))
- self.check_url(response, '/u/{0}/'.format(self.our_user().username))
+ self.check_url(response, '/u/{}/'.format(self.our_user().username))
assert 'mediagoblin/user_pages/user.html' in context
# Shouldn't have uploaded
@@ -266,10 +266,10 @@ class TestSubmissionBasics(BaseTestSubmission):
# User uploaded should be 25
assert self.our_user().uploaded == 25
- response, context = self.do_post({'title': u'Normal upload 5'},
+ response, context = self.do_post({'title': 'Normal upload 5'},
do_follow=True,
**self.upload_data(GOOD_JPG))
- self.check_url(response, '/u/{0}/'.format(self.our_user().username))
+ self.check_url(response, '/u/{}/'.format(self.our_user().username))
assert 'mediagoblin/user_pages/user.html' in context
# Shouldn't have uploaded
@@ -281,23 +281,23 @@ class TestSubmissionBasics(BaseTestSubmission):
# User uploaded should be 499
assert self.our_user().uploaded == 499
- response, context = self.do_post({'title': u'Normal upload 6'},
+ response, context = self.do_post({'title': 'Normal upload 6'},
do_follow=False,
**self.upload_data(MED_PNG))
form = context['mediagoblin/submit/start.html']['submit_form']
- assert form.file.errors == [u'Sorry, uploading this file will put you'
+ assert form.file.errors == ['Sorry, uploading this file will put you'
' over your upload limit.']
# Shouldn't have uploaded
assert self.our_user().uploaded == 499
def test_big_file(self):
- response, context = self.do_post({'title': u'Normal upload 7'},
+ response, context = self.do_post({'title': 'Normal upload 7'},
do_follow=False,
**self.upload_data(BIG_PNG))
form = context['mediagoblin/submit/start.html']['submit_form']
- assert form.file.errors == [u'Sorry, the file size is too big.']
+ assert form.file.errors == ['Sorry, the file size is too big.']
def check_media(self, request, find_data, count=None):
media = MediaEntry.query.filter_by(**find_data)
@@ -310,34 +310,34 @@ class TestSubmissionBasics(BaseTestSubmission):
def test_tags(self):
# Good tag string
# --------
- response, request = self.do_post({'title': u'Balanced Goblin 2',
+ response, request = self.do_post({'title': 'Balanced Goblin 2',
'tags': GOOD_TAG_STRING},
*REQUEST_CONTEXT, do_follow=True,
**self.upload_data(GOOD_JPG))
- media = self.check_media(request, {'title': u'Balanced Goblin 2'}, 1)
- assert media.tags[0]['name'] == u'yin'
- assert media.tags[0]['slug'] == u'yin'
+ media = self.check_media(request, {'title': 'Balanced Goblin 2'}, 1)
+ assert media.tags[0]['name'] == 'yin'
+ assert media.tags[0]['slug'] == 'yin'
- assert media.tags[1]['name'] == u'yang'
- assert media.tags[1]['slug'] == u'yang'
+ assert media.tags[1]['name'] == 'yang'
+ assert media.tags[1]['slug'] == 'yang'
# Test tags that are too long
# ---------------
- response, form = self.do_post({'title': u'Balanced Goblin 2',
+ response, form = self.do_post({'title': 'Balanced Goblin 2',
'tags': BAD_TAG_STRING},
*FORM_CONTEXT,
**self.upload_data(GOOD_JPG))
assert form.tags.errors == [
- u'Tags must be shorter than 50 characters. ' \
+ 'Tags must be shorter than 50 characters. ' \
'Tags that are too long: ' \
'ffffffffffffffffffffffffffuuuuuuuuuuuuuuuuuuuuuuuuuu']
def test_delete(self):
self.user_upload_limits(uploaded=50)
- response, request = self.do_post({'title': u'Balanced Goblin'},
+ response, request = self.do_post({'title': 'Balanced Goblin'},
*REQUEST_CONTEXT, do_follow=True,
**self.upload_data(GOOD_JPG))
- media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
+ media = self.check_media(request, {'title': 'Balanced Goblin'}, 1)
media_id = media.id
# render and post to the edit page.
@@ -346,11 +346,11 @@ class TestSubmissionBasics(BaseTestSubmission):
user=self.our_user().username, media_id=media_id)
self.test_app.get(edit_url)
self.test_app.post(edit_url,
- {'title': u'Balanced Goblin',
- 'slug': u"Balanced=Goblin",
- 'tags': u''})
- media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
- assert media.slug == u"balanced-goblin"
+ {'title': 'Balanced Goblin',
+ 'slug': "Balanced=Goblin",
+ 'tags': ''})
+ media = self.check_media(request, {'title': 'Balanced Goblin'}, 1)
+ assert media.slug == "balanced-goblin"
# Add a comment, so we can test for its deletion later.
self.check_comments(request, media_id, 0)
@@ -368,7 +368,7 @@ class TestSubmissionBasics(BaseTestSubmission):
user=self.our_user().username, media_id=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': u'Balanced Goblin'}, 1)
+ media = self.check_media(request, {'title': 'Balanced Goblin'}, 1)
media_id = media.id
# Confirm deletion
@@ -384,7 +384,7 @@ class TestSubmissionBasics(BaseTestSubmission):
def test_evil_file(self):
# Test non-suppoerted file with non-supported extension
# -----------------------------------------------------
- response, form = self.do_post({'title': u'Malicious Upload 1'},
+ response, form = self.do_post({'title': 'Malicious Upload 1'},
*FORM_CONTEXT,
**self.upload_data(EVIL_FILE))
assert len(form.file.errors) == 1
@@ -395,12 +395,12 @@ class TestSubmissionBasics(BaseTestSubmission):
def test_get_media_manager(self):
"""Test if the get_media_manger function returns sensible things
"""
- response, request = self.do_post({'title': u'Balanced Goblin'},
+ response, request = self.do_post({'title': 'Balanced Goblin'},
*REQUEST_CONTEXT, do_follow=True,
**self.upload_data(GOOD_JPG))
- media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
+ media = self.check_media(request, {'title': 'Balanced Goblin'}, 1)
- assert media.media_type == u'mediagoblin.media_types.image'
+ assert media.media_type == 'mediagoblin.media_types.image'
assert isinstance(media.media_manager, ImageMediaManager)
assert media.media_manager.entry == media
@@ -412,7 +412,7 @@ class TestSubmissionBasics(BaseTestSubmission):
template.clear_test_template_context()
response = self.test_app.post(
'/submit/', {
- 'title': u'UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE'
+ 'title': 'UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE'
}, upload_files=[(
'file', GOOD_JPG)])
@@ -423,7 +423,7 @@ class TestSubmissionBasics(BaseTestSubmission):
request = context['request']
media = request.db.MediaEntry.query.filter_by(
- title=u'UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE').first()
+ title='UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE').first()
assert media.media_type == 'mediagoblin.media_types.image'
@@ -433,31 +433,31 @@ class TestSubmissionBasics(BaseTestSubmission):
# they'll be caught as failures during the processing step.
response, context = self.do_post({'title': title}, do_follow=True,
**self.upload_data(filename))
- self.check_url(response, '/u/{0}/'.format(self.our_user().username))
+ self.check_url(response, '/u/{}/'.format(self.our_user().username))
entry = mg_globals.database.MediaEntry.query.filter_by(title=title).first()
assert entry.state == 'failed'
- assert entry.fail_error == u'mediagoblin.processing:BadMediaFail'
+ assert entry.fail_error == 'mediagoblin.processing:BadMediaFail'
def test_evil_jpg(self):
# Test non-supported file with .jpg extension
# -------------------------------------------
- self.check_false_image(u'Malicious Upload 2', EVIL_JPG)
+ self.check_false_image('Malicious Upload 2', EVIL_JPG)
def test_evil_png(self):
# Test non-supported file with .png extension
# -------------------------------------------
- self.check_false_image(u'Malicious Upload 3', EVIL_PNG)
+ self.check_false_image('Malicious Upload 3', EVIL_PNG)
def test_media_data(self):
- self.check_normal_upload(u"With GPS data", GPS_JPG)
- media = self.check_media(None, {"title": u"With GPS data"}, 1)
+ self.check_normal_upload("With GPS data", GPS_JPG)
+ media = self.check_media(None, {"title": "With GPS data"}, 1)
assert media.get_location.position["latitude"] == 59.336666666666666
def test_processing(self):
public_store_dir = mg_globals.global_config[
'storage:publicstore']['base_dir']
- data = {'title': u'Big Blue'}
+ data = {'title': '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)
@@ -497,8 +497,8 @@ class TestSubmissionBasics(BaseTestSubmission):
# Collection option should be present if the user has collections. It
# shouldn't allow other users' collections to be selected.
col = fixture_add_collection(user=self.our_user())
- user = fixture_add_user(username=u'different')
- fixture_add_collection(user=user, name=u'different')
+ user = fixture_add_user(username='different')
+ fixture_add_collection(user=user, name='different')
response = self.test_app.get('/submit/')
form = response.form
assert 'collection' in form.fields
@@ -522,7 +522,7 @@ class TestSubmissionBasics(BaseTestSubmission):
# collection. That should be the last activity.
assert Activity.query.order_by(
Activity.id.desc()
- ).first().content == '{0} added new picture to {1}'.format(
+ ).first().content == '{} added new picture to {}'.format(
self.our_user().username, col.title)
# Test upload succeeds if the user has collection and no collection is
@@ -547,7 +547,7 @@ class TestSubmissionVideo(BaseTestSubmission):
# TODO: Possibly abstract into a decorator like:
# @as_authenticated_user('chris')
- fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
+ fixture_add_user(privileges=['active','uploader', 'commenter'])
self.login()
@@ -558,7 +558,7 @@ class TestSubmissionVideo(BaseTestSubmission):
self.check_normal_upload('Video', path)
media = mg_globals.database.MediaEntry.query.filter_by(
- title=u'Video').first()
+ title='Video').first()
video_config = mg_globals.global_config['plugins'][self.media_type]
for each_res in video_config['available_resolutions']:
@@ -573,7 +573,7 @@ class TestSubmissionVideo(BaseTestSubmission):
self.check_normal_upload('testgetallmedia', path)
media = mg_globals.database.MediaEntry.query.filter_by(
- title=u'testgetallmedia').first()
+ title='testgetallmedia').first()
result = media.get_all_media()
video_config = mg_globals.global_config['plugins'][self.media_type]
@@ -595,7 +595,7 @@ class TestSubmissionVideo(BaseTestSubmission):
assert len(result) == len(video_config['available_resolutions'])
for i in range(len(video_config['available_resolutions'])):
media_file = MediaFile.query.filter_by(media_entry=media.id,
- name=('webm_{0}'.format(str(result[i][0])))).first()
+ name=('webm_{}'.format(str(result[i][0])))).first()
# check media_file label
assert result[i][0] == video_config['available_resolutions'][i]
# check dimensions of media_file
@@ -645,7 +645,7 @@ class TestSubmissionVideo(BaseTestSubmission):
mock_comp_task.assert_has_calls(calls)
mock_cleanup.assert_called_once_with(args=(entry.id,), queue='default',
immutable=True)
- assert entry.state == u'processing'
+ assert entry.state == 'processing'
# delete the entry
entry.delete()
@@ -738,7 +738,7 @@ class TestSubmissionAudio(BaseTestSubmission):
# TODO: Possibly abstract into a decorator like:
# @as_authenticated_user('chris')
- fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
+ fixture_add_user(privileges=['active','uploader', 'commenter'])
self.login()
@@ -756,7 +756,7 @@ class TestSubmissionAudioVideo(BaseTestSubmission):
# TODO: Possibly abstract into a decorator like:
# @as_authenticated_user('chris')
- fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
+ fixture_add_user(privileges=['active','uploader', 'commenter'])
self.login()
@@ -774,15 +774,15 @@ class TestSubmissionPDF(BaseTestSubmission):
# TODO: Possibly abstract into a decorator like:
# @as_authenticated_user('chris')
- fixture_add_user(privileges=[u'active',u'uploader', u'commenter'])
+ fixture_add_user(privileges=['active','uploader', 'commenter'])
self.login()
@pytest.mark.skipif("not os.path.exists(GOOD_PDF) or not pdf_check_prerequisites()")
def test_normal_pdf(self):
- response, context = self.do_post({'title': u'Normal upload 3 (pdf)'},
+ response, context = self.do_post({'title': 'Normal upload 3 (pdf)'},
do_follow=True,
**self.upload_data(GOOD_PDF))
- self.check_url(response, '/u/{0}/'.format(self.our_user().username))
+ self.check_url(response, '/u/{}/'.format(self.our_user().username))
assert 'mediagoblin/user_pages/user.html' in context
diff --git a/mediagoblin/tests/test_subtitles.py b/mediagoblin/tests/test_subtitles.py
index 4e884d07..87bf71df 100644
--- a/mediagoblin/tests/test_subtitles.py
+++ b/mediagoblin/tests/test_subtitles.py
@@ -25,12 +25,12 @@ from mediagoblin.plugins.subtitles.tools import open_subtitle, save_subtitle
# Checking if the subtitle entry is working
def test_add_subtitle_entry(test_app):
- user_a = fixture_add_user(u"test_user")
+ user_a = fixture_add_user("test_user")
media = fixture_media_entry(uploader=user_a.id, save=False, expunge=False)
media.subtitle_files.append(dict(
- name=u"some name",
- filepath=[u"does", u"not", u"exist"],
+ name="some name",
+ filepath=["does", "not", "exist"],
))
Session.add(media)
Session.flush()
@@ -54,12 +54,12 @@ def test_read_write_file(test_app):
# Checking the customize exceptions
def test_customize_subtitle(test_app):
- user_a = fixture_add_user(u"test_user")
+ user_a = fixture_add_user("test_user")
media = fixture_media_entry(uploader=user_a.id, save=False, expunge=False)
media.subtitle_files.append(dict(
- name=u"some name",
- filepath=[u"does", u"not", u"exist"],
+ name="some name",
+ filepath=["does", "not", "exist"],
))
Session.add(media)
Session.flush()
diff --git a/mediagoblin/tests/test_tags.py b/mediagoblin/tests/test_tags.py
index 8358b052..87edf196 100644
--- a/mediagoblin/tests/test_tags.py
+++ b/mediagoblin/tests/test_tags.py
@@ -25,19 +25,19 @@ def test_list_of_dicts_conversion(test_app):
"""
# Leading, trailing, and internal whitespace should be removed and slugified
assert text.convert_to_tag_list_of_dicts('sleep , 6 AM, chainsaw! ') == [
- {'name': u'sleep', 'slug': u'sleep'},
- {'name': u'6 AM', 'slug': u'6-am'},
- {'name': u'chainsaw!', 'slug': u'chainsaw'}]
+ {'name': 'sleep', 'slug': 'sleep'},
+ {'name': '6 AM', 'slug': '6-am'},
+ {'name': 'chainsaw!', 'slug': 'chainsaw'}]
# If the user enters two identical tags, record only one of them
- assert text.convert_to_tag_list_of_dicts('echo,echo') == [{'name': u'echo',
- 'slug': u'echo'}]
+ assert text.convert_to_tag_list_of_dicts('echo,echo') == [{'name': 'echo',
+ 'slug': 'echo'}]
# When checking for duplicates, use the slug, not the tag
- assert text.convert_to_tag_list_of_dicts('echo,#echo') == [{'name': u'#echo',
- 'slug': u'echo'}]
+ assert text.convert_to_tag_list_of_dicts('echo,#echo') == [{'name': '#echo',
+ 'slug': 'echo'}]
# Make sure converting the list of dicts to a string works
- assert text.media_tags_as_string([{'name': u'yin', 'slug': u'yin'},
- {'name': u'yang', 'slug': u'yang'}]) == \
- u'yin, yang'
+ assert text.media_tags_as_string([{'name': 'yin', 'slug': 'yin'},
+ {'name': 'yang', 'slug': 'yang'}]) == \
+ 'yin, yang'
diff --git a/mediagoblin/tests/test_tools.py b/mediagoblin/tests/test_tools.py
index 5f916400..ffbd184c 100644
--- a/mediagoblin/tests/test_tools.py
+++ b/mediagoblin/tests/test_tools.py
@@ -14,10 +14,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from __future__ import absolute_import, unicode_literals
try:
- import mock
+ from unittest import mock
except ImportError:
import unittest.mock as mock
@@ -27,7 +26,7 @@ from werkzeug.test import EnvironBuilder
from mediagoblin.tools.request import decode_request
from mediagoblin.tools.pagination import Pagination
-class TestDecodeRequest(object):
+class TestDecodeRequest:
"""Test the decode_request function."""
def test_form_type(self):
@@ -67,7 +66,7 @@ class TestDecodeRequest(object):
assert data['foo'] == 'bar'
-class TestPagination(object):
+class TestPagination:
def _create_paginator(self, num_items, page, per_page):
"""Create a Paginator with a mock database cursor."""
mock_cursor = mock.MagicMock()
diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py
index 02976405..e1d2bdc1 100644
--- a/mediagoblin/tests/test_util.py
+++ b/mediagoblin/tests/test_util.py
@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
try:
- import mock
+ from unittest import mock
except ImportError:
import unittest.mock as mock
import email
@@ -35,14 +35,14 @@ testing._activate_testing()
def _import_component_testing_method(silly_string):
# Just for the sake of testing that our component importer works.
- return u"'%s' is the silliest string I've ever seen" % silly_string
+ return "'%s' is the silliest string I've ever seen" % silly_string
def test_import_component():
imported_func = common.import_component(
'mediagoblin.tests.test_util:_import_component_testing_method')
result = imported_func('hooobaladoobala')
- expected = u"'hooobaladoobala' is the silliest string I've ever seen"
+ expected = "'hooobaladoobala' is the silliest string I've ever seen"
assert result == expected
@@ -104,19 +104,19 @@ def test_email_force_starttls(starttls_enabled_app):
)
def test_slugify():
- assert url.slugify(u'a walk in the park') == u'a-walk-in-the-park'
- assert url.slugify(u'A Walk in the Park') == u'a-walk-in-the-park'
- assert url.slugify(u'a walk in the park') == u'a-walk-in-the-park'
- assert url.slugify(u'a walk in-the-park') == u'a-walk-in-the-park'
- assert url.slugify(u'a w@lk in the park?') == u'a-w-lk-in-the-park'
- assert url.slugify(u'a walk in the par\u0107') == u'a-walk-in-the-parc'
- assert url.slugify(u'\u00E0\u0042\u00E7\u010F\u00EB\u0066') == u'abcdef'
+ assert url.slugify('a walk in the park') == 'a-walk-in-the-park'
+ assert url.slugify('A Walk in the Park') == 'a-walk-in-the-park'
+ assert url.slugify('a walk in the park') == 'a-walk-in-the-park'
+ assert url.slugify('a walk in-the-park') == 'a-walk-in-the-park'
+ assert url.slugify('a w@lk in the park?') == 'a-w-lk-in-the-park'
+ assert url.slugify('a walk in the par\u0107') == 'a-walk-in-the-parc'
+ assert url.slugify('\u00E0\u0042\u00E7\u010F\u00EB\u0066') == 'abcdef'
# Russian
- assert url.slugify(u'\u043f\u0440\u043e\u0433\u0443\u043b\u043a\u0430 '
- u'\u0432 \u043f\u0430\u0440\u043a\u0435') == u'progulka-v-parke'
+ assert url.slugify('\u043f\u0440\u043e\u0433\u0443\u043b\u043a\u0430 '
+ '\u0432 \u043f\u0430\u0440\u043a\u0435') == 'progulka-v-parke'
# Korean
- assert (url.slugify(u'\uacf5\uc6d0\uc5d0\uc11c \uc0b0\ucc45') ==
- u'gongweoneseo-sancaeg')
+ assert (url.slugify('\uacf5\uc6d0\uc5d0\uc11c \uc0b0\ucc45') ==
+ 'gongweoneseo-sancaeg')
def test_locale_to_lower_upper():
"""
@@ -147,17 +147,17 @@ def test_locale_to_lower_lower():
def test_gettext_lazy_proxy():
from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
from mediagoblin.tools.translate import pass_to_ugettext, set_thread_locale
- proxy = _(u"Password")
- orig = u"Password"
+ proxy = _("Password")
+ orig = "Password"
set_thread_locale("es")
- p1 = six.text_type(proxy)
+ p1 = str(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 = six.text_type(proxy)
+ p2 = str(proxy)
p2_should = pass_to_ugettext(orig)
assert p2_should != orig, "Test broken, string not translated"
assert p2 == p2_should
@@ -185,7 +185,7 @@ def test_html_cleaner():
'<p><a href="">innocent link!</a></p>')
-class TestMail(object):
+class TestMail:
""" Test mediagoblin's mail tool """
def test_no_mail_server(self):
""" Tests that no smtp server is available """
diff --git a/mediagoblin/tests/test_workbench.py b/mediagoblin/tests/test_workbench.py
index 3202e698..f8df009e 100644
--- a/mediagoblin/tests/test_workbench.py
+++ b/mediagoblin/tests/test_workbench.py
@@ -24,7 +24,7 @@ from mediagoblin.decorators import get_workbench
from mediagoblin.tests.test_storage import get_tmp_filestorage, cleanup_storage
-class TestWorkbench(object):
+class TestWorkbench:
def setup(self):
self.workbench_base = tempfile.mkdtemp(prefix='gmg_workbench_testing')
self.workbench_manager = workbench.WorkbenchManager(
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index 82def02c..626ff323 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -39,7 +39,7 @@ from mediagoblin.tools.crypto import random_string
from datetime import datetime
-MEDIAGOBLIN_TEST_DB_NAME = u'__mediagoblin_tests__'
+MEDIAGOBLIN_TEST_DB_NAME = '__mediagoblin_tests__'
TEST_SERVER_CONFIG = pkg_resources.resource_filename(
'mediagoblin.tests', 'test_paste.ini')
TEST_APP_CONFIG = pkg_resources.resource_filename(
@@ -147,20 +147,20 @@ def install_fixtures_simple(db, fixtures):
"""
Very simply install fixtures in the database
"""
- for collection_name, collection_fixtures in six.iteritems(fixtures):
+ for collection_name, collection_fixtures in fixtures.items():
collection = db[collection_name]
for fixture in collection_fixtures:
collection.insert(fixture)
-def fixture_add_user(username=u'chris', password=u'toast',
+def fixture_add_user(username='chris', password='toast',
privileges=[], wants_comment_notification=True):
# Reuse existing user or create a new one
test_user = LocalUser.query.filter(LocalUser.username==username).first()
if test_user is None:
test_user = LocalUser()
test_user.username = username
- test_user.email = username + u'@example.com'
+ test_user.email = username + '@example.com'
if password is not None:
test_user.pw_hash = gen_password_hash(password)
test_user.wants_comment_notification = wants_comment_notification
@@ -218,9 +218,9 @@ def fixture_add_comment_notification(entry, subject, user,
return cn
-def fixture_media_entry(title=u"Some title", slug=None,
+def fixture_media_entry(title="Some title", slug=None,
uploader=None, save=True, gen_slug=True,
- state=u'unprocessed', fake_upload=True,
+ state='unprocessed', fake_upload=True,
expunge=True):
"""
Add a media entry for testing purposes.
@@ -237,14 +237,14 @@ def fixture_media_entry(title=u"Some title", slug=None,
entry.title = title
entry.slug = slug
entry.actor = uploader
- entry.media_type = u'image'
+ entry.media_type = 'image'
entry.state = state
if fake_upload:
entry.media_files = {'thumb': ['a', 'b', 'c.jpg'],
'medium': ['d', 'e', 'f.png'],
'original': ['g', 'h', 'i.png']}
- entry.media_type = u'mediagoblin.media_types.image'
+ entry.media_type = 'mediagoblin.media_types.image'
if gen_slug:
entry.generate_slug()
@@ -260,7 +260,7 @@ def fixture_media_entry(title=u"Some title", slug=None,
return entry
-def fixture_add_collection(name=u"My first Collection", user=None,
+def fixture_add_collection(name="My first Collection", user=None,
collection_type=Collection.USER_DEFINED_TYPE):
if user is None:
user = fixture_add_user()