File: test_base.py

package info (click to toggle)
python-flasgger 0.9.5%2Bdfsg.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,152 kB
  • sloc: javascript: 6,403; python: 3,665; makefile: 9; sh: 1
file content (52 lines) | stat: -rw-r--r-- 1,613 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
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
import pytest
from flasgger.base import Swagger


def test_init_config(monkeypatch):

    def __init__(self, config=None, merge=False):
        self._init_config(config, merge)

    monkeypatch.setattr(Swagger, "__init__", __init__)

    # # Unspecified config will be initialized to dict()
    t = Swagger(config=None, merge=False)
    assert t.config == Swagger.DEFAULT_CONFIG

    # Empty dict passed to arguments will be overriden with default_config
    empty_dict = dict()
    t = Swagger(config=empty_dict, merge=False)
    assert t.config == Swagger.DEFAULT_CONFIG
    assert t.config is not empty_dict

    # Config will be merged
    d = {"a": 0}
    t = Swagger(config=d, merge=False)
    assert t.config is d

    # Config will be overridden
    t = Swagger(config={"a": 0}, merge=False)
    assert t.config == {"a": 0}

    # Config will be merged
    t = Swagger(config={"a": 0}, merge=True)
    assert t.config.items() > {"a": 0}.items()
    assert all( t.config[k] == v for k, v in Swagger.DEFAULT_CONFIG.items() )

    # Config will be merged
    empty_dict = dict()
    t = Swagger(config=empty_dict, merge=True)
    assert t.config == Swagger.DEFAULT_CONFIG

    # keys in DEFAULT_CONFIG will be overridden
    d = {"specs": [
        {
            "endpoint": "swagger",
            "route": "/characteristics/swagger.json",
            "rule_filter": lambda rule: True,  # all in
            "model_filter": lambda tag: True,  # all in
        }
    ],}
    t = Swagger(config=d, merge=True)
    assert all( t.config[k] == v for k, v in d.items() )
    assert t.config["specs"] == d["specs"]