本文整理汇总了Python中devmo.tests.LocalizingClient.logout方法的典型用法代码示例。如果您正苦于以下问题:Python LocalizingClient.logout方法的具体用法?Python LocalizingClient.logout怎么用?Python LocalizingClient.logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类devmo.tests.LocalizingClient
的用法示例。
在下文中一共展示了LocalizingClient.logout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_404_already_logged_in
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import logout [as 别名]
def test_404_already_logged_in(self):
"""The login buttons should not display on the 404 page when the user is logged in"""
client = LocalizingClient()
# View page as a logged in user
client.login(username='testuser',
password='testpass')
response = client.get('/something-doesnt-exist', follow=True)
doc = pq(response.content)
login_block = doc.find('.socialaccount_providers')
eq_(len(login_block), 0)
eq_(404, response.status_code)
client.logout()
示例2: LoginTestCase
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import logout [as 别名]
class LoginTestCase(TestCase):
fixtures = ['test_users.json']
def setUp(self):
self.old_debug = settings.DEBUG
settings.DEBUG = True
self.client = LocalizingClient()
self.client.logout()
def tearDown(self):
settings.DEBUG = self.old_debug
@mock.patch_object(Site.objects, 'get_current')
def test_clean_next_url_request_properties(self, get_current):
'''_clean_next_url checks POST, GET, and REFERER'''
get_current.return_value.domain = 'dev.mo.org'
r = RequestFactory().get('/users/login', {'next': '/demos/submit'},
HTTP_REFERER='referer-trumped-by-get')
eq_('/demos/submit', _clean_next_url(r))
r = RequestFactory().post('/users/login', {'next': '/demos/submit'})
eq_('/demos/submit', _clean_next_url(r))
r = RequestFactory().get('/users/login', HTTP_REFERER='/demos/submit')
eq_('/demos/submit', _clean_next_url(r))
@mock.patch_object(Site.objects, 'get_current')
def test_clean_next_url_no_self_redirects(self, get_current):
'''_clean_next_url checks POST, GET, and REFERER'''
get_current.return_value.domain = 'dev.mo.org'
for next in [settings.LOGIN_URL, settings.LOGOUT_URL]:
r = RequestFactory().get('/users/login', {'next': next})
eq_(None, _clean_next_url(r))
@mock.patch_object(Site.objects, 'get_current')
def test_clean_next_url_invalid_next_parameter(self, get_current):
'''_clean_next_url cleans invalid urls'''
get_current.return_value.domain = 'dev.mo.org'
for next in self._invalid_nexts():
r = RequestFactory().get('/users/login', {'next': next})
eq_(None, _clean_next_url(r))
def _invalid_nexts(self):
return ['http://foobar.com/evil/', '//goo.gl/y-bad']
示例3: test_ban_permission
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import logout [as 别名]
def test_ban_permission(self):
"""The ban permission controls access to the ban view."""
client = LocalizingClient()
admin = User.objects.get(username='admin')
testuser = User.objects.get(username='testuser')
# testuser doesn't have ban permission, can't ban.
client.login(username='testuser',
password='testpass')
ban_url = reverse('users.ban_user',
kwargs={'user_id': admin.id})
resp = client.get(ban_url)
eq_(302, resp.status_code)
ok_(settings.LOGIN_URL in resp['Location'])
client.logout()
# admin has ban permission, can ban.
client.login(username='admin',
password='testpass')
ban_url = reverse('users.ban_user',
kwargs={'user_id': testuser.id})
resp = client.get(ban_url)
eq_(200, resp.status_code)
示例4: LoginTestCase
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import logout [as 别名]
class LoginTestCase(TestCase):
fixtures = ['test_users.json']
def setUp(self):
self.old_debug = settings.DEBUG
settings.DEBUG = True
self.client = LocalizingClient()
self.client.logout()
def tearDown(self):
settings.DEBUG = self.old_debug
@mock.patch_object(Site.objects, 'get_current')
def test_bad_login_fails_both_backends(self, get_current):
get_current.return_value.domain = 'dev.mo.org'
self.assertRaises(User.DoesNotExist, User.objects.get,
username='nouser')
response = self.client.post(reverse('users.login'),
{'username': 'nouser',
'password': 'nopass'}, follow=True)
eq_(200, response.status_code)
self.assertContains(response, 'Please enter a correct username and '
'password.')
@mock.patch_object(Site.objects, 'get_current')
def test_django_login(self, get_current):
get_current.return_value.domain = 'dev.mo.org'
response = self.client.post(reverse('users.login'),
{'username': 'testuser',
'password': 'testpass'}, follow=True)
eq_(200, response.status_code)
doc = pq(response.content)
eq_('testuser', doc.find('ul.user-state a:first').text())
@mock.patch_object(Site.objects, 'get_current')
def test_django_login_wont_redirect_to_login(self, get_current):
get_current.return_value.domain = 'dev.mo.org'
login_uri = reverse('users.login')
response = self.client.post(login_uri,
{'username': 'testuser',
'password': 'testpass',
'next': login_uri},
follow=True)
eq_(200, response.status_code)
for redirect_url, code in response.redirect_chain:
ok_(login_uri not in redirect_url, "Found %s in redirect_chain"
% login_uri)
doc = pq(response.content)
eq_('testuser', doc.find('ul.user-state a:first').text())
@mock.patch_object(Site.objects, 'get_current')
def test_logged_in_message(self, get_current):
get_current.return_value.domain = 'dev.mo.org'
login_uri = reverse('users.login')
response = self.client.post(login_uri,
{'username': 'testuser',
'password': 'testpass'},
follow=True)
eq_(200, response.status_code)
response = self.client.get(login_uri, follow=True)
eq_(200, response.status_code)
doc = pq(response.content)
eq_("You are already logged in.", doc.find('article').text())
@mock.patch_object(Site.objects, 'get_current')
def test_django_login_redirects_to_next(self, get_current):
get_current.return_value.domain = 'dev.mo.org'
login_uri = reverse('users.login')
response = self.client.post(login_uri,
{'username': 'testuser',
'password': 'testpass'},
follow=True)
eq_(200, response.status_code)
response = self.client.get(login_uri, {'next': '/en-US/demos/submit'},
follow=True)
eq_('http://testserver/en-US/demos/submit',
response.redirect_chain[0][0])
@mock.patch_object(Site.objects, 'get_current')
def test_clean_next_url_request_properties(self, get_current):
'''_clean_next_url checks POST, GET, and REFERER'''
get_current.return_value.domain = 'dev.mo.org'
r = RequestFactory().get('/users/login', {'next': '/demos/submit'},
HTTP_REFERER='referer-trumped-by-get')
eq_('/demos/submit', _clean_next_url(r))
r = RequestFactory().post('/users/login', {'next': '/demos/submit'})
eq_('/demos/submit', _clean_next_url(r))
r = RequestFactory().get('/users/login', HTTP_REFERER='/demos/submit')
eq_('/demos/submit', _clean_next_url(r))
@mock.patch_object(Site.objects, 'get_current')
def test_clean_next_url_no_self_redirects(self, get_current):
'''_clean_next_url checks POST, GET, and REFERER'''
get_current.return_value.domain = 'dev.mo.org'
#.........这里部分代码省略.........
示例5: ProfileViewsTest
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import logout [as 别名]
class ProfileViewsTest(TestCase):
fixtures = ['test_users.json']
def setUp(self):
self.old_debug = settings.DEBUG
settings.DEBUG = True
self.client = LocalizingClient()
self.client.logout()
def tearDown(self):
settings.DEBUG = self.old_debug
def _get_current_form_field_values(self, doc):
# Scrape out the existing significant form field values.
form = dict()
for fn in ('email', 'fullname', 'title', 'organization', 'location',
'irc_nickname', 'bio', 'interests', 'country', 'format'):
form[fn] = doc.find('#profile-edit *[name="%s"]' % fn).val()
form['country'] = 'us'
form['format'] = 'html'
return form
@attr('docs_activity')
def test_profile_view(self):
"""A user profile can be viewed"""
profile = UserProfile.objects.get(user__username='testuser')
user = profile.user
url = reverse('users.profile', args=(user.username,))
r = self.client.get(url, follow=True)
doc = pq(r.content)
eq_(profile.user.username,
doc.find('#profile-head.vcard .nickname').text())
eq_(profile.fullname,
doc.find('#profile-head.vcard .fn').text())
eq_(profile.title,
doc.find('#profile-head.vcard .title').text())
eq_(profile.organization,
doc.find('#profile-head.vcard .org').text())
eq_(profile.location,
doc.find('#profile-head.vcard .loc').text())
eq_('IRC: ' + profile.irc_nickname,
doc.find('#profile-head.vcard .irc').text())
eq_(profile.bio,
doc.find('#profile-head.vcard .bio').text())
def test_my_profile_view(self):
u = User.objects.get(username='testuser')
self.client.login(username=u.username, password=TESTUSER_PASSWORD)
resp = self.client.get('/profile/')
eq_(302, resp.status_code)
ok_(reverse('users.profile', args=(u.username,)) in
resp['Location'])
def test_bug_698971(self):
"""A non-numeric page number should not cause an error"""
(user, profile) = create_profile()
url = '%s?page=asdf' % reverse('users.profile', args=(user.username,))
try:
self.client.get(url, follow=True)
except PageNotAnInteger:
ok_(False, "Non-numeric page number should not cause an error")
@mock.patch('basket.lookup_user')
@mock.patch('basket.subscribe')
@mock.patch('basket.unsubscribe')
def test_profile_edit(self,
unsubscribe,
subscribe,
lookup_user):
lookup_user.return_value = mock_lookup_user()
subscribe.return_value = True
unsubscribe.return_value = True
profile = UserProfile.objects.get(user__username='testuser')
user = profile.user
url = reverse('users.profile', args=(user.username,))
r = self.client.get(url, follow=True)
doc = pq(r.content)
eq_(0, doc.find('#profile-head .edit .button').length)
self.client.login(username=user.username,
password=TESTUSER_PASSWORD)
url = reverse('users.profile', args=(user.username,))
r = self.client.get(url, follow=True)
doc = pq(r.content)
edit_button = doc.find('#profile-head .edit #edit-profile')
eq_(1, edit_button.length)
url = edit_button.attr('href')
r = self.client.get(url, follow=True)
doc = pq(r.content)
eq_(profile.fullname,
doc.find('#profile-edit input[name="fullname"]').val())
eq_(profile.title,
doc.find('#profile-edit input[name="title"]').val())
#.........这里部分代码省略.........
示例6: ProfileViewsTest
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import logout [as 别名]
class ProfileViewsTest(TestCase):
fixtures = ["test_users.json"]
def setUp(self):
self.old_debug = settings.DEBUG
settings.DEBUG = True
self.client = LocalizingClient()
self.client.logout()
def tearDown(self):
settings.DEBUG = self.old_debug
def _get_current_form_field_values(self, doc):
# Scrape out the existing significant form field values.
form = dict()
for fn in (
"email",
"fullname",
"title",
"organization",
"location",
"irc_nickname",
"bio",
"interests",
"country",
"format",
):
form[fn] = doc.find('#profile-edit *[name="%s"]' % fn).val()
form["country"] = "us"
form["format"] = "html"
return form
@attr("docs_activity")
def test_profile_view(self):
"""A user profile can be viewed"""
profile = UserProfile.objects.get(user__username="testuser")
user = profile.user
url = reverse("devmo.views.profile_view", args=(user.username,))
r = self.client.get(url, follow=True)
doc = pq(r.content)
eq_(profile.user.username, doc.find("#profile-head.vcard .nickname").text())
eq_(profile.fullname, doc.find("#profile-head.vcard .fn").text())
eq_(profile.title, doc.find("#profile-head.vcard .title").text())
eq_(profile.organization, doc.find("#profile-head.vcard .org").text())
eq_(profile.location, doc.find("#profile-head.vcard .loc").text())
eq_("IRC: " + profile.irc_nickname, doc.find("#profile-head.vcard .irc").text())
eq_(profile.bio, doc.find("#profile-head.vcard .bio").text())
def test_my_profile_view(self):
u = User.objects.get(username="testuser")
self.client.login(username=u.username, password=TESTUSER_PASSWORD)
resp = self.client.get("/profile/")
eq_(302, resp.status_code)
ok_(reverse("devmo.views.profile_view", args=(u.username,)) in resp["Location"])
def test_bug_698971(self):
"""A non-numeric page number should not cause an error"""
(user, profile) = create_profile()
url = "%s?page=asdf" % reverse("devmo.views.profile_view", args=(user.username,))
try:
self.client.get(url, follow=True)
except PageNotAnInteger:
ok_(False, "Non-numeric page number should not cause an error")
@mock.patch("basket.lookup_user")
@mock.patch("basket.subscribe")
@mock.patch("basket.unsubscribe")
def test_profile_edit(self, unsubscribe, subscribe, lookup_user):
lookup_user.return_value = mock_lookup_user()
subscribe.return_value = True
unsubscribe.return_value = True
profile = UserProfile.objects.get(user__username="testuser")
user = profile.user
url = reverse("devmo.views.profile_view", args=(user.username,))
r = self.client.get(url, follow=True)
doc = pq(r.content)
eq_(0, doc.find("#profile-head .edit .button").length)
self.client.login(username=user.username, password=TESTUSER_PASSWORD)
url = reverse("devmo.views.profile_view", args=(user.username,))
r = self.client.get(url, follow=True)
doc = pq(r.content)
edit_button = doc.find("#profile-head .edit #edit-profile")
eq_(1, edit_button.length)
url = edit_button.attr("href")
r = self.client.get(url, follow=True)
doc = pq(r.content)
eq_(profile.fullname, doc.find('#profile-edit input[name="fullname"]').val())
eq_(profile.title, doc.find('#profile-edit input[name="title"]').val())
eq_(profile.organization, doc.find('#profile-edit input[name="organization"]').val())
eq_(profile.location, doc.find('#profile-edit input[name="location"]').val())
eq_(profile.irc_nickname, doc.find('#profile-edit input[name="irc_nickname"]').val())
#.........这里部分代码省略.........