Coverage for tests\request\test_request_chain.py: 100%

1 import unittest

2 from unittest import mock

3 import httpx

4

5 from zapy.test import AssertTestResultMixin

6 from zapy.utils import module

7 from pathlib import Path

8

9

10 class TestScript(unittest.IsolatedAsyncioTestCase, AssertTestResultMixin):

11

12 @mock.patch.object(

13 httpx.AsyncClient, 'send',

14 return_value = httpx.Response(200, json={'id': 'test-id'})

15 )

16 async def test_chain_success(self, mock_request):

17 chain = await module.load_ipynb('tests/assets/chain.ipynb')

18 self.assertEqual({'id': 'test-id'}, chain.out_response)

19

20 @mock.patch.object(

21 httpx.AsyncClient, 'send',

22 return_value = httpx.Response(200, json={'id': 'test-id'})

23 )

24 async def test_chain_error(self, mock_request):

25 with self.assertRaises(AssertionError) as ex:

26 chain = await module.load_ipynb('tests/assets/chain_asserterror.ipynb')

27

28 self.assertIn("AssertionError: 'FOO' != 'will raise an error'", str(ex.exception))

29

30 @mock.patch.object(

31 httpx.AsyncClient, 'send',

32 return_value = httpx.Response(200, json={'id': 'test-id'})

33 )

34 async def test_chain_success_import(self, mock_request):

35 rel_path = Path('tests/assets')

36 chain = await module.load_ipynb(rel_path / 'chain_import.ipynb', variables={

37 'rel_path': rel_path

38 })