本文整理匯總了Python中example_block.tests.factories.TitleFactory.refresh_from_db方法的典型用法代碼示例。如果您正苦於以下問題:Python TitleFactory.refresh_from_db方法的具體用法?Python TitleFactory.refresh_from_db怎麽用?Python TitleFactory.refresh_from_db使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類example_block.tests.factories.TitleFactory
的用法示例。
在下文中一共展示了TitleFactory.refresh_from_db方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_select_multi
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [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]
示例2: test_choose_category_multi
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [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()]
示例3: test_wizard_image_choose_category_multi
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_wizard_image_choose_category_multi(client):
"""Choose from images in the selected category."""
content = TitleFactory()
category = ImageCategoryFactory()
ImageFactory()
image_2 = ImageFactory(category=category)
ImageFactory(category=category)
image_4 = ImageFactory(category=category)
user = UserFactory(is_staff=True)
assert content.picture is None
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_image_multi(content, 'block.wizard.image.choose', category=category)
assert category.slug in url
data = {
'images': [image_2.pk, image_4.pk],
}
response = client.post(url, data)
# check
assert 302 == response.status_code
expect = url_image_multi(content, 'block.wizard.image.option')
assert expect in response['Location']
content.refresh_from_db()
assert 2 == content.slideshow.count()
# ordering controlled by 'ordering' on 'TitleImage' model
assert [1, 2] == [item.order for item in content.ordered_slideshow()]
示例4: test_upload_single
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_upload_single(client):
content = TitleFactory()
category = LinkCategoryFactory()
DocumentFactory()
#image = ImageFactory()
user = UserFactory(is_staff=True)
assert content.link is None
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_link_single(content, 'block.wizard.link.upload')
# create a document ready to upload
data = {
'add_to_library': True,
'category': category.pk,
'document': test_file(),
'title': 'Cricket',
}
response = client.post(url, data)
# check
content.refresh_from_db()
expect = content.block.page_section.page.get_design_url()
assert 302 == response.status_code
assert expect in response['Location']
assert 'Cricket' == content.link.title
assert content.link is not None
assert category == content.link.category
assert content.link.document.deleted is False
# check a document has been added to the database
assert 2 == Document.objects.count()
示例5: test_external_single
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_external_single(client):
content = TitleFactory()
#category = ImageCategoryFactory()
#DocumentFactory()
#image = ImageFactory()
user = UserFactory(is_staff=True)
assert content.link is None
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_link_single(content, 'block.wizard.link.external')
# create a document ready to upload
data = {
'add_to_library': True,
#'category': category.pk,
'url_external': 'https://www.pkimber.net',
'title': 'Rugby',
}
response = client.post(url, data)
# check
content.refresh_from_db()
expect = content.block.page_section.page.get_design_url()
assert 302 == response.status_code
assert expect in response['Location']
assert 'Rugby' == content.link.title
assert content.link is not None
assert 'https://www.pkimber.net' == content.link.url_external
示例6: test_wizard_image_upload_multi
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_wizard_image_upload_multi(client):
content = TitleFactory()
category = ImageCategoryFactory()
user = UserFactory(is_staff=True)
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_image_multi(content, 'block.wizard.image.upload')
data = {
'add_to_library': True,
'category': category.pk,
'image': test_file(),
'title': 'Cricket',
}
response = client.post(url, data)
# check
content.refresh_from_db()
assert 302 == response.status_code
expect = url_image_multi(content, 'block.wizard.image.option')
assert expect in response['Location']
assert 1 == content.slideshow.count()
image = content.slideshow.first()
assert 'Cricket' == image.title
assert image.category == category
assert image.deleted is False
# check an image has been added to the database
assert 1 == Image.objects.count()
示例7: test_wizard_image_select_multi
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_wizard_image_select_multi(client):
"""The single test for removing is ``test_wizard_image_remove_single``."""
image_1 = ImageFactory()
image_2 = ImageFactory()
image_3 = ImageFactory()
image_4 = ImageFactory()
content = TitleFactory()
through_1 = TitleImageFactory(content=content, image=image_1, order=4)
TitleImageFactory(content=content, image=image_2, order=3)
through_3 = TitleImageFactory(content=content, image=image_3, order=2)
TitleImageFactory(content=content, image=image_4, order=1)
user = UserFactory(is_staff=True)
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_image_multi(content, 'block.wizard.image.select')
data = {
'many_to_many': [through_1.pk, through_3.pk],
}
response = client.post(url, data)
# check
assert 302 == response.status_code
expect = url_image_multi(content, 'block.wizard.image.option')
assert expect in response['Location']
content.refresh_from_db()
assert 2 == content.slideshow.count()
qs = content.ordered_slideshow()
result = [item.image.pk for item in qs]
assert image_1.pk in result and image_3.pk in result
# ordering controlled by 'ordering' on 'TitleImage' model
assert [1, 2] == [item.order for item in qs]
示例8: test_remove_single
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_remove_single(client):
"""The multi test for removing is ````."""
link = LinkFactory()
content = TitleFactory(link=link)
user = UserFactory(is_staff=True)
assert content.link is not None
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_link_single(content, 'block.wizard.link.remove')
response = client.post(url)
# check
content.refresh_from_db()
expect = content.block.page_section.page.get_design_url()
assert 302 == response.status_code
assert expect in response['Location']
assert content.link is None
示例9: test_choose_single
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_choose_single(client):
content = TitleFactory()
LinkFactory()
link = LinkFactory()
user = UserFactory(is_staff=True)
assert content.link is None
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_link_single(content, 'block.wizard.link.choose')
data = {
'links': link.pk,
}
response = client.post(url, data)
# check
assert 302 == response.status_code
expect = content.block.page_section.page.get_design_url()
assert expect in response['Location']
content.refresh_from_db()
assert link == content.link
示例10: test_wizard_image_choose_category_single
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_wizard_image_choose_category_single(client):
"""Choose from images in the selected category."""
content = TitleFactory()
category = ImageCategoryFactory()
ImageFactory()
image = ImageFactory(category=category)
user = UserFactory(is_staff=True)
assert content.picture is None
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_image_single(content, 'block.wizard.image.choose', category=category)
assert category.slug in url
data = {
'images': image.pk,
}
response = client.post(url, data)
# check
assert 302 == response.status_code
expect = content.block.page_section.page.get_design_url()
assert expect in response['Location']
content.refresh_from_db()
assert image == content.picture
示例11: test_wizard_image_choose_multi
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_wizard_image_choose_multi(client):
content = TitleFactory()
ImageFactory(title='0')
image_1 = ImageFactory(title='1')
image_2 = ImageFactory(title='2')
user = UserFactory(is_staff=True)
assert content.picture is None
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_image_multi(content, 'block.wizard.image.choose')
data = {
'images': [image_2.pk, image_1.pk],
}
response = client.post(url, data)
# check
assert 302 == response.status_code, response.context['form'].errors
expect = url_image_multi(content, 'block.wizard.image.option')
assert expect in response['Location']
content.refresh_from_db()
assert 2 == content.slideshow.count()
# ordering controlled by 'ordering' on 'TitleImage' model
assert [1, 2] == [item.order for item in content.ordered_slideshow()]
示例12: test_page_single
# 需要導入模塊: from example_block.tests.factories import TitleFactory [as 別名]
# 或者: from example_block.tests.factories.TitleFactory import refresh_from_db [as 別名]
def test_page_single(client):
content = TitleFactory()
#category = ImageCategoryFactory()
page = PageFactory(name='Information', slug='info', slug_menu='')
url_internal = Url.objects.init_page_url(page)
user = UserFactory(is_staff=True)
assert content.link is None
assert client.login(username=user.username, password=TEST_PASSWORD) is True
url = url_link_single(content, 'block.wizard.link.page')
# create a document ready to upload
data = {
#'add_to_library': True,
#'category': category.pk,
'url_internal': url_internal.pk,
'title': 'Cricket',
}
response = client.post(url, data)
# check
content.refresh_from_db()
expect = content.block.page_section.page.get_design_url()
assert 302 == response.status_code
assert expect in response['Location']
assert 'Cricket' == content.link.title
assert url_internal == content.link.url_internal