aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tests')
-rw-r--r--mediagoblin/tests/test_csrf_middleware.py6
-rw-r--r--mediagoblin/tests/test_http_callback.py4
-rw-r--r--mediagoblin/tests/test_oauth.py17
-rw-r--r--mediagoblin/tests/test_sql_migrations.py29
-rw-r--r--mediagoblin/tests/test_submission.py15
5 files changed, 54 insertions, 17 deletions
diff --git a/mediagoblin/tests/test_csrf_middleware.py b/mediagoblin/tests/test_csrf_middleware.py
index ad433fe8..d730909f 100644
--- a/mediagoblin/tests/test_csrf_middleware.py
+++ b/mediagoblin/tests/test_csrf_middleware.py
@@ -44,7 +44,7 @@ def test_csrf_token_must_match(test_app):
# construct a request with a cookie, but no form token
assert test_app.post('/auth/login/',
- headers={'Cookie': str('%s=foo; ' %
+ headers={'Cookie': str('%s=foo' %
mg_globals.app_config['csrf_cookie_name'])},
extra_environ={'gmg.verify_csrf': True},
expect_errors=True).status_int == 403
@@ -52,7 +52,7 @@ def test_csrf_token_must_match(test_app):
# if both the cookie and form token are provided, they must match
assert test_app.post('/auth/login/',
{'csrf_token': 'blarf'},
- headers={'Cookie': str('%s=foo; ' %
+ headers={'Cookie': str('%s=foo' %
mg_globals.app_config['csrf_cookie_name'])},
extra_environ={'gmg.verify_csrf': True},
expect_errors=True).\
@@ -60,7 +60,7 @@ def test_csrf_token_must_match(test_app):
assert test_app.post('/auth/login/',
{'csrf_token': 'foo'},
- headers={'Cookie': str('%s=foo; ' %
+ headers={'Cookie': str('%s=foo' %
mg_globals.app_config['csrf_cookie_name'])},
extra_environ={'gmg.verify_csrf': True}).\
status_int == 200
diff --git a/mediagoblin/tests/test_http_callback.py b/mediagoblin/tests/test_http_callback.py
index d769af1e..8b0a03b9 100644
--- a/mediagoblin/tests/test_http_callback.py
+++ b/mediagoblin/tests/test_http_callback.py
@@ -30,8 +30,8 @@ class TestHTTPCallback(object):
self.app = get_test_app()
self.db = mg_globals.database
- self.user_password = 'secret'
- self.user = fixture_add_user('call_back', self.user_password)
+ self.user_password = u'secret'
+ self.user = fixture_add_user(u'call_back', self.user_password)
self.login()
diff --git a/mediagoblin/tests/test_oauth.py b/mediagoblin/tests/test_oauth.py
index db4e226a..a72f766e 100644
--- a/mediagoblin/tests/test_oauth.py
+++ b/mediagoblin/tests/test_oauth.py
@@ -34,8 +34,8 @@ class TestOAuth(object):
self.pman = pluginapi.PluginManager()
- self.user_password = '4cc355_70k3N'
- self.user = fixture_add_user('joauth', self.user_password)
+ self.user_password = u'4cc355_70k3N'
+ self.user = fixture_add_user(u'joauth', self.user_password)
self.login()
@@ -59,13 +59,13 @@ class TestOAuth(object):
def test_1_public_client_registration_without_redirect_uri(self):
''' Test 'public' OAuth client registration without any redirect uri '''
- response = self.register_client('OMGOMGOMG', 'public',
+ response = self.register_client(u'OMGOMGOMG', 'public',
'OMGOMG Apache License v2')
ctx = self.get_context('oauth/client/register.html')
client = self.db.OAuthClient.query.filter(
- self.db.OAuthClient.name == 'OMGOMGOMG').first()
+ self.db.OAuthClient.name == u'OMGOMGOMG').first()
assert response.status_int == 200
@@ -78,23 +78,23 @@ class TestOAuth(object):
def test_2_successful_public_client_registration(self):
''' Successfully register a public client '''
self.login()
- self.register_client('OMGOMG', 'public', 'OMG!',
+ self.register_client(u'OMGOMG', 'public', 'OMG!',
'http://foo.example')
client = self.db.OAuthClient.query.filter(
- self.db.OAuthClient.name == 'OMGOMG').first()
+ self.db.OAuthClient.name == u'OMGOMG').first()
# Client should have been registered
assert client
def test_3_successful_confidential_client_reg(self):
''' Register a confidential OAuth client '''
- response = self.register_client('GMOGMO', 'confidential', 'NO GMO!')
+ response = self.register_client(u'GMOGMO', 'confidential', 'NO GMO!')
assert response.status_int == 302
client = self.db.OAuthClient.query.filter(
- self.db.OAuthClient.name == 'GMOGMO').first()
+ self.db.OAuthClient.name == u'GMOGMO').first()
# Client should have been registered
assert client
@@ -103,6 +103,7 @@ class TestOAuth(object):
def test_4_authorize_confidential_client(self):
''' Authorize a confidential client as a logged in user '''
+
client = self.test_3_successful_confidential_client_reg()
client_identifier = client.identifier
diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py
index e3b55634..6383d096 100644
--- a/mediagoblin/tests/test_sql_migrations.py
+++ b/mediagoblin/tests/test_sql_migrations.py
@@ -322,6 +322,28 @@ def creature_power_hitpower_to_float(db_conn):
creature_power.c.hitpower.alter(type=Float)
+@RegisterMigration(8, FULL_MIGRATIONS)
+def creature_power_name_creature_unique(db_conn):
+ """
+ Add a unique constraint to name and creature on creature_power.
+
+ We don't want multiple creature powers with the same name per creature!
+ """
+ # Note: We don't actually check to see if this constraint is set
+ # up because at present there's no way to do so in sqlalchemy :\
+
+ metadata = MetaData(bind=db_conn.bind)
+
+ creature_power = Table(
+ 'creature_power', metadata,
+ autoload=True, autoload_with=db_conn.bind)
+
+ cons = changeset.constraint.UniqueConstraint(
+ 'name', 'creature', table=creature_power)
+
+ cons.create()
+
+
def _insert_migration1_objects(session):
"""
Test objects to insert for the first set of things
@@ -660,7 +682,7 @@ def test_set1_to_set3():
u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(),
printer)
- assert migration_manager.latest_migration == 7
+ assert migration_manager.latest_migration == 8
assert migration_manager.database_current_migration == 0
# Migrate
@@ -679,14 +701,15 @@ def test_set1_to_set3():
+ Running migration 5, "level_exit_index_from_and_to_level"... done.
+ Running migration 6, "creature_power_index_creature"... done.
+ Running migration 7, "creature_power_hitpower_to_float"... done.
+ + Running migration 8, "creature_power_name_creature_unique"... done.
"""
# Make sure version matches expected
migration_manager = MigrationManager(
u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(),
printer)
- assert migration_manager.latest_migration == 7
- assert migration_manager.database_current_migration == 7
+ assert migration_manager.latest_migration == 8
+ assert migration_manager.database_current_migration == 8
# Check all things in database match expected
diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
index b7b0e574..b6fe0015 100644
--- a/mediagoblin/tests/test_submission.py
+++ b/mediagoblin/tests/test_submission.py
@@ -28,7 +28,7 @@ from mediagoblin.tests.tools import get_test_app, \
fixture_add_user
from mediagoblin import mg_globals
from mediagoblin.tools import template
-
+from mediagoblin.media_types.image import MEDIA_MANAGER as img_MEDIA_MANAGER
def resource(filename):
return resource_filename('mediagoblin.tests', 'test_submission/' + filename)
@@ -197,6 +197,19 @@ class TestSubmission:
assert 'Sorry, I don\'t support that file type :(' == \
str(form.file.errors[0])
+
+ 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'},
+ *REQUEST_CONTEXT, do_follow=True,
+ **self.upload_data(GOOD_JPG))
+ media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
+
+ assert_equal(media.media_type, u'mediagoblin.media_types.image')
+ assert_equal(media.media_manager, img_MEDIA_MANAGER)
+
+
def test_sniffing(self):
'''
Test sniffing mechanism to assert that regular uploads work as intended