Completed
Push — master ( 87f3f9...e861eb )
by Jochen
04:09
created

send_request()   A

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nop 4
dl 0
loc 12
rs 9.95
c 0
b 0
f 0
1
"""
2
:Copyright: 2006-2019 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
    avatars_path, app, api_client, api_client_authz_header, party, user
14
):
15
    app.config['PATH_TOURNEY_AVATAR_IMAGES'] = avatars_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 avatars_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