Exemple #1
0
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()]
Exemple #2
0
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]
Exemple #3
0
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()]
Exemple #4
0
def test_wizard_image_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_slideshow()]
Exemple #5
0
def test_wizard_image_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_slideshow()]
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()]