~homeworkprod/byceps

1b8d7118484005af0280fb734f874aa3efd268b9 — Jochen Kupperschmidt 1 year, 10 months ago 1668918
Make user avatar path depend on data path, but non-configurable besides that
M byceps/services/user_avatar/models.py => byceps/services/user_avatar/models.py +1 -1
@@ 56,7 56,7 @@ class Avatar(db.Model):

    @property
    def path(self) -> Path:
        path = current_app.config['PATH_USER_AVATAR_IMAGES']
        path = current_app.config['PATH_DATA'] / 'global' / 'users' / 'avatars'
        return path / self.filename

    @property

M config/development_admin.py => config/development_admin.py +0 -1
@@ 14,7 14,6 @@ SITE_MODE = 'admin'

PATH_DATA = Path('./data')
PATH_GLOBAL = PATH_DATA / 'global'
PATH_USER_AVATAR_IMAGES = PATH_GLOBAL / 'users/avatars'

MAIL_DEBUG = True
MAIL_DEFAULT_SENDER = 'BYCEPS <noreply@example.com>'

M config/development_party.py => config/development_party.py +0 -1
@@ 20,7 20,6 @@ PATH_DATA = Path('./data')
PATH_GLOBAL = PATH_DATA / 'global'
PATH_BRAND = PATH_DATA / 'brands' / BRAND
PATH_PARTY = PATH_DATA / 'parties' / PARTY
PATH_USER_AVATAR_IMAGES = PATH_GLOBAL / 'users/avatars'

MAIL_DEBUG = True
MAIL_DEFAULT_SENDER = 'BYCEPS <noreply@example.com>'

M config/production_party.py => config/production_party.py +0 -1
@@ 27,7 27,6 @@ PATH_DATA = Path('./data')
PATH_GLOBAL = PATH_DATA / 'global'
PATH_BRAND = PATH_DATA / 'brands' / BRAND
PATH_PARTY = PATH_DATA / 'parties' / PARTY
PATH_USER_AVATAR_IMAGES = PATH_GLOBAL / 'users/avatars'

MAIL_DEBUG = False
MAIL_DEFAULT_SENDER = 'BYCEPS <noreply@example.com>'

M config/test_party.py => config/test_party.py +0 -1
@@ 21,7 21,6 @@ PATH_DATA = Path('./data')
PATH_GLOBAL = PATH_DATA / 'global'
PATH_BRAND = PATH_DATA / 'brands' / BRAND
PATH_PARTY = PATH_DATA / 'parties' / PARTY
PATH_USER_AVATAR_IMAGES = PATH_GLOBAL / 'users/avatars'

MAIL_DEBUG = False
MAIL_DEFAULT_SENDER = 'BYCEPS <noreply@example.com>'

M tests/services/user_avatar/test_models_image_path.py => tests/services/user_avatar/test_models_image_path.py +6 -6
@@ 16,25 16,25 @@ from testfixtures.user_avatar import create_avatar
from tests.helpers import app_context


@pytest.mark.parametrize('avatar_images_path, avatar_id, image_type, expected', [
@pytest.mark.parametrize('data_path, avatar_id, image_type, expected', [
    (
        Path('/var/data/avatars'),
        Path('/var/byceps/data'),
        UUID('2e17cb15-d763-4f93-882a-371296a3c63f'),
        ImageType.jpeg,
        Path('/var/data/avatars/2e17cb15-d763-4f93-882a-371296a3c63f.jpeg'),
        Path('/var/byceps/data/global/users/avatars/2e17cb15-d763-4f93-882a-371296a3c63f.jpeg'),
    ),
    (
        Path('/home/byceps/data/global/users/avatars'),
        Path('/home/byceps/data'),
        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):
def test_path(data_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
        app.config['PATH_DATA'] = data_path
        assert avatar.path == expected