Files
zulip/zerver/tests/test_internet.py
Anders Kaseorg 365fe0b3d5 python: Sort imports with isort.
Fixes #2665.

Regenerated by tabbott with `lint --fix` after a rebase and change in
parameters.

Note from tabbott: In a few cases, this converts technical debt in the
form of unsorted imports into different technical debt in the form of
our largest files having very long, ugly import sequences at the
start.  I expect this change will increase pressure for us to split
those files, which isn't a bad thing.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-11 16:45:32 -07:00

22 lines
912 B
Python

import requests
import responses
from zerver.lib.test_classes import ZulipTestCase
class ResponsesTest(ZulipTestCase):
def test_responses(self) -> None:
# With our test setup, accessing the internet should be blocked.
with self.assertRaises(Exception):
result = requests.request('GET', 'https://www.google.com')
# A test can invoke its own responses.RequestsMock context manager
# and register URLs to mock, accessible from within the context.
with responses.RequestsMock() as requests_mock:
requests_mock.add(responses.GET, 'https://www.google.com',
body='{}', status=200,
content_type='application/json')
result = requests.request('GET', 'https://www.google.com')
self.assertEqual(result.status_code, 200)
self.assertEqual(result.text, '{}')