Ejemplo n.º 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()]
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
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]
Ejemplo n.º 4
0
def _post_multi_order(client, content, data):
    user = UserFactory(is_staff=True)
    assert client.login(username=user.username, password=TEST_PASSWORD) is True
    url = url_image_multi(content, 'block.wizard.image.order')
    response = client.post(url, data)
    # check
    assert 302 == response.status_code
    assert url in response['Location']
Ejemplo n.º 5
0
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()]