本文整理汇总了Python中devmo.tests.LocalizingClient.post方法的典型用法代码示例。如果您正苦于以下问题:Python LocalizingClient.post方法的具体用法?Python LocalizingClient.post怎么用?Python LocalizingClient.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类devmo.tests.LocalizingClient
的用法示例。
在下文中一共展示了LocalizingClient.post方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReminderEmailTestCase
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import post [as 别名]
class ReminderEmailTestCase(TestCase):
fixtures = ['test_users.json']
def setUp(self):
self.client = LocalizingClient()
@mock.patch_object(Site.objects, 'get_current')
def test_reminder_email(self, get_current):
"""Should send simple email reminder to user."""
get_current.return_value.domain = 'dev.mo.org'
response = self.client.post(reverse('users.send_email_reminder'),
{'username': 'testuser'},
follow=True)
eq_(200, response.status_code)
eq_(1, len(mail.outbox))
email = mail.outbox[0]
assert email.subject.find('Email Address Reminder') == 0
assert 'testuser' in email.body
@mock.patch_object(Site.objects, 'get_current')
def test_unknown_user_no_email_sent(self, get_current):
"""Should send simple email reminder to user."""
get_current.return_value.domain = 'dev.mo.org'
response = self.client.post(reverse('users.send_email_reminder'),
{'username': 'testuser404'},
follow=True)
eq_(200, response.status_code)
eq_(0, len(mail.outbox))
@mock.patch_object(Site.objects, 'get_current')
def test_user_without_email_message(self, get_current):
"""Should send simple email reminder to user."""
get_current.return_value.domain = 'dev.mo.org'
u = User.objects.get(username='testuser')
u.email = ''
u.save()
response = self.client.post(reverse('users.send_email_reminder'),
{'username': 'testuser'},
follow=True)
eq_(200, response.status_code)
eq_(0, len(mail.outbox))
ok_('Could not find email' in response.content)
ok_('file a bug' in response.content)
示例2: AppsViewsTest
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import post [as 别名]
class AppsViewsTest(SkippedTestCase):
def setUp(self):
self.client = LocalizingClient()
super(AppsViewsTest, self).setUp()
def _good_newsletter_post(self):
url = reverse('landing.views.apps_newsletter')
r = self.client.post(url,
{'format': 'html',
'country': 'pt',
'email': '[email protected]',
'agree': 'checked'},
follow=True)
eq_(200, r.status_code)
return r
@patch('landing.views.basket.subscribe')
def test_apps_subscription(self, subscribe):
subscribe.return_value = {'status': 'success'}
r = self._good_newsletter_post()
# assert thank you message
self.assertContains(r, 'Thank you')
eq_(1, subscribe.call_count)
@patch('landing.views.basket.subscribe')
def test_apps_subscription_bad_values(self, subscribe):
subscribe.return_value = True
url = reverse('landing.views.apps_newsletter')
r = self.client.post(url, {'format': 1, 'email': 'nope'})
eq_(200, r.status_code)
# assert error
self.assertContains(r, 'Enter a valid e-mail address.')
self.assertContains(r, 'Select a valid choice.')
self.assertContains(r, 'You must agree to the privacy policy.')
@patch('landing.views.basket.subscribe')
def test_apps_subscription_exception_retry(self, subscribe):
subscribe.side_effect = basket.base.BasketException("500!")
subscribe.return_value = True
self._good_newsletter_post()
eq_(constance.config.BASKET_RETRIES, subscribe.call_count)
示例3: test_ban_view
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import post [as 别名]
def test_ban_view(self):
testuser = User.objects.get(username='testuser')
admin = User.objects.get(username='admin')
client = LocalizingClient()
client.login(username='admin', password='testpass')
data = {'reason': 'Banned by unit test.'}
ban_url = reverse('users.ban_user',
kwargs={'user_id': testuser.id})
resp = client.post(ban_url, data)
eq_(302, resp.status_code)
ok_(testuser.get_absolute_url() in resp['Location'])
testuser_banned = User.objects.get(username='testuser')
ok_(not testuser_banned.is_active)
bans = UserBan.objects.filter(user=testuser,
by=admin,
reason='Banned by unit test.')
ok_(bans.count())
示例4: DemoViewsTest
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import post [as 别名]
class DemoViewsTest(test_utils.TestCase):
fixtures = ["test_users.json"]
def setUp(self):
self.testuser = User.objects.get(username="testuser")
self.testuser.set_password(TESTUSER_PASSWORD)
self.testuser.save()
self.client = LocalizingClient()
def test_submit_loggedout(self):
r = self.client.get(reverse("demos_submit"))
choices = pq(r.content)('p.choices a[href*="login"]')
eq_(choices.length, 1)
@logged_in
def test_submit_loggedin(self):
r = self.client.get(reverse("demos_submit"))
assert pq(r.content)("form#demo-submit")
@logged_in
def test_submit_post_invalid(self):
r = self.client.post(reverse("demos_submit"), data={})
d = pq(r.content)
assert d("form#demo-submit")
assert d("li#field_title ul.errorlist")
assert d("li#field_summary ul.errorlist")
assert d("li#field_screenshot_1 ul.errorlist")
assert d("li#field_demo_package ul.errorlist")
assert d("li#field_license_name ul.errorlist")
assert d("li#field_captcha ul.errorlist")
assert d("li#field_accept_terms ul.errorlist")
@logged_in
@disable_captcha
def test_submit_post_valid(self):
# Create a valid demo zip file
zf_fout = StringIO()
zf = zipfile.ZipFile(zf_fout, "w")
zf.writestr("index.html", """<html></html>""")
zf.close()
# Create a new file for input
zf_fin = StringIO(zf_fout.getvalue())
zf_fin.name = "demo.zip"
r = self.client.post(
reverse("demos_submit"),
data=dict(
title="Test submission",
summary="This is a test demo submission",
description="Some description goes here",
tech_tags=("tech:audio", "tech:video", "tech:websockets"),
screenshot_1=open(SCREENSHOT_PATH),
demo_package=zf_fin,
license_name="gpl",
accept_terms="1",
),
)
eq_(302, r.status_code)
assert "Location" in r
assert "test-submission" in r["Location"]
try:
obj = Submission.objects.get(slug="test-submission")
eq_("Test submission", obj.title)
except Submission.DoesNotExist:
assert False
result_tags = [t.name for t in obj.taggit_tags.all_ns("tech:")]
result_tags.sort()
eq_(["tech:audio", "tech:video", "tech:websockets"], result_tags)
@logged_in
def test_edit_invalid(self):
s = save_valid_submission()
edit_url = reverse("demos_edit", args=[s.slug])
r = self.client.post(edit_url, data=dict())
d = pq(r.content)
assert d("form#demo-submit")
assert d("li#field_title ul.errorlist")
assert d("li#field_summary ul.errorlist")
assert d("li#field_license_name ul.errorlist")
@logged_in
def test_edit_valid(self):
s = save_valid_submission()
edit_url = reverse("demos_edit", args=[s.slug])
r = self.client.post(
edit_url,
data=dict(
title=s.title,
summary="This is a test demo submission",
description="Some description goes here",
tech_tags=("tech:audio", "tech:video", "tech:websockets"),
license_name="gpl",
accept_terms="1",
),
)
#.........这里部分代码省略.........
示例5: BrowserIDTestCase
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import post [as 别名]
class BrowserIDTestCase(TestCase):
fixtures = ['test_users.json']
def setUp(self):
# Ensure @ssl_required goes unenforced.
settings.DEBUG = True
# Set up some easily-testable redirects.
settings.LOGIN_REDIRECT_URL = 'SUCCESS'
settings.LOGIN_REDIRECT_URL_FAILURE = 'FAILURE'
# BrowserID will squawk if this isn't set
settings.SITE_URL = 'http://testserver'
self.client = LocalizingClient()
# TODO: upgrade mock to 0.8.0 so we can do this.
"""
self.lookup = mock.patch('basket.lookup_user')
self.subscribe = mock.patch('basket.subscribe')
self.unsubscribe = mock.patch('basket.unsubscribe')
self.lookup.return_value = mock_lookup_user()
self.subscribe.return_value = True
self.unsubscribe.return_value = True
self.lookup.start()
self.subscribe.start()
self.unsubscribe.start()
def tearDown(self):
self.lookup.stop()
self.subscribe.stop()
self.unsubscribe.stop()
"""
def test_invalid_post(self):
resp = self.client.post(reverse('users.browserid_verify',
locale='en-US'))
eq_(302, resp.status_code)
ok_('FAILURE' in resp['Location'])
@mock.patch('users.views._verify_browserid')
def test_invalid_assertion(self, _verify_browserid):
_verify_browserid.return_value = None
resp = self.client.post(reverse('users.browserid_verify',
locale='en-US'),
{'assertion': 'bad data'})
eq_(302, resp.status_code)
ok_('FAILURE' in resp['Location'])
@mock.patch('users.views._verify_browserid')
def test_valid_assertion_with_django_user(self, _verify_browserid):
_verify_browserid.return_value = {'email': '[email protected]'}
# Posting the fake assertion to browserid_verify should work, with the
# actual verification method mocked out.
resp = self.client.post(reverse('users.browserid_verify',
locale='en-US'),
{'assertion': 'PRETENDTHISISVALID'})
eq_(302, resp.status_code)
ok_('SUCCESS' in resp['Location'])
# The session should look logged in, now.
ok_('_auth_user_id' in self.client.session.keys())
eq_('django_browserid.auth.BrowserIDBackend',
self.client.session.get('_auth_user_backend', ''))
@mock.patch('users.views._verify_browserid')
def test_explain_popup(self, _verify_browserid):
_verify_browserid.return_value = {'email': '[email protected]'}
resp = self.client.get(reverse('home', locale='en-US'))
# Posting the fake assertion to browserid_verify should work, with the
# actual verification method mocked out.
resp = self.client.post(reverse('users.browserid_verify',
locale='en-US'),
{'assertion': 'PRETENDTHISISVALID'})
eq_('1', resp.cookies.get('browserid_explained').value)
resp = self.client.get(reverse('users.logout'), locale='en-US')
# even after logout, cookie should prevent the toggle
resp = self.client.get(reverse('home', locale='en-US'))
eq_('1', self.client.cookies.get('browserid_explained').value)
@mock.patch('basket.lookup_user')
@mock.patch('basket.subscribe')
@mock.patch('basket.unsubscribe')
@mock.patch('users.views._verify_browserid')
@override_settings(CELERY_ALWAYS_EAGER=True)
def test_valid_assertion_with_new_account_creation(self,
_verify_browserid,
unsubscribe,
subscribe,
lookup_user):
Switch.objects.create(name='welcome_email', active=True)
new_username = 'neverbefore'
new_email = '[email protected]'
lookup_user.return_value = mock_lookup_user()
subscribe.return_value = True
#.........这里部分代码省略.........
示例6: ChangeEmailTestCase
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import post [as 别名]
class ChangeEmailTestCase(TestCase):
fixtures = ['test_users.json']
def setUp(self):
self.client = LocalizingClient()
@mock.patch_object(Site.objects, 'get_current')
def test_user_change_email(self, get_current):
"""Send email to change user's email and then change it."""
get_current.return_value.domain = 'su.mo.com'
self.client.login(username='testuser', password='testpass')
# Attempt to change email.
response = self.client.post(reverse('users.change_email'),
{'email': '[email protected]'},
follow=True)
eq_(200, response.status_code)
# Be notified to click a confirmation link.
eq_(1, len(mail.outbox))
assert mail.outbox[0].subject.find('Please confirm your') == 0
ec = EmailChange.objects.all()[0]
assert ec.activation_key in mail.outbox[0].body
eq_('[email protected]', ec.email)
# Visit confirmation link to change email.
response = self.client.get(reverse('users.confirm_email',
args=[ec.activation_key]))
eq_(200, response.status_code)
u = User.objects.get(username='testuser')
eq_('[email protected]', u.email)
def test_user_change_email_same(self):
"""Changing to same email shows validation error."""
self.client.login(username='testuser', password='testpass')
user = User.objects.get(username='testuser')
user.email = '[email protected]'
user.save()
response = self.client.post(reverse('users.change_email'),
{'email': user.email})
eq_(200, response.status_code)
doc = pq(response.content)
eq_('This is your current email.', doc('ul.errorlist').text())
def test_user_change_email_duplicate(self):
"""Changing to same email shows validation error."""
self.client.login(username='testuser', password='testpass')
email = '[email protected]'
response = self.client.post(reverse('users.change_email'),
{'email': email})
eq_(200, response.status_code)
doc = pq(response.content)
eq_('A user with that email address already exists.',
doc('ul.errorlist').text())
@mock.patch_object(Site.objects, 'get_current')
def test_user_confirm_email_duplicate(self, get_current):
"""If we detect a duplicate email when confirming an email change,
don't change it and notify the user."""
get_current.return_value.domain = 'su.mo.com'
self.client.login(username='testuser', password='testpass')
old_email = User.objects.get(username='testuser').email
new_email = '[email protected]'
response = self.client.post(reverse('users.change_email'),
{'email': new_email})
eq_(200, response.status_code)
assert mail.outbox[0].subject.find('Please confirm your') == 0
ec = EmailChange.objects.all()[0]
# Before new email is confirmed, give the same email to a user
other_user = User.objects.filter(username='testuser2')[0]
other_user.email = new_email
other_user.save()
# Visit confirmation link and verify email wasn't changed.
response = self.client.get(reverse('users.confirm_email',
args=[ec.activation_key]))
eq_(200, response.status_code)
doc = pq(response.content)
eq_('Unable to change email for user testuser',
doc('article h1').text())
u = User.objects.get(username='testuser')
eq_(old_email, u.email)
示例7: LoginTestCase
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import post [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'
#.........这里部分代码省略.........
示例8: ProfileViewsTest
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import post [as 别名]
#.........这里部分代码省略.........
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())
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",
country="us",
format="html"
)
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('users.profile_edit', args=(u.username,)) in
resp['Location'])
@mock.patch('basket.lookup_user')
@mock.patch('basket.subscribe')
@mock.patch('basket.unsubscribe')
def test_profile_edit_beta(self, unsubscribe, subscribe, lookup_user):
lookup_user.return_value = mock_lookup_user()
subscribe.return_value = True
unsubscribe.return_value = True
user = User.objects.get(username='testuser')
self.client.login(username=user.username,
示例9: ProfileViewsTest
# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import post [as 别名]
#.........这里部分代码省略.........
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",
country="us",
format="html",
)
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"])
@mock.patch("basket.lookup_user")
@mock.patch("basket.subscribe")
@mock.patch("basket.unsubscribe")
def test_profile_edit_beta(self, unsubscribe, subscribe, lookup_user):
lookup_user.return_value = mock_lookup_user()
subscribe.return_value = True
unsubscribe.return_value = True
user = User.objects.get(username="testuser")
self.client.login(username=user.username, password=TESTUSER_PASSWORD)
url = reverse("devmo.views.profile_edit", args=(user.username,))
r = self.client.get(url, follow=True)
doc = pq(r.content)