~homeworkprod/byceps

ref: 1181a35dd06d48c779208a6d2a4b3672dd38d812 byceps/tests/services/user_avatar/test_models_image_path.py -rw-r--r-- 1.2 KiB
1181a35d — Jochen Kupperschmidt Ported tests from nose2 to pytest 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from pathlib import Path
from uuid import UUID

import pytest

from byceps.util.image.models import ImageType

from testfixtures.user import create_user
from testfixtures.user_avatar import create_avatar

from tests.helpers import app_context


@pytest.mark.parametrize('avatar_images_path, avatar_id, image_type, expected', [
    (
        Path('/var/data/avatars'),
        UUID('2e17cb15-d763-4f93-882a-371296a3c63f'),
        ImageType.jpeg,
        Path('/var/data/avatars/2e17cb15-d763-4f93-882a-371296a3c63f.jpeg'),
    ),
    (
        Path('/home/byceps/data/global/users/avatars'),
        UUID('f0266761-c37e-4519-8cb8-5812d2bfe595'),
        ImageType.png,
        Path('/home/byceps/data/global/users/avatars/f0266761-c37e-4519-8cb8-5812d2bfe595.png'),
    ),
])
def test_path(avatar_images_path, avatar_id, image_type, expected):
    user = create_user()

    avatar = create_avatar(user.id, id=avatar_id, image_type=image_type)

    with app_context() as app:
        app.config['PATH_USER_AVATAR_IMAGES'] = avatar_images_path
        assert avatar.path == expected