• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vcr.use_cassette函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vcr.use_cassette函数的典型用法代码示例。如果您正苦于以下问题:Python use_cassette函数的具体用法?Python use_cassette怎么用?Python use_cassette使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了use_cassette函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_stops_in_area

    def test_stops_in_area(self):
        legion = StopPoint.objects.get(pk='5820AWN26274')
        self.assertEqual(self.stop_area, legion.stop_area)

        with catch_warnings(record=True) as caught_warnings:
            import_stops_in_area.Command().handle_row({
                'StopAreaCode': 'poo',
                'AtcoCode': 'poo'
            })
            self.assertEqual(1, len(caught_warnings))

        with vcr.use_cassette(os.path.join(FIXTURES_DIR, '5820AWN26361.yaml')):
            self.assertContains(self.client.get('/stops/5820AWN26361'), 'Port Talbot Circular')

        with vcr.use_cassette(os.path.join(FIXTURES_DIR, '5820AWN26274.yaml')):
            res = self.client.get('/stops/5820AWN26274')
        self.assertContains(res, 'On Talbot Road, near Eagle Street, near Port Talbot British Legion')
        self.assertContains(res, 'Services')
        self.assertContains(res, '44 - Port Talbot Circular')
        self.assertContains(res, """
            <div class="aside box">
                <h2>Nearby stops</h2>
                <ul class="has-smalls">
                    <li itemscope itemtype="https://schema.org/BusStop" data-indicator="NE-bound" data-heading="45">
                        <a href="/stops/5820AWN26438">
                            <span itemprop="name">Ty&#39;n y Twr Club (NE-bound)</span>
                        </a>
                        <span itemprop="geo" itemscope itemtype="https://schema.org/GeoCoordinates">
                            <meta itemprop="latitude" content="51.6171316877" />
                            <meta itemprop="longitude" content="-3.8000765776" />
                        </span>
                    </li>
                </ul>
            </div>
        """, html=True)
开发者ID:jclgoodwin,项目名称:bustimes.org.uk,代码行数:35,代码来源:test_import_naptan.py


示例2: test_flickr_multipart_upload

def test_flickr_multipart_upload(httpbin, tmpdir):
    """
    The python-flickr-api project does a multipart
    upload that confuses vcrpy
    """
    def _pretend_to_be_flickr_library():
        content_type, body = "text/plain", "HELLO WORLD"
        h = httplib.HTTPConnection(httpbin.host, httpbin.port)
        headers = {
            "Content-Type": content_type,
            "content-length": str(len(body))
        }
        h.request("POST", "/post/", headers=headers)
        h.send(body)
        r = h.getresponse()
        data = r.read()
        h.close()

        return data

    testfile = str(tmpdir.join('flickr.yml'))
    with vcr.use_cassette(testfile) as cass:
        _pretend_to_be_flickr_library()
        assert len(cass) == 1

    with vcr.use_cassette(testfile) as cass:
        assert len(cass) == 1
        _pretend_to_be_flickr_library()
        assert cass.play_count == 1
开发者ID:anovikov1984,项目名称:vcrpy,代码行数:29,代码来源:test_wild.py


示例3: test_original_decoded_response_is_not_modified

def test_original_decoded_response_is_not_modified(tmpdir, httpbin):
    testfile = str(tmpdir.join('decoded_response.yml'))
    host, port = httpbin.host, httpbin.port

    conn = httplib.HTTPConnection(host, port)
    conn.request('GET', '/gzip')
    outside = conn.getresponse()

    with vcr.use_cassette(testfile, decode_compressed_response=True):
        conn = httplib.HTTPConnection(host, port)
        conn.request('GET', '/gzip')
        inside = conn.getresponse()

        # Assert that we do not modify the original response while appending
        # to the casssette.
        assert 'gzip' == inside.headers['content-encoding']

        # They should effectively be the same response.
        inside_headers = (h for h in inside.headers.items() if h[0] != 'Date')
        outside_headers = (h for h in outside.getheaders() if h[0] != 'Date')
        assert set(inside_headers) == set(outside_headers)
        assert inside.read() == outside.read()

    # Even though the above are raw bytes, the JSON data should have been
    # decoded and saved to the cassette.
    with vcr.use_cassette(testfile):
        conn = httplib.HTTPConnection(host, port)
        conn.request('GET', '/gzip')
        inside = conn.getresponse()

        assert 'content-encoding' not in inside.headers
        assert_is_json(inside.read())
开发者ID:foobarna,项目名称:vcrpy,代码行数:32,代码来源:test_stubs.py


示例4: test_auth_failed

def test_auth_failed(get_client, tmpdir, scheme):
    '''Ensure that we can save failed auth statuses'''
    auth = ('user', 'wrongwrongwrong')
    url = scheme + '://httpbin.org/basic-auth/user/passwd'
    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        with pytest.raises(http.HTTPError) as exc_info:
            yield get(
                get_client(),
                url,
                auth_username=auth[0],
                auth_password=auth[1],
            )
        one = exc_info.value.response
        assert exc_info.value.code == 401

    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        with pytest.raises(http.HTTPError) as exc_info:
            two = yield get(
                get_client(),
                url,
                auth_username=auth[0],
                auth_password=auth[1],
            )
        two = exc_info.value.response
        assert exc_info.value.code == 401
        assert one.body == two.body
        assert one.code == two.code == 401
        assert 1 == cass.play_count
开发者ID:JanLikar,项目名称:vcrpy,代码行数:30,代码来源:test_tornado.py


示例5: test_original_response_is_not_modified_by_before_filter

def test_original_response_is_not_modified_by_before_filter(tmpdir, httpbin):
    testfile = str(tmpdir.join('sensitive_data_scrubbed_response.yml'))
    host, port = httpbin.host, httpbin.port
    field_to_scrub = 'url'
    replacement = '[YOU_CANT_HAVE_THE_MANGO]'

    conn = httplib.HTTPConnection(host, port)
    conn.request('GET', '/get')
    outside = conn.getresponse()

    callback = _make_before_record_response([field_to_scrub], replacement)
    with vcr.use_cassette(testfile, before_record_response=callback):
        conn = httplib.HTTPConnection(host, port)
        conn.request('GET', '/get')
        inside = conn.getresponse()

        # The scrubbed field should be the same, because no cassette existed.
        # Furthermore, the responses should be identical.
        inside_body = json.loads(inside.read().decode('utf-8'))
        outside_body = json.loads(outside.read().decode('utf-8'))
        assert not inside_body[field_to_scrub] == replacement
        assert inside_body[field_to_scrub] == outside_body[field_to_scrub]

    # Ensure that when a cassette exists, the scrubbed response is returned.
    with vcr.use_cassette(testfile, before_record_response=callback):
        conn = httplib.HTTPConnection(host, port)
        conn.request('GET', '/get')
        inside = conn.getresponse()

        inside_body = json.loads(inside.read().decode('utf-8'))
        assert inside_body[field_to_scrub] == replacement
开发者ID:adamchainz,项目名称:vcrpy,代码行数:31,代码来源:test_stubs.py


示例6: test_new_episodes_record_mode

def test_new_episodes_record_mode(tmpdir):
    testfile = str(tmpdir.join('recordmode.yml'))

    with vcr.use_cassette(testfile, record_mode="new_episodes"):
        # cassette file doesn't exist, so create.
        response = urlopen('http://httpbin.org/').read()

    with vcr.use_cassette(testfile, record_mode="new_episodes") as cass:
        # make the same request again
        response = urlopen('http://httpbin.org/').read()

        # all responses have been played
        assert cass.all_played

        # in the "new_episodes" record mode, we can add more requests to
        # a cassette without repurcussions.
        response = urlopen('http://httpbin.org/get').read()

        # one of the responses has been played
        assert cass.play_count == 1

        # not all responses have been played
        assert not cass.all_played

    with vcr.use_cassette(testfile, record_mode="new_episodes") as cass:
        # the cassette should now have 2 responses
        assert len(cass.responses) == 2
开发者ID:darioush,项目名称:vcrpy,代码行数:27,代码来源:test_record_mode.py


示例7: test_flickr_multipart_upload

def test_flickr_multipart_upload():
    """
    The python-flickr-api project does a multipart
    upload that confuses vcrpy
    """
    def _pretend_to_be_flickr_library():
        content_type, body = "text/plain", "HELLO WORLD"
        h = httplib.HTTPConnection("httpbin.org")
        headers = {
            "Content-Type": content_type,
            "content-length": str(len(body))
        }
        h.request("POST", "/post/", headers=headers)
        h.send(body)
        r = h.getresponse()
        data = r.read()
        h.close()

    with vcr.use_cassette('fixtures/vcr_cassettes/flickr.json') as cass:
        _pretend_to_be_flickr_library()
        assert len(cass) == 1

    with vcr.use_cassette('fixtures/vcr_cassettes/flickr.json') as cass:
        assert len(cass) == 1
        _pretend_to_be_flickr_library()
        assert cass.play_count == 1
开发者ID:aah,项目名称:vcrpy,代码行数:26,代码来源:test_wild.py


示例8: test_filter_querystring

def test_filter_querystring(tmpdir):
    url = 'http://httpbin.org/?foo=bar'
    cass_file = str(tmpdir.join('filter_qs.yaml'))
    with vcr.use_cassette(cass_file, filter_query_parameters=['foo']):
        urlopen(url)
    with vcr.use_cassette(cass_file, filter_query_parameters=['foo']) as cass:
        urlopen(url)
        assert 'foo' not in cass.requests[0].url
开发者ID:Bjwebb,项目名称:vcrpy,代码行数:8,代码来源:test_filter.py


示例9: test_random_body

def test_random_body(httpbin_both, tmpdir):
    '''Ensure we can read the content, and that it's served from cache'''
    url = httpbin_both.url + '/bytes/1024'
    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
        body = urlopen_with_cafile(url).read()

    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
        assert body == urlopen_with_cafile(url).read()
开发者ID:JanLikar,项目名称:vcrpy,代码行数:8,代码来源:test_urllib2.py


示例10: test_filter_post_data

def test_filter_post_data(tmpdir):
    url = "http://httpbin.org/post"
    data = urlencode({"id": "secret", "foo": "bar"}).encode("utf-8")
    cass_file = str(tmpdir.join("filter_pd.yaml"))
    with vcr.use_cassette(cass_file, filter_post_data_parameters=["id"]):
        urlopen(url, data)
    with vcr.use_cassette(cass_file, filter_post_data_parameters=["id"]) as cass:
        assert b"id=secret" not in cass.requests[0].body
开发者ID:koobs,项目名称:vcrpy,代码行数:8,代码来源:test_filter.py


示例11: test_headers

def test_headers(scheme, tmpdir):
    '''Ensure that we can read the headers back'''
    url = scheme + '://httpbin.org/'
    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
        headers = requests.get(url).headers

    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
        assert headers == requests.get(url).headers
开发者ID:gazpachoking,项目名称:vcrpy,代码行数:8,代码来源:test_requests.py


示例12: test_status_code

def test_status_code(scheme, tmpdir):
    '''Ensure that we can read the status code'''
    url = scheme + '://httpbin.org/'
    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
        status_code = requests.get(url).status_code

    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
        assert status_code == requests.get(url).status_code
开发者ID:gazpachoking,项目名称:vcrpy,代码行数:8,代码来源:test_requests.py


示例13: test_body

def test_body(tmpdir, scheme):
    '''Ensure the responses are all identical enough'''
    url = scheme + '://httpbin.org/bytes/1024'
    with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
        content = requests.get(url).content

    with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
        assert content == requests.get(url).content
开发者ID:aah,项目名称:vcrpy,代码行数:8,代码来源:test_requests.py


示例14: test_body

def test_body(tmpdir, scheme, verify_pool_mgr):
    '''Ensure the responses are all identical enough'''
    url = scheme + '://httpbin.org/bytes/1024'
    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
        content = verify_pool_mgr.request('GET', url).data

    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
        assert content == verify_pool_mgr.request('GET', url).data
开发者ID:JeffSpies,项目名称:vcrpy,代码行数:8,代码来源:test_urllib3.py


示例15: test_headers

def test_headers(scheme, tmpdir, verify_pool_mgr):
    '''Ensure that we can read the headers back'''
    url = scheme + '://httpbin.org/'
    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
        headers = verify_pool_mgr.request('GET', url).headers

    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
        assert headers == verify_pool_mgr.request('GET', url).headers
开发者ID:JeffSpies,项目名称:vcrpy,代码行数:8,代码来源:test_urllib3.py


示例16: test_status_code

def test_status_code(scheme, tmpdir, verify_pool_mgr):
    '''Ensure that we can read the status code'''
    url = scheme + '://httpbin.org/'
    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
        status_code = verify_pool_mgr.request('GET', url).status

    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
        assert status_code == verify_pool_mgr.request('GET', url).status
开发者ID:JeffSpies,项目名称:vcrpy,代码行数:8,代码来源:test_urllib3.py


示例17: test_headers

def test_headers(tmpdir, httpbin_both, verify_pool_mgr):
    '''Ensure that we can read the headers back'''
    url = httpbin_both.url
    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
        headers = verify_pool_mgr.request('GET', url).headers

    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
        assert headers == verify_pool_mgr.request('GET', url).headers
开发者ID:adamchainz,项目名称:vcrpy,代码行数:8,代码来源:test_urllib3.py


示例18: test_response_code

def test_response_code(httpbin_both, tmpdir):
    '''Ensure we can read a response code from a fetch'''
    url = httpbin_both.url
    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
        code = urlopen_with_cafile(url).getcode()

    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
        assert code == urlopen_with_cafile(url).getcode()
开发者ID:JanLikar,项目名称:vcrpy,代码行数:8,代码来源:test_urllib2.py


示例19: test_headers

def test_headers(httpbin_both, tmpdir):
    '''Ensure that we can read the headers back'''
    url = httpbin_both + '/'
    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
        headers = requests.get(url).headers

    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
        assert headers == requests.get(url).headers
开发者ID:dedsm,项目名称:vcrpy,代码行数:8,代码来源:test_requests.py


示例20: test_body

def test_body(tmpdir, httpbin_both):
    '''Ensure the responses are all identical enough'''
    url = httpbin_both + '/bytes/1024'
    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
        content = requests.get(url).content

    with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
        assert content == requests.get(url).content
开发者ID:dedsm,项目名称:vcrpy,代码行数:8,代码来源:test_requests.py



注:本文中的vcr.use_cassette函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vcr.VCR类代码示例发布时间:2022-05-26
下一篇:
Python shwrap.ExternalCommand类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap