forked from bkircher/intro-python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_echo.py
More file actions
Latest commit
36 lines (25 loc) · 1.04 KB
/
Copy pathtest_echo.py
File metadata and controls
36 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
importunittest
fromunittest.mockimportpatch, MagicMock
importasyncio
fromechoimportfetch_content_sync, fetch_content_async
classTestMain(unittest.TestCase):
@patch('requests.get')
deftest_fetch_content_sync(self, mock_get):
mock_response=MagicMock()
mock_response.text="# Mocked Markdown Response"
mock_get.return_value=mock_response
url="https://example.com"
response=fetch_content_sync(url)
mock_get.assert_called_with(url)
self.assertEqual(response.text, "# Mocked Markdown Response")
@patch('requests.get')
deftest_fetch_content_async(self, mock_get):
mock_response=MagicMock()
mock_response.text="# Mocked Async Markdown Response"
mock_get.return_value=mock_response
url="https://example.com"
response=asyncio.run(fetch_content_async(url))
mock_get.assert_called_with(url)
self.assertEqual(response.text, "# Mocked Async Markdown Response")
if__name__=='__main__':
unittest.main()