Пример #1
0
 def test_connect_error(self, conn_mock):
     response = Mock(status=404)
     conn_mock.return_value.getresponse.return_value = response
     conn = nw.HTTPThread(Mock(), 0)
     info = conn.connect()
     self.assertIsInstance(info, ti.TaskHeadError)
     self.assertEqual(info.status, 404)
Пример #2
0
 def test_connect_redirect(self, conn_mock):
     response = Mock(status=301)
     response.getheader.return_value = 'http://server.com'
     conn_mock.return_value.getresponse.return_value = response
     conn = nw.HTTPThread(Mock(), 0)
     info = conn.connect()
     self.assertIsInstance(info, ti.TaskRedirect)
     self.assertEqual(info.location.url, 'http://server.com')
Пример #3
0
 def test_connect_ok(self, conn_mock):
     response = Mock(status=200)
     response.getheader.return_value = '100'
     conn_mock.return_value.getresponse.return_value = response
     conn = nw.HTTPThread(Mock(), 0)
     info = conn.connect()
     self.assertIsInstance(info, ti.TaskHeadData)
     self.assertEqual(info.file_size, 100)
Пример #4
0
 def test_redirect_absolute(self):
     url = Mock()
     url.protocol = 'http'
     url.host = 'server.com'
     conn = nw.HTTPThread(url, 0)
     info = conn.redirect('/path/to/file', 301)
     self.assertIsInstance(info, ti.TaskRedirect)
     self.assertEqual(info.location.url, 'http://server.com/path/to/file')
Пример #5
0
 def test_run_ok(self):
     task_info = Mock()
     conn = nw.HTTPThread(Mock(), 0)
     conn.data_queue = Mock()
     conn.connect = Mock(return_value=task_info)
     self.assertFalse(conn.ready.is_set())
     conn.run()
     conn.data_queue.put.assert_called_with(task_info)
     self.assertTrue(conn.ready.is_set())
Пример #6
0
 def test_run_error(self):
     conn = nw.HTTPThread(Mock(), 0)
     conn.data_queue = Mock()
     conn.connect = Mock(side_effect=Exception)
     self.assertFalse(conn.ready.is_set())
     conn.run()
     args = conn.data_queue.put.call_args
     self.assertIsInstance(args[0][0], ti.TaskHeadError)
     self.assertTrue(conn.ready.is_set())
Пример #7
0
 def test_redirect_with_host(self):
     location = 'http://server.com/path/to/file'
     conn = nw.HTTPThread(Mock(), 0)
     info = conn.redirect(location, 301)
     self.assertIsInstance(info, ti.TaskRedirect)
     self.assertEqual(info.location.url, location)