Skip to content

Commit 01d760b

Browse files
authored
Merge pull request #327 from p1c2u/feature/more-schema-parameters-tests
More schema parameters tests
2 parents 6ccf3dd + a569a7f commit 01d760b

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import pytest
2+
3+
from openapi_core.schema.parameters import get_style, get_explode
4+
from openapi_core.spec.paths import SpecPath
5+
6+
7+
class TestGetStyle:
8+
9+
@pytest.mark.parametrize('location,expected', [
10+
('query', 'form'),
11+
('path', 'simple'),
12+
('header', 'simple'),
13+
('cookie', 'form'),
14+
])
15+
def test_defaults(self, location, expected):
16+
spec = {
17+
'name': 'default',
18+
'in': location,
19+
}
20+
param = SpecPath.from_spec(spec)
21+
result = get_style(param)
22+
23+
assert result == expected
24+
25+
@pytest.mark.parametrize('style,location', [
26+
('matrix', 'path'),
27+
('label', 'apth'),
28+
('form', 'query'),
29+
('form', 'cookie'),
30+
('simple', 'path'),
31+
('simple', 'header'),
32+
('spaceDelimited', 'query'),
33+
('pipeDelimited', 'query'),
34+
('deepObject', 'query'),
35+
])
36+
def test_defined(self, style, location):
37+
spec = {
38+
'name': 'default',
39+
'in': location,
40+
'style': style,
41+
}
42+
param = SpecPath.from_spec(spec)
43+
result = get_style(param)
44+
45+
assert result == style
46+
47+
48+
class TestGetExplode:
49+
50+
@pytest.mark.parametrize('style,location', [
51+
('matrix', 'path'),
52+
('label', 'path'),
53+
('simple', 'path'),
54+
('spaceDelimited', 'query'),
55+
('pipeDelimited', 'query'),
56+
('deepObject', 'query'),
57+
])
58+
def test_defaults_false(self, style, location):
59+
spec = {
60+
'name': 'default',
61+
'in': location,
62+
'style': style,
63+
}
64+
param = SpecPath.from_spec(spec)
65+
result = get_explode(param)
66+
67+
assert result is False
68+
69+
@pytest.mark.parametrize('location', ['query', 'cookie'])
70+
def test_defaults_true(self, location):
71+
spec = {
72+
'name': 'default',
73+
'in': location,
74+
'style': 'form',
75+
}
76+
param = SpecPath.from_spec(spec)
77+
result = get_explode(param)
78+
79+
assert result is True
80+
81+
@pytest.mark.parametrize('location', ['path', 'query', 'cookie', 'header'])
82+
@pytest.mark.parametrize('style', [
83+
'matrix', 'label', 'form', 'form', 'simple', 'spaceDelimited',
84+
'pipeDelimited', 'deepObject',
85+
])
86+
@pytest.mark.parametrize('schema_type', [
87+
'string', 'array' 'object',
88+
])
89+
@pytest.mark.parametrize('explode', [False, True])
90+
def test_defined(self, location, style, schema_type, explode):
91+
spec = {
92+
'name': 'default',
93+
'in': location,
94+
'explode': explode,
95+
'schema': {
96+
'type': schema_type,
97+
}
98+
}
99+
param = SpecPath.from_spec(spec)
100+
result = get_explode(param)
101+
102+
assert result == explode

0 commit comments

Comments
 (0)