Skip to content

Commit

Permalink
Merge pull request #132 from dlieu/pipeline
Browse files Browse the repository at this point in the history
Pipeline
  • Loading branch information
niall-byrne authored Nov 19, 2019
2 parents cd8b2c3 + 300040c commit 6f375c7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
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

0 comments on commit 6f375c7

Please sign in to comment.