aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tests')
-rw-r--r--mediagoblin/tests/test_auth.py88
-rw-r--r--mediagoblin/tests/test_cache.py52
-rw-r--r--mediagoblin/tests/test_mgoblin_app.ini4
-rw-r--r--mediagoblin/tests/test_storage.py6
-rw-r--r--mediagoblin/tests/test_submission.py5
5 files changed, 150 insertions, 5 deletions
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py
index eed418c6..fbbe1613 100644
--- a/mediagoblin/tests/test_auth.py
+++ b/mediagoblin/tests/test_auth.py
@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import urlparse
+import datetime
from nose.tools import assert_equal
@@ -237,6 +238,93 @@ def test_register_views(test_app):
## TODO: Also check for double instances of an email address?
+ ### Oops, forgot the password
+ # -------------------
+ util.clear_test_template_context()
+ response = test_app.post(
+ '/auth/forgot_password/',
+ {'username': 'happygirl'})
+ response.follow()
+
+ ## Did we redirect to the proper page? Use the right template?
+ assert_equal(
+ urlparse.urlsplit(response.location)[2],
+ '/auth/forgot_password/email_sent/')
+ assert util.TEMPLATE_TEST_CONTEXT.has_key(
+ 'mediagoblin/auth/fp_email_sent.html')
+
+ ## Make sure link to change password is sent by email
+ assert len(util.EMAIL_TEST_INBOX) == 1
+ message = util.EMAIL_TEST_INBOX.pop()
+ assert message['To'] == 'happygrrl@example.org'
+ email_context = util.TEMPLATE_TEST_CONTEXT[
+ 'mediagoblin/auth/fp_verification_email.txt']
+ #TODO - change the name of verification_url to something forgot-password-ish
+ assert email_context['verification_url'] in message.get_payload(decode=True)
+
+ path = urlparse.urlsplit(email_context['verification_url'])[2]
+ get_params = urlparse.urlsplit(email_context['verification_url'])[3]
+ assert path == u'/auth/forgot_password/verify/'
+ parsed_get_params = urlparse.parse_qs(get_params)
+
+ # user should have matching parameters
+ new_user = mg_globals.database.User.find_one({'username': 'happygirl'})
+ assert parsed_get_params['userid'] == [unicode(new_user['_id'])]
+ assert parsed_get_params['token'] == [new_user['fp_verification_key']]
+
+ ### The forgotten password token should be set to expire in ~ 10 days
+ # A few ticks have expired so there are only 9 full days left...
+ assert (new_user['fp_token_expire'] - datetime.datetime.now()).days == 9
+
+ ## Try using a bs password-changing verification key, shouldn't work
+ util.clear_test_template_context()
+ response = test_app.get(
+ "/auth/forgot_password/verify/?userid=%s&token=total_bs" % unicode(
+ new_user['_id']), status=400)
+ assert response.status == '400 Bad Request'
+
+ ## Try using an expired token to change password, shouldn't work
+ util.clear_test_template_context()
+ real_token_expiration = new_user['fp_token_expire']
+ new_user['fp_token_expire'] = datetime.datetime.now()
+ new_user.save()
+ response = test_app.get("%s?%s" % (path, get_params), status=400)
+ assert response.status == '400 Bad Request'
+ new_user['fp_token_expire'] = real_token_expiration
+ new_user.save()
+
+ ## Verify step 1 of password-change works -- can see form to change password
+ util.clear_test_template_context()
+ response = test_app.get("%s?%s" % (path, get_params))
+ assert util.TEMPLATE_TEST_CONTEXT.has_key('mediagoblin/auth/change_fp.html')
+
+ ## Verify step 2.1 of password-change works -- report success to user
+ util.clear_test_template_context()
+ response = test_app.post(
+ '/auth/forgot_password/verify/', {
+ 'userid': parsed_get_params['userid'],
+ 'password': 'iamveryveryhappy',
+ 'confirm_password': 'iamveryveryhappy',
+ 'token': parsed_get_params['token']})
+ response.follow()
+ assert util.TEMPLATE_TEST_CONTEXT.has_key(
+ 'mediagoblin/auth/fp_changed_success.html')
+
+ ## Verify step 2.2 of password-change works -- login w/ new password success
+ util.clear_test_template_context()
+ response = test_app.post(
+ '/auth/login/', {
+ 'username': u'happygirl',
+ 'password': 'iamveryveryhappy'})
+
+ # User should be redirected
+ response.follow()
+ assert_equal(
+ urlparse.urlsplit(response.location)[2],
+ '/')
+ assert util.TEMPLATE_TEST_CONTEXT.has_key(
+ 'mediagoblin/root.html')
+
@setup_fresh_app
def test_authentication_views(test_app):
diff --git a/mediagoblin/tests/test_cache.py b/mediagoblin/tests/test_cache.py
new file mode 100644
index 00000000..cbffeb84
--- /dev/null
+++ b/mediagoblin/tests/test_cache.py
@@ -0,0 +1,52 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011 Free Software Foundation, Inc
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# 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 import mg_globals
+
+
+DATA_TO_CACHE = {
+ 'herp': 'derp',
+ 'lol': 'cats'}
+
+
+def _get_some_data(key):
+ """
+ Stuid function that makes use of some caching.
+ """
+ some_data_cache = mg_globals.cache.get_cache('sum_data')
+ if some_data_cache.has_key(key):
+ return some_data_cache.get(key)
+
+ value = DATA_TO_CACHE.get(key)
+ some_data_cache.put(key, value)
+ return value
+
+
+@setup_fresh_app
+def test_cache_working(test_app):
+ some_data_cache = mg_globals.cache.get_cache('sum_data')
+ assert not some_data_cache.has_key('herp')
+ assert _get_some_data('herp') == 'derp'
+ assert some_data_cache.get('herp') == 'derp'
+ # should get the same value again
+ assert _get_some_data('herp') == 'derp'
+
+ # now we force-change it, but the function should use the cached
+ # version
+ some_data_cache.put('herp', 'pred')
+ assert _get_some_data('herp') == 'pred'
diff --git a/mediagoblin/tests/test_mgoblin_app.ini b/mediagoblin/tests/test_mgoblin_app.ini
index 9d938b4f..ab32cccc 100644
--- a/mediagoblin/tests/test_mgoblin_app.ini
+++ b/mediagoblin/tests/test_mgoblin_app.ini
@@ -19,5 +19,9 @@ base_url = /mgoblin_media/
[storage:queuestore]
base_dir = %(here)s/test_user_dev/media/queue
+[beaker.cache]
+data_dir = %(here)s/test_user_dev/beaker/cache/data
+lock_dir = %(here)s/test_user_dev/beaker/cache/lock
+
[celery]
celery_always_eager = true
diff --git a/mediagoblin/tests/test_storage.py b/mediagoblin/tests/test_storage.py
index 9c96f6ca..46ecb2ec 100644
--- a/mediagoblin/tests/test_storage.py
+++ b/mediagoblin/tests/test_storage.py
@@ -52,7 +52,7 @@ class FakeStorageSystem():
self.foobie = foobie
self.blech = blech
-class FakeRemoteStorage(storage.BasicFileStorage):
+class FakeRemoteStorage(storage.filestorage.BasicFileStorage):
# Theoretically despite this, all the methods should work but it
# should force copying to the workbench
local_storage = False
@@ -66,7 +66,7 @@ def test_storage_system_from_config():
'garbage_arg': 'trash'})
assert this_storage.base_url == 'http://example.org/moodia/'
assert this_storage.base_dir == '/tmp/'
- assert this_storage.__class__ is storage.BasicFileStorage
+ assert this_storage.__class__ is storage.filestorage.BasicFileStorage
this_storage = storage.storage_system_from_config(
{'foobie': 'eiboof',
@@ -88,7 +88,7 @@ def get_tmp_filestorage(mount_url=None, fake_remote=False):
if fake_remote:
this_storage = FakeRemoteStorage(tmpdir, mount_url)
else:
- this_storage = storage.BasicFileStorage(tmpdir, mount_url)
+ this_storage = storage.filestorage.BasicFileStorage(tmpdir, mount_url)
return tmpdir, this_storage
diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
index b7013839..007c0348 100644
--- a/mediagoblin/tests/test_submission.py
+++ b/mediagoblin/tests/test_submission.py
@@ -178,7 +178,8 @@ class TestSubmission:
# No work: user=media.uploader().username,
user=self.test_user['username'],
media=media['_id']),
- {'confirm': 'False'})
+ # no value means no confirm
+ {})
response.follow()
@@ -197,7 +198,7 @@ class TestSubmission:
# No work: user=media.uploader().username,
user=self.test_user['username'],
media=media['_id']),
- {'confirm': 'True'})
+ {'confirm': 'y'})
response.follow()