Completed
Push — master ( a3214d...e114dc )
by Jochen
02:21
created

tests.api.tourney.avatar.test_create.data_path()   A

Complexity

Conditions 2

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2020 Jochen Kupperschmidt
3
:License: Modified BSD, see LICENSE for details.
4
"""
5
6
from pathlib import Path
7
from tempfile import TemporaryDirectory
8
9
import pytest
10
11
12
def test_create(
13
    data_path, app, api_client, api_client_authz_header, party, user
14
):
15
    app.config['PATH_DATA'] = data_path
16
17
    response = send_request(
18
        api_client, api_client_authz_header, party.id, user.id
19
    )
20
21
    assert response.status_code == 201
22
23
24
@pytest.fixture
25
def data_path():
26
    with TemporaryDirectory() as d:
27
        yield Path(d)
28
29
30
def send_request(api_client, api_client_authz_header, party_id, creator_id):
31
    url = f'/api/tourney/avatars'
32
33
    headers = [api_client_authz_header]
34
    with Path('testfixtures/images/image.png').open('rb') as image_file:
35
        form_data = {
36
            'image': image_file,
37
            'party_id': party_id,
38
            'creator_id': creator_id,
39
        }
40
41
        return api_client.post(url, headers=headers, data=form_data)
42