-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfixtures_session.py
More file actions
78 lines (65 loc) · 2.37 KB
/
fixtures_session.py
File metadata and controls
78 lines (65 loc) · 2.37 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# pylint: disable=missing-function-docstring
import pytest
from src.main.session import (
ApiSession,
HttpbinApiSessionLevelOne,
HttpbinApiSessionLevelTwo,
)
@pytest.fixture(scope='session', autouse=True)
def api_session() -> ApiSession:
with ApiSession() as session:
yield session
@pytest.fixture(scope='session')
def httpbin2() -> HttpbinApiSessionLevelOne:
with HttpbinApiSessionLevelOne() as session:
yield session
@pytest.fixture(scope='session')
def httpbin3() -> HttpbinApiSessionLevelTwo:
with HttpbinApiSessionLevelTwo() as session:
yield session
@pytest.fixture(scope='session')
def httpbin():
class _FakeResponse:
def __init__(self, payload: dict):
self._payload = payload
def json(self):
return self._payload
class _FakeHttpbin:
@staticmethod
def request(method, url):
if method == 'GET' and url == '/get':
return _FakeResponse(
{
'args': {},
'headers': {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Host': 'httpbin.org',
'User-Agent': 'python-requests/fake',
},
'origin': '127.0.0.1',
'url': 'https://httpbin.org/get',
}
)
if method == 'PATCH' and url == '/patch':
body = ''
return _FakeResponse(
{
'args': {},
'data': body,
'files': {},
'form': {},
'headers': {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Content-Length': str(len(body)),
'Host': 'httpbin.org',
'User-Agent': 'python-requests/fake',
},
'json': None,
'origin': '127.0.0.1',
'url': 'https://httpbin.org/patch',
}
)
raise ValueError(f'Unsupported fake httpbin request: method={method}, url={url}')
return _FakeHttpbin()