File: conftest.py

package info (click to toggle)
python-openapi-core 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,008 kB
  • sloc: python: 18,868; makefile: 47
file content (90 lines) | stat: -rw-r--r-- 2,332 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from base64 import b64decode
from os import path
from urllib import request

import pytest
from jsonschema_path import SchemaPath
from openapi_spec_validator.readers import read_from_filename
from yaml import safe_load

from openapi_core import Spec


def content_from_file(spec_file):
    directory = path.abspath(path.dirname(__file__))
    path_full = path.join(directory, spec_file)
    return read_from_filename(path_full)


def schema_path_from_file(spec_file):
    spec_dict, base_uri = content_from_file(spec_file)
    return SchemaPath.from_dict(spec_dict, base_uri=base_uri)


def schema_path_from_url(base_uri):
    content = request.urlopen(base_uri)
    spec_dict = safe_load(content)
    return SchemaPath.from_dict(spec_dict, base_uri=base_uri)


def spec_from_file(spec_file):
    schema_path = schema_path_from_file(spec_file)
    return Spec(schema_path)


def spec_from_url(base_uri):
    schema_path = schema_path_from_url(base_uri)
    return Spec(schema_path)


@pytest.fixture(scope="session")
def data_gif():
    return b64decode(
        """
R0lGODlhEAAQAMQAAO3t7eHh4srKyvz8/P5pDP9rENLS0v/28P/17tXV1dHEvPDw8M3Nzfn5+d3d
3f5jA97Syvnv6MfLzcfHx/1mCPx4Kc/S1Pf189C+tP+xgv/k1N3OxfHy9NLV1/39/f///yH5BAAA
AAAALAAAAAAQABAAAAVq4CeOZGme6KhlSDoexdO6H0IUR+otwUYRkMDCUwIYJhLFTyGZJACAwQcg
EAQ4kVuEE2AIGAOPQQAQwXCfS8KQGAwMjIYIUSi03B7iJ+AcnmclHg4TAh0QDzIpCw4WGBUZeikD
Fzk0lpcjIQA7
"""
    )


class Factory(dict):
    __getattr__ = dict.__getitem__
    __setattr__ = dict.__setitem__


@pytest.fixture(scope="session")
def content_factory():
    return Factory(
        from_file=content_from_file,
    )


@pytest.fixture(scope="session")
def schema_path_factory():
    return Factory(
        from_file=schema_path_from_file,
        from_url=schema_path_from_url,
    )


@pytest.fixture(scope="session")
def spec_factory(schema_path_factory):
    return Factory(
        from_file=spec_from_file,
        from_url=spec_from_url,
    )


@pytest.fixture(scope="session")
def v30_petstore_content(content_factory):
    content, _ = content_factory.from_file("data/v3.0/petstore.yaml")
    return content


@pytest.fixture(scope="session")
def v30_petstore_spec(v30_petstore_content):
    base_uri = "file://tests/integration/data/v3.0/petstore.yaml"
    return SchemaPath.from_dict(v30_petstore_content, base_uri=base_uri)