#!/usr/bin/env python3

from unittest import main, mock, IsolatedAsyncioTestCase

from async_lib import aget_user

__all__ = ("GetUserQuerySetTestCase",)


class GetUserQuerySetTestCase(IsolatedAsyncioTestCase):

    async def test_aget_user_with_select_for_update_mock(self):
        get_user_queryset_mock = mock.Mock()
        get_user_queryset_mock.select_for_update.return_value = mock.Mock()
        get_user_queryset_mock.select_for_update.return_value.aget = mock.AsyncMock()

        await self._test_aget_user_with_select_for_update(get_user_queryset_mock)

    async def test_aget_user_with_select_for_update_magic_mock(self):
        await self._test_aget_user_with_select_for_update(mock.MagicMock())

    async def _test_aget_user_with_select_for_update(self, mock_):
        with mock.patch(
            "async_lib.get_user_queryset",
            return_value=mock_,
        ):
            await aget_user(1, select_for_update=True)
            mock_.select_for_update.assert_called_once_with(foo=True)


if __name__ == "__main__":
    main()
