File: test_register_matcher.py

package info (click to toggle)
python-azure 20230112%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 749,544 kB
  • sloc: python: 6,815,827; javascript: 287; makefile: 195; xml: 109; sh: 105
file content (36 lines) | stat: -rw-r--r-- 1,122 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import vcr
from six.moves.urllib.request import urlopen


def true_matcher(r1, r2):
    return True


def false_matcher(r1, r2):
    return False


def test_registered_true_matcher(tmpdir, httpbin):
    my_vcr = vcr.VCR()
    my_vcr.register_matcher("true", true_matcher)
    testfile = str(tmpdir.join("test.yml"))
    with my_vcr.use_cassette(testfile, match_on=["true"]):
        # These 2 different urls are stored as the same request
        urlopen(httpbin.url)
        urlopen(httpbin.url + "/get")

    with my_vcr.use_cassette(testfile, match_on=["true"]):
        # I can get the response twice even though I only asked for it once
        urlopen(httpbin.url + "/get")
        urlopen(httpbin.url + "/get")


def test_registered_false_matcher(tmpdir, httpbin):
    my_vcr = vcr.VCR()
    my_vcr.register_matcher("false", false_matcher)
    testfile = str(tmpdir.join("test.yml"))
    with my_vcr.use_cassette(testfile, match_on=["false"]) as cass:
        # These 2 different urls are stored as different requests
        urlopen(httpbin.url)
        urlopen(httpbin.url + "/get")
        assert len(cass) == 2