class WiringFastAPITest(AsyncTestCase):

    client: AsyncClient

    def setUp(self) -> None:
        super().setUp()
        self.client = AsyncClient(app=web.app, base_url='http://test')

    def tearDown(self) -> None:
        self._run(self.client.aclose())
        super().tearDown()

    def test_depends_marker_injection(self):
        class ServiceMock:
            async def process(self):
                return 'Foo'

        with web.container.service.override(ServiceMock()):
            response = self._run(self.client.get('/'))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(), {'result': 'Foo'})

    def test_depends_injection(self):
        response = self._run(self.client.get('/auth', auth=('john_smith', 'secret')))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(), {'username': '******', 'password': '******'})
Ejemplo n.º 2
0
def client(event_loop):
    client = AsyncClient(app=app, base_url='http://test')
    yield client
    event_loop.run_until_complete(client.aclose())