| @@ 18-37 (lines=20) @@ | ||
| 15 | _FIXTURE_PATH = os.path.join(_TESTS_PATH, 'fixtures', 'enterprise') |
|
| 16 | ||
| 17 | ||
| 18 | @urlmatch(netloc=r'(.*\.)?qyapi\.weixin\.qq\.com$') |
|
| 19 | def wechat_api_mock(url, request): |
|
| 20 | path = url.path.replace('/cgi-bin/', '').replace('/', '_') |
|
| 21 | res_file = os.path.join(_FIXTURE_PATH, '%s.json' % path) |
|
| 22 | content = { |
|
| 23 | 'errcode': 99999, |
|
| 24 | 'errmsg': 'can not find fixture %s' % res_file, |
|
| 25 | } |
|
| 26 | headers = { |
|
| 27 | 'Content-Type': 'application/json' |
|
| 28 | } |
|
| 29 | try: |
|
| 30 | with open(res_file, 'rb') as f: |
|
| 31 | content = json.loads(f.read().decode('utf-8')) |
|
| 32 | except (IOError, ValueError) as e: |
|
| 33 | content['errmsg'] = 'Loads fixture {0} failed, error: {1}'.format( |
|
| 34 | res_file, |
|
| 35 | e |
|
| 36 | ) |
|
| 37 | return response(200, content, headers, request=request) |
|
| 38 | ||
| 39 | ||
| 40 | class WeChatClientTestCase(unittest.TestCase): |
|
| @@ 14-33 (lines=20) @@ | ||
| 11 | _FIXTURE_PATH = os.path.join(_TESTS_PATH, 'fixtures', 'enterprise') |
|
| 12 | ||
| 13 | ||
| 14 | @urlmatch(netloc=r'(.*\.)?qyapi\.weixin\.qq\.com$') |
|
| 15 | def wechat_api_mock(url, request): |
|
| 16 | path = url.path.replace('/cgi-bin/', '').replace('/', '_') |
|
| 17 | res_file = os.path.join(_FIXTURE_PATH, '%s.json' % path) |
|
| 18 | content = { |
|
| 19 | 'errcode': 99999, |
|
| 20 | 'errmsg': 'can not find fixture %s' % res_file, |
|
| 21 | } |
|
| 22 | headers = { |
|
| 23 | 'Content-Type': 'application/json' |
|
| 24 | } |
|
| 25 | try: |
|
| 26 | with open(res_file, 'rb') as f: |
|
| 27 | content = json.loads(f.read().decode('utf-8')) |
|
| 28 | except (IOError, ValueError) as e: |
|
| 29 | content['errmsg'] = 'Loads fixture {0} failed, error: {1}'.format( |
|
| 30 | res_file, |
|
| 31 | e |
|
| 32 | ) |
|
| 33 | return response(200, content, headers, request=request) |
|
| 34 | ||
| 35 | ||
| 36 | class WeChatClientTestCase(unittest.TestCase): |
|
| @@ 16-32 (lines=17) @@ | ||
| 13 | _FIXTURE_PATH = os.path.join(_TESTS_PATH, 'fixtures', 'component') |
|
| 14 | ||
| 15 | ||
| 16 | @urlmatch(netloc=r'(.*\.)?api\.weixin\.qq\.com$') |
|
| 17 | def wechat_api_mock(url, request): |
|
| 18 | path = url.path.replace('/cgi-bin/component/', '').replace('/', '_') |
|
| 19 | res_file = os.path.join(_FIXTURE_PATH, '%s.json' % path) |
|
| 20 | content = { |
|
| 21 | 'errcode': 99999, |
|
| 22 | 'errmsg': 'can not find fixture %s' % res_file, |
|
| 23 | } |
|
| 24 | headers = { |
|
| 25 | 'Content-Type': 'application/json' |
|
| 26 | } |
|
| 27 | try: |
|
| 28 | with open(res_file, 'rb') as f: |
|
| 29 | content = json.loads(f.read().decode('utf-8')) |
|
| 30 | except (IOError, ValueError): |
|
| 31 | pass |
|
| 32 | return response(200, content, headers, request=request) |
|
| 33 | ||
| 34 | ||
| 35 | class WeChatComponentTestCase(unittest.TestCase): |
|