当前位置: 首页>>代码示例>>Python>>正文


Python factories.TitleFactory类代码示例

本文整理汇总了Python中example_block.tests.factories.TitleFactory的典型用法代码示例。如果您正苦于以下问题:Python TitleFactory类的具体用法?Python TitleFactory怎么用?Python TitleFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TitleFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_upload_single

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()
开发者ID:,项目名称:,代码行数:28,代码来源:

示例2: test_external_single

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
开发者ID:,项目名称:,代码行数:25,代码来源:

示例3: test_select_multi

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]
开发者ID:,项目名称:,代码行数:28,代码来源:

示例4: test_wizard_image_choose_category_multi

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()]
开发者ID:,项目名称:,代码行数:25,代码来源:

示例5: test_wizard_image_select_multi

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]
开发者ID:,项目名称:,代码行数:29,代码来源:

示例6: test_wizard_image_upload_multi

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()
开发者ID:,项目名称:,代码行数:25,代码来源:

示例7: test_wizard_image_order_multi_up_4

def test_wizard_image_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_slideshow()]
开发者ID:,项目名称:,代码行数:7,代码来源:

示例8: test_choose_category_multi

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()]
开发者ID:,项目名称:,代码行数:25,代码来源:

示例9: test_order_multi_up_4

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()]
开发者ID:,项目名称:,代码行数:7,代码来源:

示例10: test_edit_published

def test_edit_published():
    """edit published content."""
    page_section = PageSectionFactory()
    # block_1
    block_1 = TitleBlockFactory(page_section=page_section)
    TitleFactory(block=block_1, title='content_1')
    block_1.publish(UserFactory())
    # block_2
    block_2 = TitleBlockFactory(page_section=page_section)
    content_2 = TitleFactory(block=block_2, title='content_2')
    block_2.publish(UserFactory())
    # check pending
    assert [
        'content_1', 'content_2'
    ] == [c.title for c in Title.objects.pending(page_section)]
    # check published
    assert [
        'content_1', 'content_2'
    ] == [c.title for c in Title.objects.published(page_section)]
    # edit content
    content_2.title = 'content_2_edit'
    content_2.save()
    # check pending
    assert [
        'content_1', 'content_2_edit'
    ] == [c.title for c in Title.objects.pending(page_section)]
    # check published
    assert [
        'content_1', 'content_2'
    ] == [c.title for c in Title.objects.published(page_section)]
开发者ID:pkimber,项目名称:block,代码行数:30,代码来源:test_moderate.py

示例11: test_order_multi_up_invalid

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()]
开发者ID:,项目名称:,代码行数:9,代码来源:

示例12: test_order_multi_up_1

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()]
开发者ID:,项目名称:,代码行数:10,代码来源:

示例13: test_wizard_image_order_multi_down_4

def test_wizard_image_order_multi_down_4(client):
    """Trying to move the last item down, 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, {'down': t4.pk})
    assert 'Cannot move the last item down' in str(e.value)
    assert [
        t1.pk, t2.pk, t3.pk, t4.pk
    ] == [item.pk for item in content.ordered_slideshow()]
开发者ID:,项目名称:,代码行数:10,代码来源:

示例14: test_remove_single

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
开发者ID:,项目名称:,代码行数:15,代码来源:

示例15: TestWorkflow

class TestWorkflow(TestCase):

    def setUp(self):
        user = UserFactory(username='staff', is_staff=True)
        self.assertTrue(
            self.client.login(username=user.username, password=TEST_PASSWORD)
        )
        self.block = TitleFactory().block

    def _get_pending(self):
        return self.block.content.get(
            moderate_state=ModerateState.objects._pending()
        )

    def _get_published(self):
        return self.block.content.get(
            moderate_state=ModerateState.objects._published()
        )

    def _pending_count(self):
        return self.block.content.filter(
            moderate_state=ModerateState.objects._pending()
        ).count()

    def _publish_count(self):
        return self.block.content.filter(
            moderate_state=ModerateState.objects._published()
        ).count()

    def _remove_count(self):
        return self.block.content.filter(
            moderate_state__slug=ModerateState.REMOVED
        ).count()

    def test_pending(self):
        self.assertEqual(1, self._pending_count())
        self.assertEqual(0, self._publish_count())
        self.assertEqual(0, self._remove_count())

    def test_published(self):
        self.block.publish(UserFactory())
        self.assertEqual(1, self._pending_count())
        self.assertEqual(1, self._publish_count())
        self.assertEqual(0, self._remove_count())

    def test_remove_pending(self):
        self.block.remove(UserFactory())
        self.assertEqual(0, self._pending_count())
        self.assertEqual(0, self._publish_count())
        self.assertEqual(1, self._remove_count())

    def test_remove_published(self):
        self.block.publish(UserFactory())
        self.block.remove(UserFactory())
        self.assertEqual(0, self._pending_count())
        self.assertEqual(0, self._publish_count())
        self.assertEqual(1, self._remove_count())
开发者ID:pkimber,项目名称:block,代码行数:57,代码来源:test_workflow.py


注:本文中的example_block.tests.factories.TitleFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。