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 = FlickrExporter("http://192.168.99.100:8081/",
                                    self.working_path,
                                    warc_base_path=self.warc_base_path)
     self.exporter.routing_key = "export.request.flickr.flickr_user"
     self.export_path = tempfile.mkdtemp()
 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 = FlickrExporter("http://192.168.99.100:8081/", self.working_path,
                                    warc_base_path=self.warc_base_path)
     self.exporter.routing_key = "export.request.flickr.flickr_user"
     self.export_path = tempfile.mkdtemp()
class TestFlickrExporter(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 = FlickrExporter("http://192.168.99.100:8081/", self.working_path,
                                       warc_base_path=self.warc_base_path)
        self.exporter.routing_key = "export.request.flickr.flickr_user"
        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": "flickr_user",
            "collection": {
                "id": "005b131f5f854402afa2b08a4b7ba960"
            },
            "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(33, len(lines))

    @vcr.use_cassette()
    def test_export_seeds(self):
        export_message = {
            "id": "test5",
            "type": "flickr_user",
            "seeds": [
                {
                    "id": "48722ac6154241f592fd74da775b7ab7",
                    "uid": "23972344@N05"
                },
                {
                    "id": "3ce76759a3ee40b894562a35359dfa54",
                    "uid": "85779209@N08"
                }
            ],
            "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, "test5_001.csv")
        self.assertTrue(os.path.exists(csv_filepath))
        with open(csv_filepath, "r") as f:
            lines = f.readlines()
        self.assertEqual(50, len(lines))
class TestFlickrExporter(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 = FlickrExporter("http://192.168.99.100:8081/",
                                       self.working_path,
                                       warc_base_path=self.warc_base_path)
        self.exporter.routing_key = "export.request.flickr.flickr_user"
        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": "flickr_user",
            "collection": {
                "id": "005b131f5f854402afa2b08a4b7ba960"
            },
            "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(33, len(lines))

    @vcr.use_cassette()
    def test_export_seeds(self):
        export_message = {
            "id":
            "test5",
            "type":
            "flickr_user",
            "seeds": [{
                "id": "48722ac6154241f592fd74da775b7ab7",
                "uid": "23972344@N05"
            }, {
                "id": "3ce76759a3ee40b894562a35359dfa54",
                "uid": "85779209@N08"
            }],
            "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, "test5_001.csv")
        self.assertTrue(os.path.exists(csv_filepath))
        with open(csv_filepath, "r") as f:
            lines = f.readlines()
        self.assertEqual(50, len(lines))