Merge branch 'WIP/test_performance'
This commit is contained in:
commit
031d988c29
@ -44,7 +44,7 @@ BIG_BLUE = resource('bigblue.png')
|
||||
|
||||
class TestAPI(object):
|
||||
def setUp(self):
|
||||
self.app = get_test_app()
|
||||
self.app = get_test_app(dump_old_app=False)
|
||||
self.db = mg_globals.database
|
||||
|
||||
self.user_password = u'4cc355_70k3N'
|
||||
|
@ -22,7 +22,7 @@ from nose.tools import assert_equal
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin.auth import lib as auth_lib
|
||||
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
|
||||
|
||||
|
||||
@ -67,11 +67,11 @@ def test_bcrypt_gen_password_hash():
|
||||
'notthepassword', hashed_pw, '3><7R45417')
|
||||
|
||||
|
||||
@setup_fresh_app
|
||||
def test_register_views(test_app):
|
||||
def test_register_views():
|
||||
"""
|
||||
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
|
||||
# -----------------------------------
|
||||
|
||||
@ -311,11 +311,11 @@ def test_register_views(test_app):
|
||||
'mediagoblin/root.html')
|
||||
|
||||
|
||||
@setup_fresh_app
|
||||
def test_authentication_views(test_app):
|
||||
def test_authentication_views():
|
||||
"""
|
||||
Test logging in and logging out
|
||||
"""
|
||||
test_app = get_test_app(dump_old_app=False)
|
||||
# Make a new user
|
||||
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
|
||||
# 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
|
||||
|
||||
|
||||
@setup_fresh_app
|
||||
def test_csrf_cookie_set(test_app):
|
||||
|
||||
def test_csrf_cookie_set():
|
||||
test_app = get_test_app(dump_old_app=False)
|
||||
cookie_name = mg_globals.app_config['csrf_cookie_name']
|
||||
|
||||
# get login page
|
||||
@ -34,9 +33,8 @@ def test_csrf_cookie_set(test_app):
|
||||
assert response.headers.get('Vary', False) == 'Cookie'
|
||||
|
||||
|
||||
@setup_fresh_app
|
||||
def test_csrf_token_must_match(test_app):
|
||||
|
||||
def test_csrf_token_must_match():
|
||||
test_app = get_test_app(dump_old_app=False)
|
||||
# construct a request with no cookie or form token
|
||||
assert test_app.post('/auth/login/',
|
||||
extra_environ={'gmg.verify_csrf': True},
|
||||
@ -65,9 +63,8 @@ def test_csrf_token_must_match(test_app):
|
||||
extra_environ={'gmg.verify_csrf': True}).\
|
||||
status_int == 200
|
||||
|
||||
@setup_fresh_app
|
||||
def test_csrf_exempt(test_app):
|
||||
|
||||
def test_csrf_exempt():
|
||||
test_app = get_test_app(dump_old_app=False)
|
||||
# monkey with the views to decorate a known endpoint
|
||||
import mediagoblin.auth.views
|
||||
from mediagoblin.meddleware.csrf import csrf_exempt
|
||||
|
@ -27,7 +27,7 @@ from mediagoblin.tests import test_oauth as oauth
|
||||
|
||||
class TestHTTPCallback(object):
|
||||
def setUp(self):
|
||||
self.app = get_test_app()
|
||||
self.app = get_test_app(dump_old_app=False)
|
||||
self.db = mg_globals.database
|
||||
|
||||
self.user_password = u'secret'
|
||||
|
@ -15,30 +15,31 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
|
||||
|
||||
@setup_fresh_app
|
||||
def test_messages(test_app):
|
||||
|
||||
def test_messages():
|
||||
"""
|
||||
Added messages should show up in the request.session,
|
||||
fetched messages should be the same as the added ones,
|
||||
and fetching should clear the message list.
|
||||
"""
|
||||
test_app = get_test_app(dump_old_app=False)
|
||||
# Aquire a request object
|
||||
test_app.get('/')
|
||||
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
|
||||
request = context['request']
|
||||
|
||||
|
||||
# The message queue should be empty
|
||||
assert request.session.get('messages', []) == []
|
||||
|
||||
|
||||
# Adding a message should modify the session accordingly
|
||||
add_message(request, 'herp_derp', 'First!')
|
||||
test_msg_queue = [{'text': 'First!', 'level': 'herp_derp'}]
|
||||
assert request.session['messages'] == test_msg_queue
|
||||
|
||||
|
||||
# fetch_messages should return and empty the queue
|
||||
assert fetch_messages(request) == test_msg_queue
|
||||
assert request.session.get('messages') == []
|
||||
|
@ -16,11 +16,9 @@
|
||||
|
||||
from nose.tools import assert_equal
|
||||
|
||||
from mediagoblin.tests.tools import setup_fresh_app
|
||||
from mediagoblin.tests.tools import get_test_app
|
||||
|
||||
|
||||
@setup_fresh_app
|
||||
def test_404_for_non_existent(test_app):
|
||||
assert_equal(test_app.get('/does-not-exist/',
|
||||
expect_errors=True).status_int,
|
||||
404)
|
||||
def test_404_for_non_existent():
|
||||
test_app = get_test_app(dump_old_app=False)
|
||||
res = test_app.get('/does-not-exist/', expect_errors=True)
|
||||
assert_equal(res.status_int, 404)
|
||||
|
@ -50,7 +50,7 @@ REQUEST_CONTEXT = ['mediagoblin/user_pages/user.html', 'request']
|
||||
|
||||
class TestSubmission:
|
||||
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:
|
||||
# @as_authenticated_user('chris')
|
||||
@ -132,11 +132,11 @@ class TestSubmission:
|
||||
def test_tags(self):
|
||||
# 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},
|
||||
*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': u'Balanced Goblin 2'}, 1)
|
||||
assert media.tags[0]['name'] == u'yin'
|
||||
assert media.tags[0]['slug'] == u'yin'
|
||||
|
||||
@ -145,7 +145,7 @@ class TestSubmission:
|
||||
|
||||
# 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},
|
||||
*FORM_CONTEXT,
|
||||
**self.upload_data(GOOD_JPG))
|
||||
|
@ -14,17 +14,17 @@
|
||||
# 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 mediagoblin.tests.tools import setup_fresh_app
|
||||
from mediagoblin.tests.tools import get_test_app
|
||||
from mediagoblin.tools import text
|
||||
|
||||
@setup_fresh_app
|
||||
def test_list_of_dicts_conversion(test_app):
|
||||
def test_list_of_dicts_conversion():
|
||||
"""
|
||||
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
|
||||
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.
|
||||
"""
|
||||
test_app = get_test_app(dump_old_app=False)
|
||||
# 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'},
|
||||
|
@ -15,7 +15,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -23,16 +23,14 @@ def test_get_test_app_wipes_db():
|
||||
"""
|
||||
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
|
||||
|
||||
new_user = mg_globals.database.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()
|
||||
fixture_add_user()
|
||||
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
|
||||
|
@ -25,6 +25,7 @@ from paste.deploy import loadapp
|
||||
from webtest import TestApp
|
||||
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin.db.models import User
|
||||
from mediagoblin.tools import testing
|
||||
from mediagoblin.init.config import read_mediagoblin_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
|
||||
|
||||
|
||||
def fixture_add_user(username=u'chris', password='toast',
|
||||
def fixture_add_user(username=u'chris', password=u'toast',
|
||||
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.email = username + u'@example.com'
|
||||
if password is not None:
|
||||
@ -216,7 +217,7 @@ def fixture_add_user(username=u'chris', password='toast',
|
||||
test_user.save()
|
||||
|
||||
# Reload
|
||||
test_user = mg_globals.database.User.find_one({'username': username})
|
||||
test_user = User.query.filter_by(username=username).first()
|
||||
|
||||
# ... and detach from session:
|
||||
Session.expunge(test_user)
|
||||
|
Loading…
x
Reference in New Issue
Block a user