from nose.tools import assert_equal
from mediagoblin.auth import lib as auth_lib
-from mediagoblin.tests.tools import setup_fresh_app
+from mediagoblin.tests.tools import setup_fresh_app, fixture_add_user
from mediagoblin import mg_globals
from mediagoblin.tools import template, mail
Test logging in and logging out
"""
# Make a new user
- test_user = mg_globals.database.User()
- test_user['username'] = u'chris'
- test_user['email'] = u'chris@example.com'
- test_user['pw_hash'] = auth_lib.bcrypt_gen_password_hash('toast')
- test_user.save()
+ test_user = fixture_add_user(active_user=False)
# Get login
# ---------
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from mediagoblin import mg_globals
-from mediagoblin.tests.tools import setup_fresh_app
+from mediagoblin.tests.tools import setup_fresh_app, fixture_add_user
from mediagoblin.tools import template
-from mediagoblin.auth.lib import bcrypt_check_password, \
- bcrypt_gen_password_hash
+from mediagoblin.auth.lib import bcrypt_check_password
@setup_fresh_app
def test_change_password(test_app):
"""Test changing password correctly and incorrectly"""
# set up new user
- test_user = mg_globals.database.User()
- test_user['username'] = u'chris'
- test_user['email'] = u'chris@example.com'
- test_user['email_verified'] = True
- test_user['status'] = u'active'
- test_user['pw_hash'] = bcrypt_gen_password_hash('toast')
- test_user.save()
+ test_user = fixture_add_user()
test_app.post(
'/auth/login/', {
def change_bio_url(test_app):
"""Test changing bio and URL"""
# set up new user
- test_user = mg_globals.database.User()
- test_user['username'] = u'chris'
- test_user['email'] = u'chris@example.com'
- test_user['email_verified'] = True
- test_user['status'] = u'active'
- test_user['pw_hash'] = bcrypt_gen_password_hash('toast')
- test_user.save()
+ test_user = fixture_add_user()
# test changing the bio and the URL properly
test_app.post(
from nose.tools import assert_equal, assert_true, assert_false
-from mediagoblin.auth import lib as auth_lib
-from mediagoblin.tests.tools import setup_fresh_app, get_test_app
+from mediagoblin.tests.tools import setup_fresh_app, get_test_app, \
+ fixture_add_user
from mediagoblin import mg_globals
from mediagoblin.tools import template, common
# TODO: Possibly abstract into a decorator like:
# @as_authenticated_user('chris')
- test_user = mg_globals.database.User()
- test_user['username'] = u'chris'
- test_user['email'] = u'chris@example.com'
- test_user['email_verified'] = True
- test_user['status'] = u'active'
- test_user['pw_hash'] = auth_lib.bcrypt_gen_password_hash('toast')
- test_user.save()
+ test_user = fixture_add_user()
self.test_user = test_user
from mediagoblin.decorators import _make_safe
from mediagoblin.db.open import setup_connection_and_db_from_config
from mediagoblin.meddleware import BaseMeddleware
+from mediagoblin.auth.lib import bcrypt_gen_password_hash
MEDIAGOBLIN_TEST_DB_NAME = u'__mediagoblin_tests__'
document = collection.find_one({'_id': expected_document['_id']})
assert document is not None # make sure it exists
assert document == expected_document # make sure it matches
+
+
+def fixture_add_user(username = u'chris', password = 'toast',
+ active_user = True):
+ test_user = mg_globals.database.User()
+ test_user.username = username
+ test_user.email = username + u'@example.com'
+ if password is not None:
+ test_user.pw_hash = bcrypt_gen_password_hash(password)
+ if active_user:
+ test_user.email_verified = True
+ test_user.status = u'active'
+
+ test_user.save()
+
+ return test_user