File: test_request_options.py

package info (click to toggle)
python-stripe 12.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,864 kB
  • sloc: python: 157,573; makefile: 13; sh: 9
file content (59 lines) | stat: -rw-r--r-- 2,224 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from stripe._request_options import (
    RequestOptions,
    merge_options,
    extract_options_from_dict,
)
from stripe._requestor_options import RequestorOptions


class TestRequestOptions(object):
    def test_merge(self):
        options = RequestorOptions(
            api_key="sk_test_123",
            stripe_account="acct_123",
            base_addresses={"api": "https://api.stripe.com"},
        )
        other: RequestOptions = {
            "api_key": "sk_test_456",
            "stripe_version": "2020-01-01",
            "headers": {"foo": "bar"},
        }
        merged = merge_options(options, other)
        assert merged.get("api_key") == "sk_test_456"
        assert merged.get("stripe_version") == "2020-01-01"
        assert merged.get("stripe_account") == "acct_123"
        assert merged.get("headers") == {"foo": "bar"}

    def test_merge_none(self):
        options = RequestorOptions(
            api_key="sk_test_123",
            stripe_account="acct_123",
            base_addresses={"api": "https://api.stripe.com"},
        )
        merged = merge_options(options, None)
        assert merged.get("api_key") == "sk_test_123"
        assert merged.get("stripe_version") is None
        assert merged.get("stripe_account") == "acct_123"
        assert merged.get("headers") is None

    def test_extract_from_dict(self):
        options, remaining = extract_options_from_dict(
            {
                "api_key": "sk_test_123",
                "stripe_version": "2020-01-01",
                "stripe_account": "acct_123",
                "stripe_context": "wksp_123",
                "idempotency_key": "idemp_123",
                "headers": {
                    "X-Stripe-Header": "Some-Value",
                },
                "foo": "bar",
            }
        )
        assert options.get("api_key") == "sk_test_123"
        assert options.get("stripe_version") == "2020-01-01"
        assert options.get("stripe_account") == "acct_123"
        assert options.get("stripe_context") == "wksp_123"
        assert options.get("idempotency_key") == "idemp_123"
        assert options.get("headers") == {"X-Stripe-Header": "Some-Value"}
        assert remaining == {"foo": "bar"}