~homeworkprod/byceps

ref: 3f0e201ac95beb0652058399be012d179753d775 byceps/tests/api/tourney/avatar/test_create.py -rw-r--r-- 1016 bytes
3f0e201a — Jochen Kupperschmidt Create tourney avatar path on upload if it doesn't exist 1 year, 11 months 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
41
"""
:Copyright: 2006-2020 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from pathlib import Path
from tempfile import TemporaryDirectory

import pytest


def test_create(
    tourney_path, app, api_client, api_client_authz_header, party, user
):
    app.config['PATH_TOURNEY_AVATAR_IMAGES'] = tourney_path / 'avatars'

    response = send_request(
        api_client, api_client_authz_header, party.id, user.id
    )

    assert response.status_code == 201


@pytest.fixture
def tourney_path():
    with TemporaryDirectory() as d:
        yield Path(d)


def send_request(api_client, api_client_authz_header, party_id, creator_id):
    url = f'/api/tourney/avatars'

    headers = [api_client_authz_header]
    with Path('testfixtures/images/image.png').open('rb') as image_file:
        form_data = {
            'image': image_file,
            'party_id': party_id,
            'creator_id': creator_id,
        }

        return api_client.post(url, headers=headers, data=form_data)