Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline #132

Merged
merged 5 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import datetime
from unittest.mock import patch

import pytest

from flask_restful_swagger import swagger


class TestEmptyClass:
pass


@pytest.mark.parametrize(
"test_input",
[
TestEmptyClass, # Test a class
"im a str", # Test a str
123, # Test int
None, # Test None
datetime.datetime.now(), # Test datetime
],
)
def test_model_with_input(test_input):
with patch("flask_restful_swagger.swagger.add_model") as mock_add_model:
assert swagger.model(test_input) == test_input
mock_add_model.assert_called_once_with(test_input)
33 changes: 33 additions & 0 deletions tests/test_operation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from flask_restful_swagger import swagger


def empty_func():
pass


def func_with_many_args(arg1, arg2, arg3, kwarg1=None, kwarg2=None):
allargs = (arg1, arg2, arg3, kwarg1, kwarg2)
print("func_with_many_args: %s, %s, %s, %s, %s" % allargs)


class EmptyClass:
pass


@pytest.mark.parametrize(
"plain_input,swagger_kwargs",
[
(empty_func, {"arg1": None, "arg2": None}),
(func_with_many_args, {"arg1": None, "arg2": None}),
(EmptyClass, {"arg1": None}),
(EmptyClass(), {"arg1": None}),
],
)
def test_operation(plain_input, swagger_kwargs):
_add_swagger_attr_wrapper = swagger.operation(**swagger_kwargs)
swaggered_input = _add_swagger_attr_wrapper(plain_input)

assert hasattr(swaggered_input, "__swagger_attr")
assert swaggered_input.__swagger_attr == swagger_kwargs