tests.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:django-sofortueberweisung 作者: ParticulateSolutions 项目源码 文件源码
def mock_urlopen(request, cafile=None):
    response = {}
    url = request.get_full_url()
    try:
        data = xmltodict.parse(request.data)
    except:
        data = {}
    try:
        if url == 'https://api.sofort.com/api/xml':
            if 'transaction_request' in data:
                if 'transaction' in data['transaction_request']:
                    if data['transaction_request']['transaction'] == '123-abc-received':
                        response = TEST_RESPONSES['123-abc-received']
                    elif data['transaction_request']['transaction'] == '123-abc-loss':
                        response = TEST_RESPONSES['123-abc-loss']
    except KeyError:
        response = False
        result = MockResponse(response)
    else:
        result = MockResponse(response)
        result.headers.update({'Content-type': 'application/xml; charset=UTF-8'})
        result.headers.update({'Accept': 'application/xml; charset=UTF-8'})
    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号