Example #1
0
 def test_http_error(self):
     for error_code in range(400, 600):  # TODO: this range is excessive
         with self.subTest(i=error_code):
             buffer = io.BytesIO()
             with self.assertRaises(HTTPError):
                 download(f'{self.endpoint}/error/{error_code}', buffer, 10, False)
             # nothing downloaded
             self.assertEqual(0, len(buffer.getbuffer()))
Example #2
0
 def test_illegal_url_error(self):
     illegal_urls = [
         ('wrong scheme', 'ftp://localhost:21/some/file'),
         ('empty url', ''),
         ('newline', '\n'),
         ('whitespace', '\t '),
         ('emojus', '🐵 🙈 🙉 🙊'),
         ('missing protocol', 'localhost:21/some/file'),
     ]
     for (desc, url) in illegal_urls:
         with self.subTest(i=desc):
             buffer = io.BytesIO()
             with self.assertRaises(RequestException):
                 download(url, buffer, 10, False)
Example #3
0
 def test_read_timeout_error(self):
     buffer = io.BytesIO()
     with self.assertRaises(Timeout):
         download(f'{self.endpoint}/sleep/{2}', buffer, 1, False)
     # nothing downloaded
     self.assertEqual(0, len(buffer.getbuffer()))
Example #4
0
 def test_simple_download_ok(self):
     num_bytes = 1024
     buffer = io.BytesIO()
     download(f'{self.endpoint}/content/{num_bytes}', buffer, 10, False)
     # read content and assert it contains exactly num_bytes
     self.assertEqual(num_bytes, len(buffer.getbuffer()))
Example #5
0
 def test_not_verify_ok(self):
     for url in self.bad_urls:
         with self.subTest(i=url):
             buffer = io.BytesIO()
             download(url, buffer, 10, False)
Example #6
0
 def test_verify_raises(self):
     for url in self.bad_urls:
         with self.subTest(i=url):
             buffer = io.BytesIO()
             with self.assertRaises(SSLError):
                 download(url, buffer, 10, True)
Example #7
0
 def test_connection_error(self):
     buffer = io.BytesIO()
     with self.assertRaises(ConnectionError):
         download(f'http://localhost:1/something', buffer, 10, False)
     # nothing downloaded
     self.assertEqual(0, len(buffer.getbuffer()))