本文整理汇总了Python中mediagoblin.tools.template.clear_test_template_context函数的典型用法代码示例。如果您正苦于以下问题:Python clear_test_template_context函数的具体用法?Python clear_test_template_context怎么用?Python clear_test_template_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clear_test_template_context函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _test_add_existing
def _test_add_existing():
template.clear_test_template_context()
res = persona_plugin_app.post(
'/edit/persona/add/')
res.follow()
assert urlparse.urlsplit(res.location)[2] == '/edit/persona/'
开发者ID:ausbin,项目名称:mediagoblin,代码行数:7,代码来源:test_persona.py
示例2: _test_delete
def _test_delete(self, test_user):
# Delete openid from user
# Create another user to test deleting OpenID that doesn't belong to them
new_user = fixture_add_user(username="newman")
openid = OpenIDUserURL()
openid.openid_url = "http://realfake.myopenid.com/"
openid.user_id = new_user.id
openid.save()
# Try and delete OpenID url that isn't the users
template.clear_test_template_context()
res = openid_plugin_app.post("/edit/openid/delete/", {"openid": "http://realfake.myopenid.com/"})
context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/plugins/openid/delete.html"]
form = context["form"]
assert form.openid.errors == [u"That OpenID is not registered to this account."]
# Delete OpenID
# Kind of weird to POST to delete/finish
template.clear_test_template_context()
res = openid_plugin_app.post("/edit/openid/delete/finish/", {"openid": u"http://add.myopenid.com"})
res.follow()
# Correct place?
assert urlparse.urlsplit(res.location)[2] == "/edit/account/"
assert "mediagoblin/edit/edit_account.html" in template.TEMPLATE_TEST_CONTEXT
# OpenID deleted?
new_openid = mg_globals.database.OpenIDUserURL.query.filter_by(
openid_url=u"http://add.myopenid.com"
).first()
assert not new_openid
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:31,代码来源:test_openid.py
示例3: _do_request
def _do_request(self, url, *context_keys, **kwargs):
template.clear_test_template_context()
response = self.test_app.request(url, **kwargs)
context_data = template.TEMPLATE_TEST_CONTEXT
for key in context_keys:
context_data = context_data[key]
return response, context_data
开发者ID:ausbin,项目名称:mediagoblin,代码行数:7,代码来源:__init__.py
示例4: test_change_password
def test_change_password(self, test_app):
"""Test changing password correctly and incorrectly"""
self.login(test_app)
# test that the password can be changed
template.clear_test_template_context()
res = test_app.post(
'/edit/password/', {
'old_password': 'toast',
'new_password': '123456',
})
res.follow()
# Did we redirect to the correct page?
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
# test_user has to be fetched again in order to have the current values
test_user = User.query.filter_by(username=u'chris').first()
assert auth.check_password('123456', test_user.pw_hash)
# Update current user passwd
self.user_password = '123456'
# test that the password cannot be changed if the given
# old_password is wrong
template.clear_test_template_context()
test_app.post(
'/edit/password/', {
'old_password': 'toast',
'new_password': '098765',
})
test_user = User.query.filter_by(username=u'chris').first()
assert not auth.check_password('098765', test_user.pw_hash)
开发者ID:RichoHan,项目名称:MediaGoblin,代码行数:33,代码来源:test_edit.py
示例5: _test_non_response
def _test_non_response():
template.clear_test_template_context()
res = openid_plugin_app.post("/auth/openid/login/", {"openid": "http://phoney.myopenid.com/"})
res.follow()
# Correct Place?
assert urlparse.urlsplit(res.location)[2] == "/auth/openid/login/"
assert "mediagoblin/plugins/openid/login.html" in template.TEMPLATE_TEST_CONTEXT
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:8,代码来源:test_openid.py
示例6: _test_non_response
def _test_non_response():
template.clear_test_template_context()
res = openid_plugin_app.post(
'/auth/openid/login/', {
'openid': 'http://phoney.myopenid.com/'})
res.follow()
# Correct Place?
assert urlparse.urlsplit(res.location)[2] == '/auth/openid/login/'
assert 'mediagoblin/plugins/openid/login.html' in template.TEMPLATE_TEST_CONTEXT
开发者ID:commonsmachinery,项目名称:mediagoblin,代码行数:10,代码来源:test_openid.py
示例7: do_post
def do_post(self, data, *context_keys, **kwargs):
url = kwargs.pop('url', '/submit/')
do_follow = kwargs.pop('do_follow', False)
template.clear_test_template_context()
response = self.test_app.post(url, data, **kwargs)
if do_follow:
response.follow()
context_data = template.TEMPLATE_TEST_CONTEXT
for key in context_keys:
context_data = context_data[key]
return response, context_data
开发者ID:piratas,项目名称:biblioteca,代码行数:11,代码来源:test_submission.py
示例8: _test_new_user
def _test_new_user():
openid_plugin_app.post(
'/auth/openid/login/', {
'openid': u'http://real.myopenid.com'})
# Right place?
assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
register_form = context['register_form']
# Register User
res = openid_plugin_app.post(
'/auth/openid/register/', {
'openid': register_form.openid.data,
'username': u'chris',
'email': u'[email protected]'})
res.follow()
# Correct place?
assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT
# No need to test if user is in logged in and verification email
# awaits, since openid uses the register_user function which is
# tested in test_auth
# Logout User
openid_plugin_app.get('/auth/logout')
# Get user and detach from session
test_user = mg_globals.database.LocalUser.query.filter(
LocalUser.username==u'chris'
).first()
Session.expunge(test_user)
# Log back in
# Could not get it to work by 'POST'ing to /auth/openid/login/
template.clear_test_template_context()
res = openid_plugin_app.post(
'/auth/openid/login/finish/', {
'openid': u'http://real.myopenid.com'})
res.follow()
assert urlparse.urlsplit(res.location)[2] == '/'
assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
# Make sure user is in the session
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
session = context['request'].session
assert session['user_id'] == six.text_type(test_user.id)
开发者ID:ausbin,项目名称:mediagoblin,代码行数:50,代码来源:test_openid.py
示例9: _test_authentication
def _test_authentication():
template.clear_test_template_context()
res = ldap_plugin_app.post(
'/auth/ldap/login/',
{'username': u'chris',
'password': u'toast'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
register_form = context['register_form']
assert register_form.username.data == u'chris'
assert register_form.email.data == u'[email protected]'
template.clear_test_template_context()
res = ldap_plugin_app.post(
'/auth/ldap/register/',
{'username': u'chris',
'email': u'[email protected]'})
res.follow()
assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
assert 'mediagoblin/user_pages/user.html' in template.TEMPLATE_TEST_CONTEXT
# Try to register with same email and username
template.clear_test_template_context()
res = ldap_plugin_app.post(
'/auth/ldap/register/',
{'username': u'chris',
'email': u'[email protected]'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
register_form = context['register_form']
assert register_form.email.errors == [u'Sorry, a user with that email address already exists.']
assert register_form.username.errors == [u'Sorry, a user with that name already exists.']
# Log out
ldap_plugin_app.get('/auth/logout/')
# Get user and detach from session
test_user = mg_globals.database.User.query.filter_by(
username=u'chris').first()
Session.expunge(test_user)
# Log back in
template.clear_test_template_context()
res = ldap_plugin_app.post(
'/auth/ldap/login/',
{'username': u'chris',
'password': u'toast'})
res.follow()
assert urlparse.urlsplit(res.location)[2] == '/'
assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
# Make sure user is in the session
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
session = context['request'].session
assert session['user_id'] == unicode(test_user.id)
开发者ID:commonsmachinery,项目名称:mediagoblin,代码行数:59,代码来源:test_ldap.py
示例10: _test_add
def _test_add():
# Successful add
template.clear_test_template_context()
res = openid_plugin_app.post("/edit/openid/", {"openid": u"http://add.myopenid.com"})
res.follow()
# Correct place?
assert urlparse.urlsplit(res.location)[2] == "/edit/account/"
assert "mediagoblin/edit/edit_account.html" in template.TEMPLATE_TEST_CONTEXT
# OpenID Added?
new_openid = mg_globals.database.OpenIDUserURL.query.filter_by(
openid_url=u"http://add.myopenid.com"
).first()
assert new_openid
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:15,代码来源:test_openid.py
示例11: clear_test_buckets
def clear_test_buckets():
"""
We store some things for testing purposes that should be cleared
when we want a "clean slate" of information for our next round of
tests. Call this function to wipe all that stuff clean.
Also wipes out some other things we might redefine during testing,
like the jinja envs.
"""
global SETUP_JINJA_ENVS
SETUP_JINJA_ENVS = {}
global EMAIL_TEST_INBOX
global EMAIL_TEST_MBOX_INBOX
EMAIL_TEST_INBOX = []
EMAIL_TEST_MBOX_INBOX = []
clear_test_template_context()
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:18,代码来源:testing.py
示例12: _test_edit_persona
def _test_edit_persona():
# Try and delete only Persona email address
template.clear_test_template_context()
res = persona_plugin_app.post(
'/edit/persona/',
{'email': '[email protected]'})
assert 'mediagoblin/plugins/persona/edit.html' in template.TEMPLATE_TEST_CONTEXT
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/persona/edit.html']
form = context['form']
assert form.email.errors == [u"You can't delete your only Persona email address unless you have a password set."]
template.clear_test_template_context()
res = persona_plugin_app.post(
'/edit/persona/', {})
assert 'mediagoblin/plugins/persona/edit.html' in template.TEMPLATE_TEST_CONTEXT
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/persona/edit.html']
form = context['form']
assert form.email.errors == [u'This field is required.']
# Try and delete Persona not owned by the user
template.clear_test_template_context()
res = persona_plugin_app.post(
'/edit/persona/',
{'email': '[email protected]'})
assert 'mediagoblin/plugins/persona/edit.html' in template.TEMPLATE_TEST_CONTEXT
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/plugins/persona/edit.html']
form = context['form']
assert form.email.errors == [u'That Persona email address is not registered to this account.']
res = persona_plugin_app.get('/edit/persona/add/')
assert urlparse.urlsplit(res.location)[2] == '/edit/persona/'
# Add Persona email address
template.clear_test_template_context()
res = persona_plugin_app.post(
'/edit/persona/add/')
res.follow()
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
# Delete a Persona
res = persona_plugin_app.post(
'/edit/persona/',
{'email': '[email protected]'})
res.follow()
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
开发者ID:ausbin,项目名称:mediagoblin,代码行数:54,代码来源:test_persona.py
示例13: _test_new_user
def _test_new_user():
openid_plugin_app.post("/auth/openid/login/", {"openid": u"http://real.myopenid.com"})
# Right place?
assert "mediagoblin/auth/register.html" in template.TEMPLATE_TEST_CONTEXT
context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/auth/register.html"]
register_form = context["register_form"]
# Register User
res = openid_plugin_app.post(
"/auth/openid/register/",
{"openid": register_form.openid.data, "username": u"chris", "email": u"[email protected]"},
)
res.follow()
# Correct place?
assert urlparse.urlsplit(res.location)[2] == "/u/chris/"
assert "mediagoblin/user_pages/user.html" in template.TEMPLATE_TEST_CONTEXT
# No need to test if user is in logged in and verification email
# awaits, since openid uses the register_user function which is
# tested in test_auth
# Logout User
openid_plugin_app.get("/auth/logout")
# Get user and detach from session
test_user = mg_globals.database.User.query.filter_by(username=u"chris").first()
Session.expunge(test_user)
# Log back in
# Could not get it to work by 'POST'ing to /auth/openid/login/
template.clear_test_template_context()
res = openid_plugin_app.post("/auth/openid/login/finish/", {"openid": u"http://real.myopenid.com"})
res.follow()
assert urlparse.urlsplit(res.location)[2] == "/"
assert "mediagoblin/root.html" in template.TEMPLATE_TEST_CONTEXT
# Make sure user is in the session
context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/root.html"]
session = context["request"].session
assert session["user_id"] == unicode(test_user.id)
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:43,代码来源:test_openid.py
示例14: test_sniffing
def test_sniffing(self):
'''
Test sniffing mechanism to assert that regular uploads work as intended
'''
template.clear_test_template_context()
response = self.test_app.post(
'/submit/', {
'title': u'UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE'
}, upload_files=[(
'file', GOOD_JPG)])
response.follow()
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/user_pages/user.html']
request = context['request']
media = request.db.MediaEntry.query.filter_by(
title=u'UNIQUE_TITLE_PLS_DONT_CREATE_OTHER_MEDIA_WITH_THIS_TITLE').first()
assert media.media_type == 'mediagoblin.media_types.image'
开发者ID:piratas,项目名称:biblioteca,代码行数:21,代码来源:test_submission.py
示例15: test_authentication_disabled_app
def test_authentication_disabled_app(authentication_disabled_app):
# app.auth should = false
assert mg_globals
assert mg_globals.app.auth is False
# Try to visit register page
template.clear_test_template_context()
response = authentication_disabled_app.get('/auth/register/')
response.follow()
# Correct redirect?
assert urlparse.urlsplit(response.location)[2] == '/'
assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
# Try to vist login page
template.clear_test_template_context()
response = authentication_disabled_app.get('/auth/login/')
response.follow()
# Correct redirect?
assert urlparse.urlsplit(response.location)[2] == '/'
assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
## Test check_login_simple should return None
assert auth_tools.check_login_simple('test', 'simple') is None
# Try to visit the forgot password page
template.clear_test_template_context()
response = authentication_disabled_app.get('/auth/register/')
response.follow()
# Correct redirect?
assert urlparse.urlsplit(response.location)[2] == '/'
assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:34,代码来源:test_auth.py
示例16: test_bad_login
def test_bad_login(self, openid_plugin_app):
""" Test that attempts to login with invalid paramaters"""
# Test GET request for auth/register page
res = openid_plugin_app.get("/auth/register/").follow()
# Make sure it redirected to the correct place
assert urlparse.urlsplit(res.location)[2] == "/auth/openid/login/"
# Test GET request for auth/login page
res = openid_plugin_app.get("/auth/login/")
res.follow()
# Correct redirect?
assert urlparse.urlsplit(res.location)[2] == "/auth/openid/login/"
# Test GET request for auth/openid/register page
res = openid_plugin_app.get("/auth/openid/register/")
res.follow()
# Correct redirect?
assert urlparse.urlsplit(res.location)[2] == "/auth/openid/login/"
# Test GET request for auth/openid/login/finish page
res = openid_plugin_app.get("/auth/openid/login/finish/")
res.follow()
# Correct redirect?
assert urlparse.urlsplit(res.location)[2] == "/auth/openid/login/"
# Test GET request for auth/openid/login page
res = openid_plugin_app.get("/auth/openid/login/")
# Correct place?
assert "mediagoblin/plugins/openid/login.html" in template.TEMPLATE_TEST_CONTEXT
# Try to login with an empty form
template.clear_test_template_context()
openid_plugin_app.post("/auth/openid/login/", {})
context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/plugins/openid/login.html"]
form = context["login_form"]
assert form.openid.errors == [u"This field is required."]
# Try to login with wrong form values
template.clear_test_template_context()
openid_plugin_app.post("/auth/openid/login/", {"openid": "not_a_url.com"})
context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/plugins/openid/login.html"]
form = context["login_form"]
assert form.openid.errors == [u"Please enter a valid url."]
# Should be no users in the db
assert User.query.count() == 0
# Phony OpenID URl
template.clear_test_template_context()
openid_plugin_app.post("/auth/openid/login/", {"openid": "http://phoney.myopenid.com/"})
context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/plugins/openid/login.html"]
form = context["login_form"]
assert form.openid.errors == [u"Sorry, the OpenID server could not be found"]
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:59,代码来源:test_openid.py
示例17: test_change_password
def test_change_password(test_app):
"""Test changing password correctly and incorrectly"""
test_user = fixture_add_user(
password=u'toast',
privileges=[u'active'])
test_app.post(
'/auth/login/', {
'username': u'chris',
'password': u'toast'})
# test that the password can be changed
res = test_app.post(
'/edit/password/', {
'old_password': 'toast',
'new_password': '123456',
})
res.follow()
# Did we redirect to the correct page?
assert urlparse.urlsplit(res.location)[2] == '/edit/account/'
# test_user has to be fetched again in order to have the current values
test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
assert auth_tools.bcrypt_check_password('123456', test_user.pw_hash)
# test that the password cannot be changed if the given
# old_password is wrong
template.clear_test_template_context()
test_app.post(
'/edit/password/', {
'old_password': 'toast',
'new_password': '098765',
})
test_user = LocalUser.query.filter(LocalUser.username==u'chris').first()
assert not auth_tools.bcrypt_check_password('098765', test_user.pw_hash)
开发者ID:ausbin,项目名称:mediagoblin,代码行数:37,代码来源:test_basic_auth.py
示例18: test_change_password
def test_change_password(test_app):
"""Test changing password correctly and incorrectly"""
test_user = fixture_add_user(password=u"toast", privileges=[u"active"])
test_app.post("/auth/login/", {"username": u"chris", "password": u"toast"})
# test that the password can be changed
res = test_app.post("/edit/password/", {"old_password": "toast", "new_password": "123456"})
res.follow()
# Did we redirect to the correct page?
assert urlparse.urlsplit(res.location)[2] == "/edit/account/"
# test_user has to be fetched again in order to have the current values
test_user = User.query.filter_by(username=u"chris").first()
assert auth_tools.bcrypt_check_password("123456", test_user.pw_hash)
# test that the password cannot be changed if the given
# old_password is wrong
template.clear_test_template_context()
test_app.post("/edit/password/", {"old_password": "toast", "new_password": "098765"})
test_user = User.query.filter_by(username=u"chris").first()
assert not auth_tools.bcrypt_check_password("098765", test_user.pw_hash)
开发者ID:vasilenkomike,项目名称:mediagoblin,代码行数:24,代码来源:test_basic_auth.py
示例19: test_register_views
def test_register_views(test_app):
"""
Massive test function that all our registration-related views all work.
"""
# Test doing a simple GET on the page
# -----------------------------------
test_app.get('/auth/register/')
# Make sure it rendered with the appropriate template
assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
# Try to register without providing anything, should error
# --------------------------------------------------------
template.clear_test_template_context()
test_app.post(
'/auth/register/', {})
context = template.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.email.errors == [u'This field is required.']
# Try to register with fields that are known to be invalid
# --------------------------------------------------------
## too short
template.clear_test_template_context()
test_app.post(
'/auth/register/', {
'username': 'l',
'password': 'o',
'email': 'l'})
context = template.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 5 and 1024 characters long.']
## bad form
template.clear_test_template_context()
test_app.post(
'/auth/register/', {
'username': '@[email protected]',
'email': 'lollerskates'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
form = context['register_form']
assert form.username.errors == [u'This field does not take email addresses.']
assert form.email.errors == [u'This field requires an email address.']
## At this point there should be no users in the database ;)
assert User.query.count() == 0
# Successful register
# -------------------
template.clear_test_template_context()
response = test_app.post(
'/auth/register/', {
'username': u'angrygirl',
'password': 'iamsoangry',
'email': '[email protected]'})
response.follow()
## Did we redirect to the proper page? Use the right template?
assert urlparse.urlsplit(response.location)[2] == '/u/angrygirl/'
assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT
## Make sure user is in place
new_user = mg_globals.database.User.query.filter_by(
username=u'angrygirl').first()
assert new_user
## Make sure that the proper privileges are granted on registration
assert new_user.has_privilege(u'commenter')
assert new_user.has_privilege(u'uploader')
assert new_user.has_privilege(u'reporter')
assert not new_user.has_privilege(u'active')
## Make sure user is logged in
request = template.TEMPLATE_TEST_CONTEXT[
'mediagoblin/user_pages/user_nonactive.html']['request']
assert request.session['user_id'] == six.text_type(new_user.id)
## Make sure we get email confirmation, and try verifying
assert len(mail.EMAIL_TEST_INBOX) == 1
message = mail.EMAIL_TEST_INBOX.pop()
assert message['To'] == '[email protected]'
email_context = template.TEMPLATE_TEST_CONTEXT[
'mediagoblin/auth/verification_email.txt']
assert email_context['verification_url'].encode('ascii') 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/verify_email/'
parsed_get_params = urlparse.parse_qs(get_params)
## Try verifying with bs verification key, shouldn't work
template.clear_test_template_context()
response = test_app.get(
#.........这里部分代码省略.........
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:101,代码来源:test_auth.py
示例20: test_authentication_views
def test_authentication_views(test_app):
"""
Test logging in and logging out
"""
# Make a new user
test_user = fixture_add_user()
# Get login
# ---------
test_app.get('/auth/login/')
assert 'mediagoblin/auth/login.html' in template.TEMPLATE_TEST_CONTEXT
# Failed login - blank form
# -------------------------
template.clear_test_template_context()
response = test_app.post('/auth/login/')
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
form = context['login_form']
assert form.username.errors == [u'This field is required.']
# Failed login - blank user
# -------------------------
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
'password': u'toast'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
form = context['login_form']
assert form.username.errors == [u'This field is required.']
# Failed login - blank password
# -----------------------------
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
'username': u'chris'})
assert 'mediagoblin/auth/login.html' in template.TEMPLATE_TEST_CONTEXT
# Failed login - bad user
# -----------------------
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
'username': u'steve',
'password': 'toast'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
assert context['login_failed']
# Failed login - bad password
# ---------------------------
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
'username': u'chris',
'password': 'jam_and_ham'})
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
assert context['login_failed']
# Successful login
# ----------------
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
'username': u'chris',
'password': 'toast'})
# User should be redirected
response.follow()
assert urlparse.urlsplit(response.location)[2] == '/'
assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
# Make sure user is in the session
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
session = context['request'].session
assert session['user_id'] == six.text_type(test_user.id)
# Successful logout
# -----------------
template.clear_test_template_context()
response = test_app.get('/auth/logout/')
# Should be redirected to index page
response.follow()
assert urlparse.urlsplit(response.location)[2] == '/'
assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
# Make sure the user is not in the session
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
session = context['request'].session
assert 'user_id' not in session
# User is redirected to custom URL if POST['next'] is set
# -------------------------------------------------------
template.clear_test_template_context()
response = test_app.post(
'/auth/login/', {
'username': u'chris',
'password': 'toast',
'next' : '/u/chris/'})
#.........这里部分代码省略.........
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:101,代码来源:test_auth.py
注:本文中的mediagoblin.tools.template.clear_test_template_context函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论