forked from doraemonext/wechat-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (26 loc) · 902 Bytes
/
utils.py
File metadata and controls
32 lines (26 loc) · 902 Bytes
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
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import json
from httmock import urlmatch, HTTMock, response
TESTS_PATH = os.path.abspath(os.path.dirname(__file__))
FIXTURE_PATH = os.path.join(TESTS_PATH, 'fixtures')
@urlmatch(netloc=r'(.*\.)?api\.weixin\.qq\.com$')
def api_weixin_mock(url, request):
path = url.path.replace('/cgi-bin/', '').replace('/', '_')
if path.startswith('_'):
path = path[1:]
res_file = os.path.join(FIXTURE_PATH, '%s.json' % path)
content = {
'errcode': 99999,
'errmsg': 'can not find fixture %s' % res_file,
}
headers = {
'Content-Type': 'application/json'
}
try:
with open(res_file, 'rb') as f:
content = json.loads(f.read().decode('utf-8'))
except (IOError, ValueError) as e:
print(e)
return response(200, content, headers, request=request)