Skip to content

Commit

Permalink
add parameters for test_schema_with_refs
Browse files Browse the repository at this point in the history
test name change 
test for key error
  • Loading branch information
Kilo59 committed Jul 4, 2020
1 parent b7af1de commit 50378db
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions tests/test_schema.py
Expand Up @@ -1087,7 +1087,17 @@ class Pizza(BaseModel):
}


def test_schema_with_ref_prefix():
@pytest.mark.parametrize(
'ref_prefix,ref_template',
[
# OpenAPI style
('#/components/schemas/', None),
(None, '#/components/schemas/{model}'),
# ref_prefix takes priority
('#/components/schemas/', '#/{model}/schemas/')
],
)
def test_schema_with_refs(ref_prefix, ref_template):
class Foo(BaseModel):
a: str

Expand All @@ -1097,7 +1107,7 @@ class Bar(BaseModel):
class Baz(BaseModel):
c: Bar

model_schema = schema([Bar, Baz], ref_prefix='#/components/schemas/') # OpenAPI style
model_schema = schema([Bar, Baz], ref_prefix=ref_prefix, ref_template=ref_template)
assert model_schema == {
'definitions': {
'Baz': {
Expand All @@ -1122,7 +1132,7 @@ class Baz(BaseModel):
}


def test_schema_with_ref_template():
def test_schema_with_custom_ref_template():
class Foo(BaseModel):
a: str

Expand Down Expand Up @@ -1157,6 +1167,20 @@ class Baz(BaseModel):
}


def test_schema_ref_template_key_error():
class Foo(BaseModel):
a: str

class Bar(BaseModel):
b: Foo

class Baz(BaseModel):
c: Bar

with pytest.raises(KeyError):
schema([Bar, Baz], ref_template='/schemas/{bad_name}.json#/')


def test_schema_no_definitions():
model_schema = schema([], title='Schema without definitions')
assert model_schema == {'title': 'Schema without definitions'}
Expand Down

0 comments on commit 50378db

Please sign in to comment.