本文整理汇总了Python中sumo.tests.LocalizingClient.login方法的典型用法代码示例。如果您正苦于以下问题:Python LocalizingClient.login方法的具体用法?Python LocalizingClient.login怎么用?Python LocalizingClient.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sumo.tests.LocalizingClient
的用法示例。
在下文中一共展示了LocalizingClient.login方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_raw_section_source
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [as 别名]
def test_raw_section_source(self):
"""The raw source for a document section can be requested"""
client = LocalizingClient()
client.login(username='admin', password='testpass')
d, r = doc_rev("""
<h1 id="s1">Head 1</h1>
<p>test</p>
<p>test</p>
<h1 id="s2">Head 2</h1>
<p>test</p>
<p>test</p>
<h1 id="s3">Head 3</h1>
<p>test</p>
<p>test</p>
""")
expected = """
<h1 id="s2">Head 2</h1>
<p>test</p>
<p>test</p>
"""
response = client.get('%s?section=s2&raw=true' %
reverse('wiki.document', args=[d.slug]))
eq_(normalize_html(expected),
normalize_html(response.content))
示例2: test_review_tags
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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)
示例3: test_kumawiki_waffle_flag
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [as 别名]
def test_kumawiki_waffle_flag(self):
# Turn off the new wiki for everyone
self.kumawiki_flag.everyone = False
self.kumawiki_flag.save()
client = LocalizingClient()
resp = client.get(reverse('wiki.all_documents'))
eq_(404, resp.status_code)
resp = client.get(reverse('docs'))
page = pq(resp.content)
eq_(0, page.find('#kumawiki_preview').length)
client.login(username='admin', password='testpass')
# Turn on the wiki for just superusers, ignore everyone else
self.kumawiki_flag.superusers = True
self.kumawiki_flag.everyone = None
self.kumawiki_flag.save()
resp = client.get(reverse('wiki.all_documents'))
eq_(200, resp.status_code)
resp = client.get(reverse('docs'))
page = pq(resp.content)
eq_(1, page.find('#kumawiki_preview').length)
示例4: test_invalid_slugs
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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'))
示例5: test_invalid_slug
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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.')
示例6: test_raw_with_editing_links_source
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [as 别名]
def test_raw_with_editing_links_source(self):
"""The raw source for a document can be requested, with section editing
links"""
client = LocalizingClient()
client.login(username='admin', password='testpass')
d, r = doc_rev("""
<h1 id="s1">Head 1</h1>
<p>test</p>
<p>test</p>
<h1 id="s2">Head 2</h1>
<p>test</p>
<p>test</p>
<h1 id="s3">Head 3</h1>
<p>test</p>
<p>test</p>
""")
expected = """
<h1 id="s1"><a class="edit-section" data-section-id="s1" data-section-src-url="/en-US/docs/%(slug)s?raw=true&section=s1" href="/en-US/docs/%(slug)s$edit?section=s1&edit_links=true" title="Edit section">Edit</a>Head 1</h1>
<p>test</p>
<p>test</p>
<h1 id="s2"><a class="edit-section" data-section-id="s2" data-section-src-url="/en-US/docs/%(slug)s?raw=true&section=s2" href="/en-US/docs/%(slug)s$edit?section=s2&edit_links=true" title="Edit section">Edit</a>Head 2</h1>
<p>test</p>
<p>test</p>
<h1 id="s3"><a class="edit-section" data-section-id="s3" data-section-src-url="/en-US/docs/%(slug)s?raw=true&section=s3" href="/en-US/docs/%(slug)s$edit?section=s3&edit_links=true" title="Edit section">Edit</a>Head 3</h1>
<p>test</p>
<p>test</p>
""" % {'slug': d.slug}
response = client.get('%s?raw=true&edit_links=true' %
reverse('wiki.document', args=[d.slug]))
eq_(normalize_html(expected),
normalize_html(response.content))
示例7: test_invalid_reserved_term_slug
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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.')
示例8: test_redirect_can_be_clobbered
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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)
示例9: test_title_slug_collision_errors
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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)
示例10: DemoListViewsTest
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [as 别名]
class DemoListViewsTest(test_utils.TestCase):
fixtures = ['test_users.json']
def setUp(self):
self.user, self.admin_user, self.other_user = make_users()
self.client = LocalizingClient()
def test_all_demos_includes_hidden_for_staff(self):
build_submission(self.user)
build_hidden_submission(self.user)
r = self.client.get(reverse('demos_all'))
count = pq(r.content)('h2.count').text()
eq_(count, "1 Demo")
self.client.login(username=self.admin_user.username,
password='admint_tester')
r = self.client.get(reverse('demos_all'))
count = pq(r.content)('h2.count').text()
eq_(count, "2 Demos")
@attr('bug882709')
def test_search_view(self):
try:
self.client.get(reverse('demos_search'))
except:
self.fail("Search should not ISE.")
示例11: UploadImageTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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'])
def test_basic(self):
"""Uploading an image works."""
# TODO: posting a valid image through the test client uploads it
raise SkipTest
def test_invalid_image(self):
"""Make sure invalid files are not accepted as images."""
f = open('apps/upload/__init__.py', 'rb')
r = post(self.client, 'upload.up_image_async', {'image': f},
args=['questions.Question', 1])
f.close()
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'])
示例12: test_invalid_slug
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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'))
示例13: GalleryUploadTestCase
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [as 别名]
class GalleryUploadTestCase(TestCase):
fixtures = ["users.json"]
def setUp(self):
super(GalleryUploadTestCase, self).setUp()
self.client = LocalizingClient()
self.client.login(username="pcraciunoiu", password="testpass")
self.u = User.objects.get(username="pcraciunoiu")
def tearDown(self):
Image.objects.all().delete()
Video.objects.all().delete()
super(GalleryUploadTestCase, self).tearDown()
def test_image_draft_shows(self):
"""The image draft is loaded for this user."""
image(title=get_draft_title(self.u), creator=self.u)
response = get(self.client, "gallery.gallery", args=["image"])
eq_(200, response.status_code)
doc = pq(response.content)
assert doc(".image-preview img").attr("src").endswith("098f6b.jpg")
eq_(1, doc(".image-preview img").length)
def test_video_draft_shows(self):
"""The video draft is loaded for this user."""
video(title=get_draft_title(self.u), creator=self.u)
response = get(self.client, "gallery.gallery", args=["image"])
eq_(200, response.status_code)
doc = pq(response.content)
# Preview for all 3 video formats: flv, ogv, webm
eq_(3, doc("ul li.video-preview").length)
def test_image_draft_post(self):
"""Posting to the page saves the field values for the image draft."""
image(title=get_draft_title(self.u), creator=self.u)
response = post(self.client, "gallery.gallery", {"description": "??", "title": "test"}, args=["image"])
eq_(200, response.status_code)
doc = pq(response.content)
# Preview for all 3 video formats: flv, ogv, webm
eq_("??", doc("#gallery-upload-modal textarea").html())
eq_("test", doc('#gallery-upload-modal input[name="title"]').val())
def test_video_draft_post(self):
"""Posting to the page saves the field values for the video draft."""
video(title=get_draft_title(self.u), creator=self.u)
response = post(self.client, "gallery.gallery", {"title": "zTestz"}, args=["image"])
eq_(200, response.status_code)
doc = pq(response.content)
# Preview for all 3 video formats: flv, ogv, webm
eq_("zTestz", doc('#gallery-upload-modal input[name="title"]').val())
示例14: test_changing_products
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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'])
示例15: test_retitling_ignored_for_iframe
# 需要导入模块: from sumo.tests import LocalizingClient [as 别名]
# 或者: from sumo.tests.LocalizingClient import login [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