Exemple #1
0
    def get_writer(self, work):
        """ Create an appropriate writer object based on the response format """
        if work["response_format"] == "tar":
            return tar_writer.TarWriter(self.config, self.c_task,
                                        work["upload_url"])

        # By default we support the JSON Writer
        return json_writer.JSONWriter(self.config, self.c_task)
def test_cleanup():
    """ Test Cleanup """
    c_task = SimpleCatalogTask()
    dirname, tgzfile = prep_test()
    writer = tar_writer.TarWriter(TestData.config, c_task, TestData.UPLOAD_URL,
                                  dirname, tgzfile)
    writer.cleanup()
    assert not os.path.exists(dirname)
    assert not os.path.exists(tgzfile)
async def test_write():
    """ Test Write Method"""
    c_task = SimpleCatalogTask()
    dirname, tgzfile = prep_test()
    writer = tar_writer.TarWriter(TestData.no_verify_config, c_task,
                                  TestData.UPLOAD_URL, dirname, tgzfile)
    result = {"name": "Fred Flintstone"}
    await writer.write(json.dumps(result), "file1")
    assert os.path.exists(dirname + "/file1")
    writer.cleanup()
async def test_flush_errors():
    """ Test Flush Errors Method """
    c_task = SimpleCatalogTask()
    dirname, tgzfile = prep_test()
    writer = tar_writer.TarWriter(TestData.config, c_task, TestData.UPLOAD_URL,
                                  dirname, tgzfile)
    await writer.flush_errors("kaboom")
    writer.cleanup()

    assert (c_task.data["state"]) == "completed"
    assert (c_task.data["status"]) == "error"
async def test_flush():
    """ Test Flush Method """
    c_task = SimpleCatalogTask()
    writer = tar_writer.TarWriter(TestData.config, c_task, TestData.UPLOAD_URL)
    result = {"name": "Fred Flintstone"}
    await writer.write(json.dumps(result), "file1")
    with aioresponses() as mocked:
        mocked.post(TestData.UPLOAD_URL,
                    status=200,
                    body=json.dumps({"name": "Fred"}))
        await writer.flush()

    assert (c_task.data["state"]) == "completed"
    assert (c_task.data["status"]) == "ok"
    writer.cleanup()