File: test_multiple.py

package info (click to toggle)
vcr.py 8.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,036 kB
  • sloc: python: 6,275; makefile: 188; sh: 1
file content (23 lines) | stat: -rw-r--r-- 973 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from urllib.request import urlopen

import pytest

import vcr
from vcr.errors import CannotOverwriteExistingCassetteException


def test_making_extra_request_raises_exception(tmpdir, httpbin):
    # make two requests in the first request that are considered
    # identical (since the match is based on method)
    with vcr.use_cassette(str(tmpdir.join("test.json")), match_on=["method"]):
        urlopen(httpbin.url + "/status/200")
        urlopen(httpbin.url + "/status/201")

    # Now, try to make three requests.  The first two should return the
    # correct status codes in order, and the third should raise an
    # exception.
    with vcr.use_cassette(str(tmpdir.join("test.json")), match_on=["method"]):
        assert urlopen(httpbin.url + "/status/200").getcode() == 200
        assert urlopen(httpbin.url + "/status/201").getcode() == 201
        with pytest.raises(CannotOverwriteExistingCassetteException):
            urlopen(httpbin.url + "/status/200")