-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from dlieu/pipeline
Pipeline
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |