Merge branch 'WIP/test_performance'
This commit is contained in:
commit
031d988c29
@ -44,7 +44,7 @@ BIG_BLUE = resource('bigblue.png')
|
|||||||
|
|
||||||
class TestAPI(object):
|
class TestAPI(object):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.app = get_test_app()
|
self.app = get_test_app(dump_old_app=False)
|
||||||
self.db = mg_globals.database
|
self.db = mg_globals.database
|
||||||
|
|
||||||
self.user_password = u'4cc355_70k3N'
|
self.user_password = u'4cc355_70k3N'
|
||||||
|
@ -22,7 +22,7 @@ from nose.tools import assert_equal
|
|||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.auth import lib as auth_lib
|
from mediagoblin.auth import lib as auth_lib
|
||||||
from mediagoblin.db.models import User
|
from mediagoblin.db.models import User
|
||||||
from mediagoblin.tests.tools import setup_fresh_app, fixture_add_user
|
from mediagoblin.tests.tools import get_test_app, fixture_add_user
|
||||||
from mediagoblin.tools import template, mail
|
from mediagoblin.tools import template, mail
|
||||||
|
|
||||||
|
|
||||||
@ -67,11 +67,11 @@ def test_bcrypt_gen_password_hash():
|
|||||||
'notthepassword', hashed_pw, '3><7R45417')
|
'notthepassword', hashed_pw, '3><7R45417')
|
||||||
|
|
||||||
|
|
||||||
@setup_fresh_app
|
def test_register_views():
|
||||||
def test_register_views(test_app):
|
|
||||||
"""
|
"""
|
||||||
Massive test function that all our registration-related views all work.
|
Massive test function that all our registration-related views all work.
|
||||||
"""
|
"""
|
||||||
|
test_app = get_test_app(dump_old_app=False)
|
||||||
# Test doing a simple GET on the page
|
# Test doing a simple GET on the page
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
|
|
||||||
@ -311,11 +311,11 @@ def test_register_views(test_app):
|
|||||||
'mediagoblin/root.html')
|
'mediagoblin/root.html')
|
||||||
|
|
||||||
|
|
||||||
@setup_fresh_app
|
def test_authentication_views():
|
||||||
def test_authentication_views(test_app):
|
|
||||||
"""
|
"""
|
||||||
Test logging in and logging out
|
Test logging in and logging out
|
||||||
"""
|
"""
|
||||||
|
test_app = get_test_app(dump_old_app=False)
|
||||||
# Make a new user
|
# Make a new user
|
||||||
test_user = fixture_add_user(active_user=False)
|
test_user = fixture_add_user(active_user=False)
|
||||||
|
|
||||||
|
@ -14,13 +14,12 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from mediagoblin.tests.tools import setup_fresh_app
|
from mediagoblin.tests.tools import get_test_app
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
|
|
||||||
|
|
||||||
@setup_fresh_app
|
def test_csrf_cookie_set():
|
||||||
def test_csrf_cookie_set(test_app):
|
test_app = get_test_app(dump_old_app=False)
|
||||||
|
|
||||||
cookie_name = mg_globals.app_config['csrf_cookie_name']
|
cookie_name = mg_globals.app_config['csrf_cookie_name']
|
||||||
|
|
||||||
# get login page
|
# get login page
|
||||||
@ -34,9 +33,8 @@ def test_csrf_cookie_set(test_app):
|
|||||||
assert response.headers.get('Vary', False) == 'Cookie'
|
assert response.headers.get('Vary', False) == 'Cookie'
|
||||||
|
|
||||||
|
|
||||||
@setup_fresh_app
|
def test_csrf_token_must_match():
|
||||||
def test_csrf_token_must_match(test_app):
|
test_app = get_test_app(dump_old_app=False)
|
||||||
|
|
||||||
# construct a request with no cookie or form token
|
# construct a request with no cookie or form token
|
||||||
assert test_app.post('/auth/login/',
|
assert test_app.post('/auth/login/',
|
||||||
extra_environ={'gmg.verify_csrf': True},
|
extra_environ={'gmg.verify_csrf': True},
|
||||||
@ -65,9 +63,8 @@ def test_csrf_token_must_match(test_app):
|
|||||||
extra_environ={'gmg.verify_csrf': True}).\
|
extra_environ={'gmg.verify_csrf': True}).\
|
||||||
status_int == 200
|
status_int == 200
|
||||||
|
|
||||||
@setup_fresh_app
|
def test_csrf_exempt():
|
||||||
def test_csrf_exempt(test_app):
|
test_app = get_test_app(dump_old_app=False)
|
||||||
|
|
||||||
# monkey with the views to decorate a known endpoint
|
# monkey with the views to decorate a known endpoint
|
||||||
import mediagoblin.auth.views
|
import mediagoblin.auth.views
|
||||||
from mediagoblin.meddleware.csrf import csrf_exempt
|
from mediagoblin.meddleware.csrf import csrf_exempt
|
||||||
|
@ -27,7 +27,7 @@ from mediagoblin.tests import test_oauth as oauth
|
|||||||
|
|
||||||
class TestHTTPCallback(object):
|
class TestHTTPCallback(object):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.app = get_test_app()
|
self.app = get_test_app(dump_old_app=False)
|
||||||
self.db = mg_globals.database
|
self.db = mg_globals.database
|
||||||
|
|
||||||
self.user_password = u'secret'
|
self.user_password = u'secret'
|
||||||
|
@ -15,17 +15,18 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from mediagoblin.messages import fetch_messages, add_message
|
from mediagoblin.messages import fetch_messages, add_message
|
||||||
from mediagoblin.tests.tools import setup_fresh_app
|
from mediagoblin.tests.tools import get_test_app
|
||||||
from mediagoblin.tools import template
|
from mediagoblin.tools import template
|
||||||
|
|
||||||
|
|
||||||
@setup_fresh_app
|
|
||||||
def test_messages(test_app):
|
def test_messages():
|
||||||
"""
|
"""
|
||||||
Added messages should show up in the request.session,
|
Added messages should show up in the request.session,
|
||||||
fetched messages should be the same as the added ones,
|
fetched messages should be the same as the added ones,
|
||||||
and fetching should clear the message list.
|
and fetching should clear the message list.
|
||||||
"""
|
"""
|
||||||
|
test_app = get_test_app(dump_old_app=False)
|
||||||
# Aquire a request object
|
# Aquire a request object
|
||||||
test_app.get('/')
|
test_app.get('/')
|
||||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
|
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
|
||||||
|
@ -16,11 +16,9 @@
|
|||||||
|
|
||||||
from nose.tools import assert_equal
|
from nose.tools import assert_equal
|
||||||
|
|
||||||
from mediagoblin.tests.tools import setup_fresh_app
|
from mediagoblin.tests.tools import get_test_app
|
||||||
|
|
||||||
|
def test_404_for_non_existent():
|
||||||
@setup_fresh_app
|
test_app = get_test_app(dump_old_app=False)
|
||||||
def test_404_for_non_existent(test_app):
|
res = test_app.get('/does-not-exist/', expect_errors=True)
|
||||||
assert_equal(test_app.get('/does-not-exist/',
|
assert_equal(res.status_int, 404)
|
||||||
expect_errors=True).status_int,
|
|
||||||
404)
|
|
||||||
|
@ -50,7 +50,7 @@ REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request']
|
|||||||
|
|
||||||
class TestSubmission:
|
class TestSubmission:
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.test_app = get_test_app()
|
self.test_app = get_test_app(dump_old_app=False)
|
||||||
|
|
||||||
# TODO: Possibly abstract into a decorator like:
|
# TODO: Possibly abstract into a decorator like:
|
||||||
# @as_authenticated_user('chris')
|
# @as_authenticated_user('chris')
|
||||||
@ -132,11 +132,11 @@ class TestSubmission:
|
|||||||
def test_tags(self):
|
def test_tags(self):
|
||||||
# Good tag string
|
# Good tag string
|
||||||
# --------
|
# --------
|
||||||
response, request = self.do_post({'title': u'Balanced Goblin',
|
response, request = self.do_post({'title': u'Balanced Goblin 2',
|
||||||
'tags': GOOD_TAG_STRING},
|
'tags': GOOD_TAG_STRING},
|
||||||
*REQUEST_CONTEXT, do_follow=True,
|
*REQUEST_CONTEXT, do_follow=True,
|
||||||
**self.upload_data(GOOD_JPG))
|
**self.upload_data(GOOD_JPG))
|
||||||
media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
|
media = self.check_media(request, {'title': u'Balanced Goblin 2'}, 1)
|
||||||
assert media.tags[0]['name'] == u'yin'
|
assert media.tags[0]['name'] == u'yin'
|
||||||
assert media.tags[0]['slug'] == u'yin'
|
assert media.tags[0]['slug'] == u'yin'
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ class TestSubmission:
|
|||||||
|
|
||||||
# Test tags that are too long
|
# Test tags that are too long
|
||||||
# ---------------
|
# ---------------
|
||||||
response, form = self.do_post({'title': u'Balanced Goblin',
|
response, form = self.do_post({'title': u'Balanced Goblin 2',
|
||||||
'tags': BAD_TAG_STRING},
|
'tags': BAD_TAG_STRING},
|
||||||
*FORM_CONTEXT,
|
*FORM_CONTEXT,
|
||||||
**self.upload_data(GOOD_JPG))
|
**self.upload_data(GOOD_JPG))
|
||||||
|
@ -14,17 +14,17 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from mediagoblin.tests.tools import setup_fresh_app
|
from mediagoblin.tests.tools import get_test_app
|
||||||
from mediagoblin.tools import text
|
from mediagoblin.tools import text
|
||||||
|
|
||||||
@setup_fresh_app
|
def test_list_of_dicts_conversion():
|
||||||
def test_list_of_dicts_conversion(test_app):
|
|
||||||
"""
|
"""
|
||||||
When the user adds tags to a media entry, the string from the form is
|
When the user adds tags to a media entry, the string from the form is
|
||||||
converted into a list of tags, where each tag is stored in the database
|
converted into a list of tags, where each tag is stored in the database
|
||||||
as a dict. Each tag dict should contain the tag's name and slug. Another
|
as a dict. Each tag dict should contain the tag's name and slug. Another
|
||||||
function performs the reverse operation when populating a form to edit tags.
|
function performs the reverse operation when populating a form to edit tags.
|
||||||
"""
|
"""
|
||||||
|
test_app = get_test_app(dump_old_app=False)
|
||||||
# Leading, trailing, and internal whitespace should be removed and slugified
|
# Leading, trailing, and internal whitespace should be removed and slugified
|
||||||
assert text.convert_to_tag_list_of_dicts('sleep , 6 AM, chainsaw! ') == [
|
assert text.convert_to_tag_list_of_dicts('sleep , 6 AM, chainsaw! ') == [
|
||||||
{'name': u'sleep', 'slug': u'sleep'},
|
{'name': u'sleep', 'slug': u'sleep'},
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.tests.tools import get_test_app
|
from mediagoblin.tests.tools import get_test_app, fixture_add_user
|
||||||
from mediagoblin.db.models import User
|
from mediagoblin.db.models import User
|
||||||
|
|
||||||
|
|
||||||
@ -23,16 +23,14 @@ def test_get_test_app_wipes_db():
|
|||||||
"""
|
"""
|
||||||
Make sure we get a fresh database on every wipe :)
|
Make sure we get a fresh database on every wipe :)
|
||||||
"""
|
"""
|
||||||
get_test_app()
|
get_test_app(dump_old_app=True)
|
||||||
assert User.query.count() == 0
|
assert User.query.count() == 0
|
||||||
|
|
||||||
new_user = mg_globals.database.User()
|
fixture_add_user()
|
||||||
new_user.username = u'lolcat'
|
|
||||||
new_user.email = u'lol@cats.example.org'
|
|
||||||
new_user.pw_hash = u'pretend_this_is_a_hash'
|
|
||||||
new_user.save()
|
|
||||||
assert User.query.count() == 1
|
assert User.query.count() == 1
|
||||||
|
|
||||||
get_test_app()
|
get_test_app(dump_old_app=False)
|
||||||
|
assert User.query.count() == 1
|
||||||
|
|
||||||
|
get_test_app(dump_old_app=True)
|
||||||
assert User.query.count() == 0
|
assert User.query.count() == 0
|
||||||
|
@ -25,6 +25,7 @@ from paste.deploy import loadapp
|
|||||||
from webtest import TestApp
|
from webtest import TestApp
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
|
from mediagoblin.db.models import User
|
||||||
from mediagoblin.tools import testing
|
from mediagoblin.tools import testing
|
||||||
from mediagoblin.init.config import read_mediagoblin_config
|
from mediagoblin.init.config import read_mediagoblin_config
|
||||||
from mediagoblin.db.open import setup_connection_and_db_from_config
|
from mediagoblin.db.open import setup_connection_and_db_from_config
|
||||||
@ -202,9 +203,9 @@ def assert_db_meets_expected(db, expected):
|
|||||||
assert document == expected_document # make sure it matches
|
assert document == expected_document # make sure it matches
|
||||||
|
|
||||||
|
|
||||||
def fixture_add_user(username=u'chris', password='toast',
|
def fixture_add_user(username=u'chris', password=u'toast',
|
||||||
active_user=True):
|
active_user=True):
|
||||||
test_user = mg_globals.database.User()
|
test_user = User.query.filter_by(username=username).first() or User()
|
||||||
test_user.username = username
|
test_user.username = username
|
||||||
test_user.email = username + u'@example.com'
|
test_user.email = username + u'@example.com'
|
||||||
if password is not None:
|
if password is not None:
|
||||||
@ -216,7 +217,7 @@ def fixture_add_user(username=u'chris', password='toast',
|
|||||||
test_user.save()
|
test_user.save()
|
||||||
|
|
||||||
# Reload
|
# Reload
|
||||||
test_user = mg_globals.database.User.find_one({'username': username})
|
test_user = User.query.filter_by(username=username).first()
|
||||||
|
|
||||||
# ... and detach from session:
|
# ... and detach from session:
|
||||||
Session.expunge(test_user)
|
Session.expunge(test_user)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user