class TestTaskDB(unittest.TestCase): sample_task_http = { 'taskid': 'taskid', 'project': 'project', 'url': 'http://httpbin.org/get', 'fetch': { 'method': 'GET', 'headers': { 'Cookie': 'a=b', 'a': 'b' }, 'timeout': 60, 'save': 'abc', }, 'process': { 'callback': 'callback', 'save': [1, 2, 3], }, } def setUp(self): self.fetcher = Fetcher(None, None) self.thread = utils.run_in_thread(self.fetcher.run) def tearDown(self): self.fetcher.quit() self.thread.join() def test_http_get(self): result = self.fetcher.sync_fetch(self.sample_task_http) self.assertEqual(result['status_code'], 200) self.assertEqual(result['orig_url'], self.sample_task_http['url']) self.assertEqual(result['save'], self.sample_task_http['fetch']['save']) self.assertIn('content', result) content = json.loads(result['content']) self.assertIn('headers', content) self.assertIn('A', content['headers']) self.assertIn('Cookie', content['headers']) self.assertEqual(content['headers']['Cookie'], 'a=b') def test_dataurl_get(self): data = dict(self.sample_task_http) data['url'] = 'data:,hello' result = self.fetcher.sync_fetch(data) self.assertEqual(result['status_code'], 200) self.assertIn('content', result) self.assertEqual(result['content'], 'hello')
class TestTaskDB(unittest.TestCase): sample_task_http = { 'taskid': 'taskid', 'project': 'project', 'url': 'http://httpbin.org/get', 'fetch': { 'method': 'GET', 'headers': { 'Cookie': 'a=b', 'a': 'b' }, 'timeout': 60, 'save': 'abc', }, 'process': { 'callback': 'callback', 'save': [1, 2, 3], }, } def setUp(self): self.fetcher = Fetcher(None, None) self.thread = utils.run_in_thread(self.fetcher.run) def tearDown(self): self.fetcher.quit() self.thread.join() def test_http_get(self): result = self.fetcher.sync_fetch(self.sample_task_http) self.assertEqual(result['status_code'], 200) self.assertEqual(result['orig_url'], self.sample_task_http['url']) self.assertEqual(result['save'], self.sample_task_http['fetch']['save']) self.assertIn('content', result) content = json.loads(result['content']) self.assertIn('headers', content) self.assertIn('A', content['headers']) self.assertIn('Cookie', content['headers']) self.assertEqual(content['headers']['Cookie'], 'a=b') def test_dataurl_get(self): data = dict(self.sample_task_http) data['url'] = 'data:,hello'; result = self.fetcher.sync_fetch(data) self.assertEqual(result['status_code'], 200) self.assertIn('content', result) self.assertEqual(result['content'], 'hello')
class TestTaskDB(unittest.TestCase): sample_task_http = { 'taskid': 'taskid', 'project': 'project', 'url': 'http://httpbin.org/get', 'fetch': { 'method': 'GET', 'headers': { 'Cookie': 'a=b', 'a': 'b' }, 'data': 'a=b&c=d', 'timeout': 60, }, 'process': { 'callback': 'callback', 'save': [1, 2, 3], }, } def setUp(self): self.fetcher = Fetcher(None, None) self.thread = threading.Thread(target=self.fetcher.run) self.thread.daemon = True self.thread.start() def tearDown(self): self.fetcher.quit() self.thread.join() def test_http_get(self): result = self.fetcher.sync_fetch(self.sample_task_http) self.assertEqual(result['status_code'], 200) self.assertEqual(result['orig_url'], self.sample_task_http['url']) self.assertIn('content', result) content = json.loads(result['content']) self.assertIn('headers', content) self.assertIn('A', content['headers']) self.assertIn('Cookie', content['headers']) self.assertEqual(content['headers']['Cookie'], 'a=b')
class TestTaskDB(unittest.TestCase): sample_task_http = { 'taskid': 'taskid', 'project': 'project', 'url': 'http://httpbin.org/get', 'fetch': { 'method': 'GET', 'headers': { 'Cookie': 'a=b', 'a': 'b' }, 'data': 'a=b&c=d', 'timeout': 60, }, 'process': { 'callback': 'callback', 'save': [1, 2, 3], }, } def setUp(self): self.fetcher = Fetcher(None, None) self.thread = threading.Thread(target=self.fetcher.run) self.thread.daemon = True self.thread.start() def tearDown(self): self.fetcher.quit() self.thread.join() def test_http_get(self): result = self.fetcher.sync_fetch(self.sample_task_http) self.assertEqual(result['status_code'], 200) self.assertEqual(result['orig_url'], self.sample_task_http['url']) self.assertIn('content', result) content = json.loads(result['content']) self.assertIn('headers', content) self.assertIn('A', content['headers']) self.assertIn('Cookie', content['headers']) self.assertEqual(content['headers']['Cookie'], 'a=b')