本文整理汇总了Python中sumo.tests.LocalizingClient.logout方法的典型用法代码示例。如果您正苦于以下问题:Python LocalizingClient.logout方法的具体用法?Python LocalizingClient.logout怎么用?Python LocalizingClient.logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sumo.tests.LocalizingClient
的用法示例。
在下文中一共展示了LocalizingClient.logout方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProfileViewsTest
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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
@attr('docs_activity')
@attr('bug715923')
@patch('devmo.models.UserDocsActivityFeed.fetch_user_feed')
def test_bug715923_feed_parsing_errors(self, fetch_user_feed):
fetch_user_feed.return_value = """
THIS IS NOT EVEN XML, SO BROKEN
"""
try:
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)
pq(r.content)
except Exception, e:
raise e
ok_(False, "There should be no exception %s" % e)
示例2: test_ban_permission
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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)
示例3: LoginTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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('div#content-main').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('dekicompat.backends.DekiUserBackend.mindtouch_login')
def test_mindtouch_disabled_login(self, mock_mindtouch_login):
"""When DEKIWIKI_ENDPOINT unavailable, skip MindTouch auth."""
# HACK: mock has an assert_called_with, but I want something like
# never_called or call_count. Instead, I have this:
trap = {'was_called': False}
def my_mindtouch_login(username, password, force=False):
trap['was_called'] = True
return False
mock_mindtouch_login.side_effect = my_mindtouch_login
# Try to log in as a MindTouch user, assert that MindTouch auth was
# never attempted.
_old = settings.DEKIWIKI_ENDPOINT
settings.DEKIWIKI_ENDPOINT = False
#.........这里部分代码省略.........
示例4: RegisterTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import logout [as 别名]
class RegisterTestCase(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_missing_get_deki_user
@mock_put_mindtouch_user
@mock_post_mindtouch_user
@mock.patch_object(Site.objects, 'get_current')
def test_new_user(self, get_current):
get_current.return_value.domain = 'su.mo.com'
now = time()
username = 'newb%s' % now
response = self.client.post(reverse('users.register'),
{'username': username,
'email': '[email protected]',
'password': 'foo',
'password2': 'foo'}, follow=True)
eq_(200, response.status_code)
u = User.objects.get(username=username)
assert u.password.startswith('sha256')
assert not u.is_active
eq_(1, len(mail.outbox))
assert mail.outbox[0].subject.find('Please confirm your') == 0
key = RegistrationProfile.objects.all()[0].activation_key
assert mail.outbox[0].body.find('activate/%s' % key) > 0
# Now try to log in
u.is_active = True
u.save()
response = self.client.post(reverse('users.login'),
{'username': username,
'password': 'foo'}, follow=True)
eq_(200, response.status_code)
eq_('http://testserver/en-US/', response.redirect_chain[0][0])
@mock_missing_get_deki_user
@mock_post_mindtouch_user
@mock_put_mindtouch_user
@mock.patch_object(Site.objects, 'get_current')
def test_unicode_password(self, get_current):
get_current.return_value.domain = 'su.mo.com'
now = time()
username = 'cjk%s' % now
u_str = u'\xe5\xe5\xee\xe9\xf8\xe7\u6709\u52b9'
response = self.client.post(reverse('users.register', locale='ja'),
{'username': username,
'email': '[email protected]',
'password': u_str,
'password2': u_str}, follow=True)
eq_(200, response.status_code)
u = User.objects.get(username=username)
u.is_active = True
u.save()
assert u.password.startswith('sha256')
# make sure you can login now
response = self.client.post(reverse('users.login', locale='ja'),
{'username': username,
'password': u_str}, follow=True)
eq_(200, response.status_code)
eq_('http://testserver/ja/', response.redirect_chain[0][0])
@mock_put_mindtouch_user
@mock_post_mindtouch_user
@mock.patch_object(Site.objects, 'get_current')
def test_new_user_activation(self, get_current):
get_current.return_value.domain = 'su.mo.com'
now = time()
username = 'sumo%s' % now
user = RegistrationProfile.objects.create_inactive_user(
username, 'testpass', '[email protected]')
assert not user.is_active
key = RegistrationProfile.objects.all()[0].activation_key
url = reverse('users.activate', args=[key])
response = self.client.get(url, follow=True)
eq_(200, response.status_code)
user = User.objects.get(pk=user.pk)
assert user.is_active
@mock_put_mindtouch_user
@mock_post_mindtouch_user
@mock.patch_object(Site.objects, 'get_current')
def test_new_user_claim_watches(self, get_current):
"""Claim user watches upon activation."""
old, settings.CELERY_ALWAYS_EAGER = settings.CELERY_ALWAYS_EAGER, True
get_current.return_value.domain = 'su.mo.com'
watch(email='[email protected]', save=True)
now = time()
username = 'sumo%s' % now
#.........这里部分代码省略.........
示例5: LoginTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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('div#content-main').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('dekicompat.backends.DekiUserBackend.mindtouch_login')
def test_mindtouch_disabled_login(self, mock_mindtouch_login):
"""When DEKIWIKI_ENDPOINT unavailable, skip MindTouch auth."""
# HACK: mock has an assert_called_with, but I want something like
# never_called or call_count. Instead, I have this:
trap = {'was_called': False}
def my_mindtouch_login(username, password, force=False):
trap['was_called'] = True
return False
mock_mindtouch_login.side_effect = my_mindtouch_login
# Try to log in as a MindTouch user, assert that MindTouch auth was
# never attempted.
_old = settings.DEKIWIKI_ENDPOINT
settings.DEKIWIKI_ENDPOINT = False
#.........这里部分代码省略.........
示例6: ProfileViewsTest
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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
@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")
def test_profile_edit(self):
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())
new_attrs = dict(
email="[email protected]", fullname="Another Name", title="Another title", organization="Another org"
)
r = self.client.post(url, new_attrs, follow=True)
doc = pq(r.content)
eq_(1, doc.find("#profile-head").length)
eq_(new_attrs["fullname"], doc.find("#profile-head .main .fn").text())
eq_(new_attrs["title"], doc.find("#profile-head .info .title").text())
eq_(new_attrs["organization"], doc.find("#profile-head .info .org").text())
profile = UserProfile.objects.get(user__username=user.username)
eq_(new_attrs["fullname"], profile.fullname)
eq_(new_attrs["title"], profile.title)
eq_(new_attrs["organization"], profile.organization)
def test_my_profile_edit(self):
u = User.objects.get(username="testuser")
self.client.login(username=u.username, password=TESTUSER_PASSWORD)
resp = self.client.get("/profile/edit")
eq_(302, resp.status_code)
ok_(reverse("devmo.views.profile_edit", args=(u.username,)) in resp["Location"])
def test_profile_edit_websites(self):
user = User.objects.get(username="testuser")
#.........这里部分代码省略.........
示例7: LoginTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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('div#content-main').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'
#.........这里部分代码省略.........
示例8: LoginTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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_mindtouch_login
@mock_get_deki_user
@mock_put_mindtouch_user
@mock.patch_object(Site.objects, 'get_current')
def test_mindtouch_creds_create_user_and_profile(self, get_current):
get_current.return_value.domain = 'dev.mo.org'
if not getattr(settings, 'DEKIWIKI_MOCK', False):
# HACK: Ensure that expected user details are in MindTouch when not
# mocking the API
mt_email = '[email protected]'
user_xml = MINDTOUCH_USER_XML % dict(username="testaccount",
email=mt_email, fullname="None", status="active",
language="", timezone="-08:00", role="Contributor")
DekiUserBackend.put_mindtouch_user(deki_user_id='=testaccount',
user_xml=user_xml)
passwd_url = '%s/@api/deki/users/%s/password?apikey=%s' % (
settings.DEKIWIKI_ENDPOINT, '=testaccount',
settings.DEKIWIKI_APIKEY)
requests.put(passwd_url, data='theplanet')
self.assertRaises(User.DoesNotExist, User.objects.get,
username='testaccount')
# Try to log in as a MindTouch user
response = self.client.post(reverse('users.login'),
{'username': 'testaccount',
'password': 'theplanet'}, follow=True)
eq_(200, response.status_code)
# Ensure there are no validation errors
page = pq(response.content)
eq_(0, page.find('.errorlist').length,
"There should be no validation errors in login")
# Login should have auto-created django user
u = User.objects.get(username='testaccount')
eq_(True, u.is_active)
ok_(u.get_profile())
# Login page should show welcome back
doc = pq(response.content)
eq_('testaccount', doc.find('ul.user-state a:first').text())
示例9: ProfileViewsTest
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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
@attr('docs_activity')
@mock_fetch_user_feed
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())
# There should be 15 doc activity items in the page.
feed_trs = doc.find('#docs-activity table.activity tbody tr')
eq_(15, feed_trs.length)
# Check to find all the items expected from the feed
feed = UserDocsActivityFeed(username="Sheppy")
for idx in range(0, 15):
item = feed.items[idx]
item_el = feed_trs.eq(idx)
eq_(item.current_title, item_el.find('h3').text())
eq_(item.view_url, item_el.find('h3 a').attr('href'))
if item.edit_url:
eq_(item.edit_url,
item_el.find('.actions a.edit').attr('href'))
if item.diff_url:
eq_(item.diff_url,
item_el.find('.actions a.diff').attr('href'))
if item.history_url:
eq_(item.history_url,
item_el.find('.actions a.history').attr('href'))
@mock_put_mindtouch_user
@mock_fetch_user_feed
def test_bug_698971(self):
"""A non-numeric page number should not cause an error"""
(user, deki_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_put_mindtouch_user
@mock_fetch_user_feed
def test_profile_edit(self):
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 .button')
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())
#.........这里部分代码省略.........
示例10: ProfileViewsTest
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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'):
form[fn] = doc.find('#profile-edit *[name="%s"]' % fn).val()
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")
def test_profile_edit(self):
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())
new_attrs = dict(
#.........这里部分代码省略.........
示例11: RegisterTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import logout [as 别名]
class RegisterTestCase(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_missing_get_deki_user
@mock_put_mindtouch_user
@mock_post_mindtouch_user
@mock.patch_object(Site.objects, "get_current")
def test_new_user(self, get_current):
get_current.return_value.domain = "su.mo.com"
now = time()
username = "newb%s" % now
response = self.client.post(
reverse("users.register"),
{"username": username, "email": "[email protected]", "password": "foo", "password2": "foo"},
follow=True,
)
eq_(200, response.status_code)
u = User.objects.get(username=username)
assert u.password.startswith("sha256")
assert not u.is_active
eq_(1, len(mail.outbox))
assert mail.outbox[0].subject.find("Please confirm your") == 0
key = RegistrationProfile.objects.all()[0].activation_key
assert mail.outbox[0].body.find("activate/%s" % key) > 0
# Now try to log in
u.is_active = True
u.save()
response = self.client.post(reverse("users.login"), {"username": username, "password": "foo"}, follow=True)
eq_(200, response.status_code)
eq_("http://testserver/en-US/", response.redirect_chain[0][0])
@mock_missing_get_deki_user
@mock_post_mindtouch_user
@mock_put_mindtouch_user
@mock.patch_object(Site.objects, "get_current")
def test_unicode_password(self, get_current):
get_current.return_value.domain = "su.mo.com"
now = time()
username = "cjk%s" % now
u_str = u"\xe5\xe5\xee\xe9\xf8\xe7\u6709\u52b9"
response = self.client.post(
reverse("users.register", locale="ja"),
{"username": username, "email": "[email protected]", "password": u_str, "password2": u_str},
follow=True,
)
eq_(200, response.status_code)
u = User.objects.get(username=username)
u.is_active = True
u.save()
assert u.password.startswith("sha256")
# make sure you can login now
response = self.client.post(
reverse("users.login", locale="ja"), {"username": username, "password": u_str}, follow=True
)
eq_(200, response.status_code)
eq_("http://testserver/ja/", response.redirect_chain[0][0])
@mock_put_mindtouch_user
@mock_post_mindtouch_user
@mock.patch_object(Site.objects, "get_current")
def test_new_user_activation(self, get_current):
get_current.return_value.domain = "su.mo.com"
now = time()
username = "sumo%s" % now
user = RegistrationProfile.objects.create_inactive_user(username, "testpass", "[email protected]")
assert not user.is_active
key = RegistrationProfile.objects.all()[0].activation_key
url = reverse("users.activate", args=[key])
response = self.client.get(url, follow=True)
eq_(200, response.status_code)
user = User.objects.get(pk=user.pk)
assert user.is_active
@mock_get_deki_user
def test_duplicate_username(self):
response = self.client.post(
reverse("users.register"),
{"username": "testuser", "email": "[email protected]", "password": "foo", "password2": "foo"},
follow=True,
)
self.assertContains(response, "already exists")
@mock_get_deki_user
def test_duplicate_mindtouch_username(self):
if not settings.DEKIWIKI_ENDPOINT:
# Don't even bother with this test, if there's no MindTouch API
raise SkipTest()
response = self.client.post(
#.........这里部分代码省略.........
示例12: UploadImageTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import logout [as 别名]
class UploadImageTestCase(TestCase):
fixtures = ['users.json', 'questions.json']
def setUp(self):
super(UploadImageTestCase, self).setUp()
self.client = LocalizingClient()
self.client.login(username='pcraciunoiu', password='testpass')
def tearDown(self):
ImageAttachment.objects.all().delete()
super(UploadImageTestCase, self).tearDown()
def test_model_invalid(self):
"""Specifying an invalid model returns 400."""
r = post(self.client, 'upload.up_image_async', {'image': ''},
args=['invalid.model', 123])
eq_(400, r.status_code)
json_r = json.loads(r.content)
eq_('error', json_r['status'])
eq_('Model does not exist.', json_r['message'])
def test_object_notexist(self):
"""Upload nothing returns 404 error and html content."""
r = post(self.client, 'upload.up_image_async', {'image': ''},
args=['questions.Question', 123])
eq_(404, r.status_code)
json_r = json.loads(r.content)
eq_('error', json_r['status'])
eq_('Object does not exist.', json_r['message'])
def test_empty_image(self):
"""Upload nothing returns 400 error and json content."""
r = post(self.client, 'upload.up_image_async', {'image': ''},
args=['questions.Question', 1])
eq_(400, r.status_code)
json_r = json.loads(r.content)
eq_('error', json_r['status'])
eq_('Invalid or no image received.', json_r['message'])
eq_('You have not selected an image to upload.',
json_r['errors']['image'][0])
def test_upload_image(self):
"""Uploading an image works."""
with open('apps/upload/tests/media/test.jpg') as f:
r = post(self.client, 'upload.up_image_async', {'image': f},
args=['questions.Question', 1])
eq_(200, r.status_code)
json_r = json.loads(r.content)
eq_('success', json_r['status'])
file = json_r['file']
eq_('test.jpg', file['name'])
eq_(90, file['width'])
eq_(120, file['height'])
name = '098f6b.jpg'
message = 'Url "%s" does not contain "%s"' % (file['url'], name)
assert (name in file['url']), message
eq_(1, ImageAttachment.objects.count())
image = ImageAttachment.objects.all()[0]
eq_('pcraciunoiu', image.creator.username)
eq_(150, image.file.width)
eq_(200, image.file.height)
eq_('question', image.content_type.model)
eq_(1, image.object_id)
def test_upload_unicode_image(self):
"""Uploading an unicode image works."""
with open(u'apps/upload/tests/media/123ascii\u6709\u52b9.jpg') as f:
r = post(self.client, 'upload.up_image_async', {'image': f},
args=['questions.Question', 1])
eq_(200, r.status_code)
json_r = json.loads(r.content)
eq_('success', json_r['status'])
def test_delete_image_logged_out(self):
"""Can't delete an image logged out."""
# Upload the image first
self.test_upload_image()
im = ImageAttachment.objects.all()[0]
self.client.logout()
r = post(self.client, 'upload.del_image_async', args=[im.id])
eq_(403, r.status_code)
assert ImageAttachment.uncached.exists()
def test_delete_image_no_permission(self):
"""Can't delete an image without permission."""
u = User.objects.get(username='tagger')
assert not u.has_perm('upload.delete_imageattachment')
self.test_upload_image()
im = ImageAttachment.objects.all()[0]
self.client.login(username='tagger', password='testpass')
r = post(self.client, 'upload.del_image_async', args=[im.id])
eq_(403, r.status_code)
assert ImageAttachment.uncached.exists()
#.........这里部分代码省略.........