Пример #1
0
def test_prepare_finds_large_file(mocker):
    filepaths = [
        'path/to/file0.jpg',
        'path/file1.jpg',
        'path/where/file2.jpg',
    ]
    mocker.patch('builtins.open',
                 Mock(side_effect=['fileobj0', 'fileobj1', 'fileobj2']))
    mocker.patch('os.path.getsize',
                 side_effect=[1048576, _const.MAX_FILE_SIZE + 1, 1048576])
    g = Gallery()
    submissions = g._prepare(*filepaths)
    assert submissions == [
        (filepaths[0], (os.path.basename(filepaths[0]), 'fileobj0'), None),
        (filepaths[1], None,
         f'File is larger than {_const.MAX_FILE_SIZE} bytes'),
        (filepaths[2], (os.path.basename(filepaths[2]), 'fileobj2'), None),
    ]
Пример #2
0
def test_prepare_fails_to_open_file(mocker):
    filepaths = [
        'path/to/file0.jpg',
        'path/file1.jpg',
        'path/where/file2.jpg',
    ]
    mocker.patch(
        'builtins.open',
        Mock(side_effect=[
            'fileobj0',
            OSError('mock errno', 'No such file'),
            'fileobj2',
        ], ))
    mocker.patch('os.path.getsize', return_value=1048576)
    g = Gallery()
    submissions = g._prepare(*filepaths)
    assert submissions == [
        (filepaths[0], (os.path.basename(filepaths[0]), 'fileobj0'), None),
        (filepaths[1], None, 'No such file'),
        (filepaths[2], (os.path.basename(filepaths[2]), 'fileobj2'), None),
    ]