예제 #1
0
def test_images(image_factory):
    controller = Controller(model=Model())
    assert controller.images == []

    for name in ('foo.jpg', 'bar.jpg', 'baz.jpg'):
        controller.add_image(image_factory(name))

    # images must be ordered alphabetically
    assert [image.path.name for image in controller.images] == [
        'bar.jpg',
        'baz.jpg',
        'foo.jpg',
    ]
예제 #2
0
def test_empty_add_one_image_and_tag_it(basedir, image_factory):
    controller = Controller(model=Model())
    assert controller._view._window.title() == "PicPick *"
    assert controller.images == []
    assert controller.tags == []
    assert controller.current_image is None

    controller.save(basedir / 'save.picpick')
    assert controller._view._window.title() == "PicPick - save.picpick"

    controller.add_image(image_factory('foo.jpg'))
    assert [image.path.name for image in controller.images] == ['foo.jpg']
    assert controller.current_image is not None

    controller.add_tag(Tag(name='alpha'))
    controller.add_tag(Tag(name='beta'))
    assert controller.tags == [Tag(name='alpha'), Tag(name='beta')]

    assert controller._view._window.title() == "PicPick - save.picpick*"
    controller.save(basedir / 'save.picpick')
    assert controller._view._window.title() == "PicPick - save.picpick"

    assert controller.current_image.path.name == 'foo.jpg'
    assert controller.current_image.tags == set()

    controller.tag_current_image(Tag(name='alpha'))
    controller.tag_current_image(Tag(name='beta'))
    assert controller.current_image.tags == {
        Tag(name='alpha'), Tag(name='beta')
    }

    assert controller._view._window.title() == "PicPick - save.picpick*"
    controller.save(basedir / 'save.picpick')
    assert controller._view._window.title() == "PicPick - save.picpick"

    # eventually wants to rename the first tag and delete the second
    controller.update_tag(old=Tag(name="alpha"), new=Tag(name="gamma"))
    controller.delete_tag(Tag(name="beta"))

    assert controller.tags == [Tag(name="gamma")]

    # image tags must have also been updated
    assert controller.current_image.tags == {Tag(name="gamma")}
예제 #3
0
def test_add_image(image_factory):
    view = mock.MagicMock()
    controller = Controller(model=Model())
    controller._view = view
    assert not hasattr(controller, '_current_image')

    # adding the first image should automatically set it as current
    controller.add_image(image_factory('foo.jpg'))
    assert controller._current_image.path.name == 'foo.jpg'
    assert [image.path.name for image in controller.images] == ['foo.jpg']

    view.update_images.assert_called_once_with()
    view.reset_mock()

    controller.add_image(image_factory('bar.jpg'))
    assert controller._current_image.path.name == 'foo.jpg'
    assert [image.path.name
            for image in controller.images] == ['bar.jpg', 'foo.jpg']

    view.update_images.assert_called_once_with()
    view.reset_mock()

    # adding the same image twice should fail
    with pytest.raises(Controller.ImageAlreadyPresent,
                       match="foo.jpg is already present"):
        controller.add_image(image_factory('foo.jpg'))
    assert [image.path.name
            for image in controller.images] == ['bar.jpg', 'foo.jpg']

    view.update_images.assert_not_called()
    view.reset_mock()