aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/hackinghowto.rst2
-rw-r--r--mediagoblin/auth/forms.py4
-rw-r--r--mediagoblin/tests/test_auth.py92
-rw-r--r--mediagoblin/tests/tools.py7
-rw-r--r--mediagoblin/util.py6
5 files changed, 102 insertions, 9 deletions
diff --git a/docs/hackinghowto.rst b/docs/hackinghowto.rst
index a56498bb..a9aadb62 100644
--- a/docs/hackinghowto.rst
+++ b/docs/hackinghowto.rst
@@ -152,7 +152,7 @@ Running the test suite
Run::
- ./bin/nosetests
+ CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_tests ./bin/nosetests
Running a shell
diff --git a/mediagoblin/auth/forms.py b/mediagoblin/auth/forms.py
index db8aaceb..7bc0aeb1 100644
--- a/mediagoblin/auth/forms.py
+++ b/mediagoblin/auth/forms.py
@@ -27,7 +27,9 @@ class RegistrationForm(wtforms.Form):
'Password',
[wtforms.validators.Required(),
wtforms.validators.Length(min=6, max=30),
- wtforms.validators.EqualTo('confirm_password')])
+ wtforms.validators.EqualTo(
+ 'confirm_password',
+ 'Passwords must match.')])
confirm_password = wtforms.PasswordField(
'Confirm password',
[wtforms.validators.Required()])
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py
index 94ce6bba..7a46a1ff 100644
--- a/mediagoblin/tests/test_auth.py
+++ b/mediagoblin/tests/test_auth.py
@@ -17,6 +17,11 @@
from mediagoblin.auth import lib as auth_lib
+from mediagoblin.tests.tools import get_test_app
+
+from mediagoblin import globals as mgoblin_globals
+from mediagoblin import util
+
########################
# Test bcrypt auth funcs
@@ -57,3 +62,90 @@ def test_bcrypt_gen_password_hash():
pw, hashed_pw, '3><7R45417')
assert not auth_lib.bcrypt_check_password(
'notthepassword', hashed_pw, '3><7R45417')
+
+
+def test_register_views():
+ util.clear_test_template_context()
+ test_app = get_test_app()
+
+ # Test doing a simple GET on the page
+ # -----------------------------------
+
+ test_app.get('/auth/register/')
+ # Make sure it rendered with the appropriate template
+ assert util.TEMPLATE_TEST_CONTEXT.has_key(
+ 'mediagoblin/auth/register.html')
+
+ # Try to register without providing anything, should error
+ # --------------------------------------------------------
+
+ util.clear_test_template_context()
+ test_app.post(
+ '/auth/register/', {})
+ context = util.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.confirm_password.errors == [u'This field is required.']
+ assert form.email.errors == [u'This field is required.']
+
+ # Try to register with fields that are known to be invalid
+ # --------------------------------------------------------
+
+ ## too short
+ util.clear_test_template_context()
+ test_app.post(
+ '/auth/register/', {
+ 'username': 'l',
+ 'password': 'o',
+ 'confirm_password': 'o',
+ 'email': 'l'})
+ context = util.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 6 and 30 characters long.']
+
+ ## bad form
+ util.clear_test_template_context()
+ test_app.post(
+ '/auth/register/', {
+ 'username': '@_@',
+ 'email': 'lollerskates'})
+ context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
+ form = context['register_form']
+
+ assert form.username.errors == [
+ u'Invalid input.']
+ assert form.email.errors == [
+ u'Invalid email address.']
+
+ ## mismatching passwords
+ util.clear_test_template_context()
+ test_app.post(
+ '/auth/register/', {
+ 'password': 'herpderp',
+ 'confirm_password': 'derpherp'})
+ context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
+ form = context['register_form']
+
+ assert form.password.errors == [
+ u'Passwords must match.']
+
+ ## At this point there should be no users in the database ;)
+ assert not mgoblin_globals.database.User.find().count()
+
+ # Successful register
+ # -------------------
+ ## Did we redirect to the proper page? Use the right template?
+ ## Make sure user is in place
+ ## Make sure we get email confirmation
+ ## Try logging in
+
+ # Uniqueness checks
+ # -----------------
+ ## We shouldn't be able to register with that user twice
+
+ ## Also check for double instances of an email address
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index 70b74b89..a51402e9 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -18,10 +18,9 @@
import pkg_resources
import os, shutil
-from paste.deploy import appconfig
+from paste.deploy import appconfig, loadapp
from webtest import TestApp
-from mediagoblin import app
from mediagoblin.db.open import setup_connection_and_db_from_config
@@ -88,7 +87,7 @@ def get_test_app(dump_old_app=True):
# TODO: Drop and recreate indexes
# setup app and return
- test_app = app.paste_app_factory(
- config.global_conf, **config.local_conf)
+ test_app = loadapp(
+ 'config:' + TEST_APP_CONFIG)
return TestApp(test_app)
diff --git a/mediagoblin/util.py b/mediagoblin/util.py
index a0a09adf..cbb937ee 100644
--- a/mediagoblin/util.py
+++ b/mediagoblin/util.py
@@ -95,7 +95,7 @@ def get_jinja_env(template_loader, locale):
TEMPLATE_TEST_CONTEXT = {}
-def render_template(request, template, context):
+def render_template(request, template_path, context):
"""
Render a template with context.
@@ -103,12 +103,12 @@ def render_template(request, template, context):
Also stores the context if we're doing unit tests. Helpful!
"""
template = request.template_env.get_template(
- template)
+ template_path)
context['request'] = request
rendered = template.render(context)
if TESTS_ENABLED:
- TEMPLATE_TEST_CONTEXT[template] = context
+ TEMPLATE_TEST_CONTEXT[template_path] = context
return rendered