| 23 | |
| 24 | @urlmatch(netloc=r'(.*\.)?api\.weixin\.qq\.com$') |
| 25 | def wechat_api_mock(url, request): |
| 26 | path = url.path.replace('/cgi-bin/', '').replace('/', '_') |
| 27 | if path.startswith('_'): |
| 28 | path = path[1:] |
| 29 | res_file = os.path.join(FIXTURE_PATH, '%s.json' % path) |
| 30 | content = { |
| 31 | 'errcode': 99999, |
| 32 | 'errmsg': 'can not find fixture %s' % res_file, |
| 33 | } |
| 34 | headers = { |
| 35 | 'Content-Type': 'application/json' |
| 36 | } |
| 37 | try: |
| 38 | with open(res_file, 'rb') as f: |
| 39 | content = json.loads(f.read().decode('utf-8')) |
| 40 | except (IOError, ValueError) as e: |
| 41 | print(e) |
| 42 | return response(200, content, headers, request=request) |
| 43 | |
| 44 | |
| 45 | class WechatBasicTestCase(unittest.TestCase): |