Skip to content

Commit

Permalink
Moved empty view_cls to conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Apr 15, 2020
1 parent 9bd34e1 commit 5935f77
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
from apispec.ext.marshmallow import MarshmallowPlugin


@pytest.fixture
def view_cls():
class ViewClass:
def get(self):
pass

def post(self):
pass

def put(self):
pass

def delete(self):
pass

return ViewClass


@pytest.fixture
def spec():
return APISpec(
Expand Down
52 changes: 17 additions & 35 deletions tests/test_server_spec_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,45 @@
import pytest


@pytest.fixture
def view_class():
class ViewClass:
def get(self):
pass

def post(self):
pass

def put(self):
pass

def delete(self):
pass

return ViewClass


def test_initial_update_spec(view_class):
def test_initial_update_spec(view_cls):
initial_spec = {"key": "value"}
utilities.update_spec(view_class, initial_spec)
utilities.update_spec(view_cls, initial_spec)

assert view_class.__apispec__ == initial_spec
assert view_cls.__apispec__ == initial_spec


def test_update_spec(view_class):
def test_update_spec(view_cls):
initial_spec = {"key": {"subkey": "value"}}
utilities.update_spec(view_class, initial_spec)
utilities.update_spec(view_cls, initial_spec)

new_spec = {"key": {"new_subkey": "new_value"}}
utilities.update_spec(view_class, new_spec)
utilities.update_spec(view_cls, new_spec)

assert view_class.__apispec__ == {
assert view_cls.__apispec__ == {
"key": {"subkey": "value", "new_subkey": "new_value"}
}


def test_get_spec(view_class):
def test_get_spec(view_cls):
assert utilities.get_spec(None) == {}
assert utilities.get_spec(view_class) == {}
assert utilities.get_spec(view_cls) == {}

initial_spec = {"key": {"subkey": "value"}}
view_class.__apispec__ = initial_spec
view_cls.__apispec__ = initial_spec

assert utilities.get_spec(view_class) == initial_spec
assert utilities.get_spec(view_cls) == initial_spec


def test_get_topmost_spec_attr(view_class):
assert not utilities.get_topmost_spec_attr(view_class, "key")
def test_get_topmost_spec_attr(view_cls):
assert not utilities.get_topmost_spec_attr(view_cls, "key")

# Root value missing, fall back to GET
view_class.get.__apispec__ = {"key": "get_value"}
assert utilities.get_topmost_spec_attr(view_class, "key") == "get_value"
view_cls.get.__apispec__ = {"key": "get_value"}
assert utilities.get_topmost_spec_attr(view_cls, "key") == "get_value"

# Root value present, return root value
view_class.__apispec__ = {"key": "class_value"}
assert utilities.get_topmost_spec_attr(view_class, "key") == "class_value"
view_cls.__apispec__ = {"key": "class_value"}
assert utilities.get_topmost_spec_attr(view_cls, "key") == "class_value"


def test_convert_schema_none(spec):
Expand Down

0 comments on commit 5935f77

Please sign in to comment.