本文整理汇总了Python中sumo.tests.LocalizingClient.post方法的典型用法代码示例。如果您正苦于以下问题:Python LocalizingClient.post方法的具体用法?Python LocalizingClient.post怎么用?Python LocalizingClient.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sumo.tests.LocalizingClient
的用法示例。
在下文中一共展示了LocalizingClient.post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_redirect_can_be_clobbered
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_redirect_can_be_clobbered(self):
"""When an attempt is made to retitle an article, and another article
with that title exists but is a redirect, there should be no errors and
the redirect should be replaced."""
client = LocalizingClient()
client.login(username='admin', password='testpass')
exist_title = "Existing doc"
exist_slug = "existing-doc"
# Create a new doc.
data = new_document_data()
data.update({ "title": exist_title, "slug": exist_slug })
resp = client.post(reverse('wiki.new_document'), data)
eq_(302, resp.status_code)
# Change title and slug
data.update({'form': 'rev',
'title': "Changed title",
'slug': "changed-title"})
resp = client.post(reverse('wiki.edit_document', args=[exist_slug]),
data)
eq_(302, resp.status_code)
# Change title and slug back to originals, clobbering the redirect
data.update({'form': 'rev',
'title': exist_title,
'slug': exist_slug})
resp = client.post(reverse('wiki.edit_document', args=["changed-title"]),
data)
eq_(302, resp.status_code)
示例2: test_invalid_slug
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_invalid_slug(self):
"""Slugs cannot contain "$", but can contain "/"."""
client = LocalizingClient()
client.login(username='admin', password='testpass')
data = new_document_data()
data['title'] = 'valid slug'
data['slug'] = 'valid'
response = client.post(reverse('wiki.new_document'), data)
self.assertRedirects(response, reverse('wiki.document',
args=[data['slug']],
locale='en-US'))
# Slashes should be fine
data['title'] = 'valid with slash'
data['slug'] = 'va/lid'
response = client.post(reverse('wiki.new_document'), data)
self.assertRedirects(response, reverse('wiki.document',
args=[data['slug']],
locale='en-US'))
# Dollar sign is reserved for verbs
data['title'] = 'invalid with dollars'
data['slug'] = 'inva$lid'
response = client.post(reverse('wiki.new_document'), data)
self.assertContains(response, 'The slug provided is not valid.')
# Question mark is reserved for query params
data['title'] = 'invalid with questions'
data['slug'] = 'inva?lid'
response = client.post(reverse('wiki.new_document'), data)
self.assertContains(response, 'The slug provided is not valid.')
示例3: test_title_slug_collision_errors
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_title_slug_collision_errors(self):
"""When an attempt is made to retitle an article and another with that
title already exists, there should be form errors"""
client = LocalizingClient()
client.login(username='admin', password='testpass')
exist_title = "Existing doc"
exist_slug = "existing-doc"
# Create a new doc.
data = new_document_data()
data.update({ "title": exist_title, "slug": exist_slug })
resp = client.post(reverse('wiki.new_document'), data)
eq_(302, resp.status_code)
# Create another new doc.
data = new_document_data()
data.update({ "title": 'Some new title', "slug": 'some-new-title' })
response = client.post(reverse('wiki.new_document'), data)
eq_(302, resp.status_code)
# Now, post an update with duplicate slug and title
data.update({
'form': 'rev',
'title': exist_title,
'slug': exist_slug
})
resp = client.post(reverse('wiki.edit_document', args=['some-new-title']), data)
eq_(200, resp.status_code)
p = pq(resp.content)
ok_(p.find('.errorlist').length > 0)
ok_(p.find('.errorlist a[href="#id_title"]').length > 0)
ok_(p.find('.errorlist a[href="#id_slug"]').length > 0)
示例4: test_review_tags
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_review_tags(self):
client = LocalizingClient()
client.login(username='admin', password='testpass')
data = new_document_data()
data.update({'review_tags':['editorial']})
response = client.post(reverse('wiki.new_document'), data)
doc = Document.objects.get(slug="a-test-article")
combos = (
([], 0, 0, 0, 0),
(['technical',], 1, 1, 0, 0),
(['editorial',], 0, 0, 1, 1),
(['technical', 'editorial',], 1, 1, 1, 1),
)
for tags, a, b, c, d in combos:
# Edit the page and set the tags for this test
data.update({ 'form': 'rev', 'review_tags': tags })
response = client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
response = client.get(reverse('docs.views.docs'))
page = pq(response.content)
# Check for the section itself, and then the doc
eq_(a, page('div#review-technical').length)
eq_(b, page("div#review-technical ul li h4 a:contains('%s')" %
doc.title).length)
eq_(c, page('div#review-editorial').length)
eq_(d, page("div#review-editorial ul li h4 a:contains('%s')" %
doc.title).length)
示例5: AppsViewsTest
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
class AppsViewsTest(test_utils.TestCase):
def setUp(self):
self.client = LocalizingClient()
@patch('landing.views.basket.subscribe')
def test_apps_subscription(self, subscribe):
subscribe.return_value = True
url = reverse('landing.views.apps_newsletter')
r = self.client.post(url,
{'format': 'html',
'email': '[email protected]',
'agree': 'checked'},
follow=True)
eq_(200, r.status_code)
# 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.')
示例6: test_invalid_slugs
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_invalid_slugs(self, get_current):
"""Slugs cannot contain /."""
get_current.return_value.domain = 'testserver'
client = LocalizingClient()
client.login(username='admin', password='testpass')
data = new_document_data()
error = 'The slug provided is not valid.'
data['slug'] = 'inva/lid'
response = client.post(reverse('wiki.new_document'), data)
self.assertContains(response, error)
data['slug'] = 'no-question-marks?'
response = client.post(reverse('wiki.new_document'), data)
self.assertContains(response, error)
data['slug'] = 'no+plus'
response = client.post(reverse('wiki.new_document'), data)
self.assertContains(response, error)
data['slug'] = 'valid'
response = client.post(reverse('wiki.new_document'), data)
self.assertRedirects(response, reverse('wiki.document_revisions',
args=[data['slug']],
locale='en-US'))
示例7: ReminderEmailTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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))
示例8: test_changing_products
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_changing_products(self):
"""Changing products works as expected."""
client = LocalizingClient()
client.login(username='admin', password='testpass')
d, r = doc_rev()
data = new_document_data()
data.update({'products': ['desktop', 'sync'],
'form': 'doc'})
client.post(reverse('wiki.edit_document', args=[d.slug]), data)
tags_eq(d, ['desktop', 'sync'])
data.update({'products': ['mobile'],
'form': 'doc'})
client.post(reverse('wiki.edit_document', args=[data['slug']]), data)
tags_eq(d, ['mobile'])
示例9: test_invalid_slug
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_invalid_slug(self):
"""Slugs cannot contain /."""
client = LocalizingClient()
client.login(username='admin', password='testpass')
data = new_document_data()
data['slug'] = 'inva/lid'
response = client.post(reverse('wiki.new_document'), data)
self.assertContains(response, 'The slug provided is not valid.')
data['slug'] = 'valid'
response = client.post(reverse('wiki.new_document'), data)
self.assertRedirects(response, reverse('wiki.document_revisions',
args=[data['slug']],
locale='en-US'))
示例10: test_retitling_ignored_for_iframe
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_retitling_ignored_for_iframe(self):
"""When the title of an article is edited in an iframe, the change is
ignored."""
client = LocalizingClient()
client.login(username='admin', password='testpass')
new_title = 'Some New Title'
d, r = doc_rev()
old_title = d.title
data = new_document_data()
data.update({'title': new_title,
'slug': d.slug,
'form': 'rev'})
client.post('%s?iframe=1' % reverse('wiki.edit_document', args=[d.slug]), data)
eq_(old_title, Document.uncached.get(slug=d.slug).title)
assert "REDIRECT" not in Document.uncached.get(title=old_title).html
示例11: test_invalid_reserved_term_slug
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_invalid_reserved_term_slug(self):
"""Slugs should not collide with reserved URL patterns"""
client = LocalizingClient()
client.login(username='admin', password='testpass')
data = new_document_data()
# TODO: This is info derived from urls.py, but unsure how to DRY it
reserved_slugs = (
'ckeditor_config.js',
'watch-ready-for-review',
'unwatch-ready-for-review',
'watch-approved',
'unwatch-approved',
'.json',
'new',
'all',
'preview-wiki-content',
'category/10',
'needs-review/technical',
'needs-review/',
'feeds/atom/all/',
'feeds/atom/needs-review/technical',
'feeds/atom/needs-review/',
'tag/tasty-pie'
)
for term in reserved_slugs:
data['title'] = 'invalid with %s' % term
data['slug'] = term
response = client.post(reverse('wiki.new_document'), data)
self.assertContains(response, 'The slug provided is not valid.')
示例12: test_retitling
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_retitling(self):
"""When the title of an article is edited, a redirect is made."""
# Not testing slug changes separately; the model tests cover those plus
# slug+title changes. If title changes work in the view, the rest
# should also.
client = LocalizingClient()
client.login(username='admin', password='testpass')
new_title = 'Some New Title'
d, r = doc_rev()
old_title = d.title
data = new_document_data()
data.update({'title': new_title,
'slug': d.slug,
'form': 'doc'})
client.post(reverse('wiki.edit_document', args=[d.slug]), data)
eq_(new_title, Document.uncached.get(slug=d.slug).title)
assert Document.uncached.get(title=old_title).redirect_url()
示例13: test_changing_metadata
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import post [as 别名]
def test_changing_metadata(self):
"""Changing metadata works as expected."""
client = LocalizingClient()
client.login(username='admin', password='testpass')
d, r = doc_rev()
data = new_document_data()
data.update({'firefox_versions': [1, 2, 3],
'operating_systems': [1, 3],
'form': 'doc'})
client.post(reverse('wiki.edit_document', args=[d.slug]), data)
eq_(3, d.firefox_versions.count())
eq_(2, d.operating_systems.count())
data.update({'firefox_versions': [1, 2],
'operating_systems': [2],
'form': 'doc'})
client.post(reverse('wiki.edit_document', args=[data['slug']]), data)
eq_(2, d.firefox_versions.count())
eq_(1, d.operating_systems.count())
示例14: AppsViewsTest
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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)
示例15: ReminderEmailTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.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)