|
| 1 | +from unittest.mock import MagicMock |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
3 | 5 | from sqlalchemy_bind_manager.exceptions import RepositoryNotFound |
@@ -31,3 +33,54 @@ async def test_raises_exception_if_repository_not_found(sa_bind, uow_class): |
31 | 33 | uow = uow_class(bind=sa_bind) |
32 | 34 | with pytest.raises(RepositoryNotFound): |
33 | 35 | uow.repository("Not existing") |
| 36 | + |
| 37 | + |
| 38 | +@pytest.mark.parametrize( |
| 39 | + ["submitted_args", "submitted_kwargs", "received_args", "received_kwargs"], |
| 40 | + [ |
| 41 | + pytest.param( |
| 42 | + ("1", "2"), |
| 43 | + dict(a="b"), |
| 44 | + ("2",), |
| 45 | + dict(model_class="1", a="b"), |
| 46 | + id="first_arg_model_class_if_no_kwarg", |
| 47 | + ), |
| 48 | + pytest.param( |
| 49 | + tuple([]), |
| 50 | + dict(a="b", model_class="c"), |
| 51 | + tuple([]), |
| 52 | + dict(model_class="c", a="b"), |
| 53 | + id="model_class_rearranged_if_in_kwargs", |
| 54 | + ), |
| 55 | + pytest.param( |
| 56 | + tuple([]), |
| 57 | + dict(a="b"), |
| 58 | + tuple([]), |
| 59 | + dict(model_class=None, a="b"), |
| 60 | + id="model_class_default_to_none", |
| 61 | + ), |
| 62 | + pytest.param( |
| 63 | + tuple([]), |
| 64 | + dict(a="b", session="c"), |
| 65 | + tuple([]), |
| 66 | + dict(model_class=None, a="b"), |
| 67 | + id="session_removed_from_kwargs", |
| 68 | + ), |
| 69 | + ], |
| 70 | +) |
| 71 | +async def test_additional_arguments_are_forwarded( |
| 72 | + sa_bind, |
| 73 | + uow_class, |
| 74 | + submitted_args: tuple, |
| 75 | + submitted_kwargs: dict, |
| 76 | + received_args: tuple, |
| 77 | + received_kwargs: dict, |
| 78 | +): |
| 79 | + repo = MagicMock() |
| 80 | + |
| 81 | + uow = uow_class(bind=sa_bind) |
| 82 | + uow.register_repository("r", repo, *submitted_args, **submitted_kwargs) |
| 83 | + |
| 84 | + repo.assert_called_once_with( |
| 85 | + *received_args, session=uow._session_handler.scoped_session(), **received_kwargs |
| 86 | + ) |
0 commit comments