本文整理匯總了Python中example_block.tests.factories.TitleFactory.ordered_references方法的典型用法代碼示例。如果您正苦於以下問題:Python TitleFactory.ordered_references方法的具體用法?Python TitleFactory.ordered_references怎麽用?Python TitleFactory.ordered_references使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類example_block.tests.factories.TitleFactory
的用法示例。
在下文中一共展示了TitleFactory.ordered_references方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_choose_category_multi
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import ordered_references [as 別名]
def test_choose_category_multi(client):
"""Choose from links in the selected category."""
content = TitleFactory()
category = LinkCategoryFactory()
LinkFactory()
link_2 = LinkFactory(category=category)
LinkFactory()
link_4 = LinkFactory(category=category)
user = UserFactory(is_staff=True)
assert 0 == content.references.count()
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_link_multi(content, 'block.wizard.link.choose', category=category)
assert category.slug in url
data = {
'links': [link_2.pk, link_4.pk],
}
response = client.post(url, data)
# check
assert 302 == response.status_code
expect = url_link_multi(content, 'block.wizard.link.option')
assert expect in response['Location']
content.refresh_from_db()
assert 2 == content.references.count()
# ordering controlled by 'ordering' on 'TitleReference' model
assert [1, 2] == [item.order for item in content.ordered_references()]
示例2: test_select_multi
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import ordered_references [as 別名]
def test_select_multi(client):
link_1 = LinkFactory()
link_2 = LinkFactory()
link_3 = LinkFactory()
link_4 = LinkFactory()
content = TitleFactory()
through_1 = TitleLinkFactory(content=content, link=link_1, order=4)
TitleLinkFactory(content=content, link=link_2, order=3)
through_3 = TitleLinkFactory(content=content, link=link_3, order=2)
TitleLinkFactory(content=content, link=link_4, order=1)
user = UserFactory(is_staff=True)
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_link_multi(content, 'block.wizard.link.select')
data = {
'many_to_many': [through_1.pk, through_3.pk],
}
response = client.post(url, data)
# check
assert 302 == response.status_code
expect = url_link_multi(content, 'block.wizard.link.option')
assert expect in response['Location']
content.refresh_from_db()
assert 2 == content.references.count()
qs = content.ordered_references()
result = [item.link.pk for item in qs]
assert link_1.pk in result and link_3.pk in result
# ordering controlled by 'ordering' on 'TitleLink' model
assert [1, 2] == [item.order for item in qs]
示例3: test_order_multi_up_4
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import ordered_references [as 別名]
def test_order_multi_up_4(client):
content = TitleFactory()
t1, t2, t3, t4 = _set_up_order_multi(content)
_post_multi_order(client, content, {'up': t4.pk})
assert [
t1.pk, t2.pk, t4.pk, t3.pk
] == [item.pk for item in content.ordered_references()]
示例4: test_order_multi_up_invalid
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import ordered_references [as 別名]
def test_order_multi_up_invalid(client):
content = TitleFactory()
t1, t2, t3, t4 = _set_up_order_multi(content)
with pytest.raises(BlockError) as e:
_post_multi_order(client, content, {'up': t1.pk+t2.pk+t3.pk+t4.pk})
assert 'Cannot find item' in str(e.value)
assert [
t1.pk, t2.pk, t3.pk, t4.pk
] == [item.pk for item in content.ordered_references()]
示例5: test_order_multi_up_1
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import ordered_references [as 別名]
def test_order_multi_up_1(client):
"""Trying to move the first item up, should raise an exception."""
content = TitleFactory()
t1, t2, t3, t4 = _set_up_order_multi(content)
with pytest.raises(BlockError) as e:
_post_multi_order(client, content, {'up': t1.pk})
assert 'Cannot move the first item up' in str(e.value)
assert [
t1.pk, t2.pk, t3.pk, t4.pk
] == [item.pk for item in content.ordered_references()]