-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
50 lines (39 loc) · 1.33 KB
/
tests.py
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
from unittest import TestCase
import requests
from remocker import Remocker, RemockerResponse, join_path
BASE_URL = 'https://test.com/base'
mocker_app = Remocker(BASE_URL)
@mocker_app.mock(method='GET', path='products')
def get_products_mocker(request):
response = RemockerResponse({
'success': True,
'given_params': request.query_params,
})
return response
@mocker_app.mock(method='POST', path='products')
def create_product_mocker(request):
response = RemockerResponse({
'success': True,
'given_data': request.data,
})
return response
@mocker_app.mock(method='GET', path=r'products/(?P<product_id>\d+)', regex=True)
def get_product_mocker(request):
response = RemockerResponse({
'success': True,
'given_product_id': request.url_params['product_id'],
})
return response
class RemockerTestCase(TestCase):
def test_mocking(self):
with mocker_app.mocking():
response = requests.get(join_path(BASE_URL, 'products'), params={
'foo': 'var',
'foos': [
'var', 'var', 'var'
],
})
response = requests.post(join_path(BASE_URL, 'products'), json={
'foo': 'var'
})
response = requests.get(join_path(BASE_URL, 'products/1'))