Passed
Push — main ( e5f873...d78ac2 )
by Jochen
04:15
created

tests.integration.services.user_avatar.test_models_image_path   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 4

3 Functions

Rating   Name   Duplication   Size   Complexity  
A app() 0 4 2
A test_path() 0 25 1
A create_avatar() 0 4 1
1
"""
2
:Copyright: 2006-2021 Jochen Kupperschmidt
3
:License: Revised BSD (see `LICENSE` file for details)
4
"""
5
6
from pathlib import Path
7
from uuid import UUID
8
9
import pytest
10
11
from byceps.services.user_avatar.dbmodels import Avatar
12
from byceps.util.image.models import ImageType
13
14
from tests.helpers import app_context
15
16
17
@pytest.fixture
18
def app():
19
    with app_context() as app:
20
        yield app
21
22
23
@pytest.mark.parametrize(
24
    'data_path, avatar_id, image_type, expected',
25
    [
26
        (
27
            Path('/var/byceps/data'),
28
            UUID('2e17cb15-d763-4f93-882a-371296a3c63f'),
29
            ImageType.jpeg,
30
            Path('/var/byceps/data/global/users/avatars/2e17cb15-d763-4f93-882a-371296a3c63f.jpeg'),
31
        ),
32
        (
33
            Path('/home/byceps/data'),
34
            UUID('f0266761-c37e-4519-8cb8-5812d2bfe595'),
35
            ImageType.png,
36
            Path('/home/byceps/data/global/users/avatars/f0266761-c37e-4519-8cb8-5812d2bfe595.png'),
37
        ),
38
    ],
39
)
40
def test_path(app, data_path, avatar_id, image_type, expected):
41
    user_id = UUID('dc4e11d5-0c43-42d9-add2-37e947f19e68')
42
43
    app.config['PATH_DATA'] = data_path
44
45
    avatar = create_avatar(user_id, avatar_id, image_type)
46
47
    assert avatar.path == expected
48
49
50
# helpers
51
52
53
def create_avatar(creator_id, avatar_id, image_type):
54
    avatar = Avatar(creator_id, image_type)
55
    avatar.id = avatar_id
56
    return avatar
57