~homeworkprod/byceps

ref: a3214d27456b4060727966ca1ad520a92edaa6b2 byceps/tests/api/tourney/avatar/test_create.py -rw-r--r-- 982 bytes
a3214d27 — Jochen Kupperschmidt Make tourney avatar path depend on party path, but non-configurable besides that 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(
    party_path, app, api_client, api_client_authz_header, party, user
):
    app.config['PATH_PARTY'] = party_path

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

    assert response.status_code == 201


@pytest.fixture
def party_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)