class TestWeiboExporterVcr(tests.TestCase): def setUp(self): self.warc_base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "warcs") self.working_path = tempfile.mkdtemp() self.exporter = WeiboExporter("http://127.0.0.1:8080", self.working_path, warc_base_path=self.warc_base_path) self.exporter.routing_key = "export.request.weibo.weibo_timeline" self.export_path = tempfile.mkdtemp() def tearDown(self): if os.path.exists(self.export_path): shutil.rmtree(self.export_path) if os.path.exists(self.working_path): shutil.rmtree(self.working_path) @vcr.use_cassette() def test_export_collection(self): export_message = { "id": "test1", "type": "weibo_timeline", "collection": { "id": "afe49fc673ab4380909e06f43b46a990" }, "format": "csv", "segment_size": None, "path": self.export_path } self.exporter.message = export_message self.exporter.on_message() self.assertTrue(self.exporter.result.success) csv_filepath = os.path.join(self.export_path, "test1_001.csv") self.assertTrue(os.path.exists(csv_filepath)) with open(csv_filepath, "r") as f: lines = f.readlines() self.assertEqual(182, len(lines))
class TestWeiboExporterVcr(tests.TestCase): def setUp(self): self.warc_base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "warcs") self.working_path = tempfile.mkdtemp() self.exporter = WeiboExporter("http://127.0.0.1:8080", self.working_path, warc_base_path=self.warc_base_path) self.exporter.routing_key = "export.request.weibo.weibo_timeline" self.export_path = tempfile.mkdtemp() def tearDown(self): if os.path.exists(self.export_path): shutil.rmtree(self.export_path) if os.path.exists(self.working_path): shutil.rmtree((self.working_path)) @vcr.use_cassette() def test_export_collection(self): export_message = { "id": "test1", "type": "weibo_timeline", "collection": { "id": "afe49fc673ab4380909e06f43b46a990" }, "format": "csv", "segment_size": None, "path": self.export_path } self.exporter.message = export_message self.exporter.on_message() self.assertTrue(self.exporter.result.success) csv_filepath = os.path.join(self.export_path, "test1_001.csv") self.assertTrue(os.path.exists(csv_filepath)) with open(csv_filepath, "r") as f: lines = f.readlines() self.assertEqual(182, len(lines))
def setUp(self): self.warc_base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "warcs") self.working_path = tempfile.mkdtemp() self.exporter = WeiboExporter("http://127.0.0.1:8080", self.working_path, warc_base_path=self.warc_base_path) self.exporter.routing_key = "export.request.weibo.weibo_timeline" self.export_path = tempfile.mkdtemp()