forked from woocommerce/wc-api-python
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathtest_transport.py
More file actions
43 lines (35 loc) · 1.24 KB
/
Copy pathtest_transport.py
File metadata and controls
43 lines (35 loc) · 1.24 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
""" API Tests """
from __future__ import unicode_literals
import unittest
from httmock import HTTMock, all_requests
from wordpress.transport import API_Requests_Wrapper
class TransportTestcases(unittest.TestCase):
def setUp(self):
self.requester = API_Requests_Wrapper(
url='https://woo.test:8888/',
api='wp-json',
api_version='wp/v2'
)
def test_api_url(self):
self.assertEqual(
'https://woo.test:8888/wp-json',
self.requester.api_url
)
def test_endpoint_url(self):
self.assertEqual(
'https://woo.test:8888/wp-json/wp/v2/posts',
self.requester.endpoint_url('posts')
)
def test_request(self):
@all_requests
def woo_test_mock(*args, **kwargs):
""" URL Mock """
return {'status_code': 200,
'content': b'OK'}
with HTTMock(woo_test_mock):
# call requests
response = self.requester.request(
"GET", "https://woo.test:8888/wp-json/wp/v2/posts")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.request.url,
'https://woo.test:8888/wp-json/wp/v2/posts')