示例#1
0
    def test_file_body_upload_raw(self):

        config = AutoRestSwaggerBATFormDataServiceConfiguration(
            base_url="http://localhost:3000")
        config.log_level = log_level
        client = AutoRestSwaggerBATFormDataService(config)

        test_string = "Upload file test case"
        test_bytes = bytearray(test_string, encoding='utf-8')
        result = io.BytesIO()
        with io.BytesIO(test_bytes) as stream_data:
            resp = client.formdata.upload_file_via_body(
                stream_data, "UploadFile.txt")
            for r in resp:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), test_string)

        name = os.path.basename(self.dummy_file)
        result = io.BytesIO()
        with open(self.dummy_file, 'rb') as upload_data:
            resp = client.formdata.upload_file_via_body(upload_data,
                                                        name,
                                                        raw=True)
            for r in resp.output:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), "Test file")
示例#2
0
    def test_file_body_upload(self):

        test_string = "Upload file test case"
        test_bytes = bytearray(test_string, encoding='utf-8')

        def test_callback(data, response, progress = [0]):
            self.assertTrue(len(data) > 0)
            progress[0] += len(data)
            total = float(len(test_bytes))
            if response:
                print("Downloading... {}%".format(int(progress[0]*100/total)))
            else:
                print("Uploading... {}%".format(int(progress[0]*100/total)))

        config = AutoRestSwaggerBATFormDataServiceConfiguration(base_url="http://localhost:3000")
        config.log_level = log_level
        config.connection.data_block_size = 2
        client = AutoRestSwaggerBATFormDataService(config)
        
        result = io.BytesIO()
        with io.BytesIO(test_bytes) as stream_data:
            resp = client.formdata.upload_file_via_body(stream_data, "UploadFile.txt", callback=test_callback)
            for r in resp:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), test_string)

        name = os.path.basename(self.dummy_file)
        result = io.BytesIO()
        with open(self.dummy_file, 'rb') as upload_data:
            resp = client.formdata.upload_file_via_body(upload_data, name, callback=test_callback)
            for r in resp:
                print(r)
                result.write(r)
            self.assertEqual(result.getvalue().decode(), "Test file")
示例#3
0
    def test_file_body_upload(self):

        test_string = "Upload file test case"
        test_bytes = bytearray(test_string, encoding='utf-8')

        def test_callback(data, response, progress = [0]):
            self.assertTrue(len(data) > 0)
            progress[0] += len(data)
            total = float(len(test_bytes))
            if response:
                print("Downloading... {}%".format(int(progress[0]*100/total)))
            else:
                print("Uploading... {}%".format(int(progress[0]*100/total)))

        config = AutoRestSwaggerBATFormDataServiceConfiguration(base_url="http://localhost:3000")
        config.log_level = log_level
        config.connection.data_block_size = 2
        client = AutoRestSwaggerBATFormDataService(config)
        
        result = io.BytesIO()
        with io.BytesIO(test_bytes) as stream_data:
            resp = client.formdata.upload_file_via_body(stream_data, "UploadFile.txt", callback=test_callback)
            for r in resp:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), test_string)

        name = os.path.basename(self.dummy_file)
        result = io.BytesIO()
        with open(self.dummy_file, 'rb') as upload_data:
            resp = client.formdata.upload_file_via_body(upload_data, name, callback=test_callback)
            for r in resp:
                print(r)
                result.write(r)
            self.assertEqual(result.getvalue().decode(), "Test file")
示例#4
0
    def test_file_upload_file_stream_raw(self):

        def test_callback(data, response, progress = [0]):
            self.assertTrue(len(data) > 0)
            progress[0] += len(data)
            total = float(response.headers['Content-Length'])
            print("Progress... {}%".format(int(progress[0]*100/total)))
            self.assertIsNotNone(response)

        config = AutoRestSwaggerBATFormDataServiceConfiguration(base_url="http://localhost:3000")
        config.log_level = log_level
        config.connection.data_block_size = 2
        client = AutoRestSwaggerBATFormDataService(config)

        name = os.path.basename(self.dummy_file)
        result = io.BytesIO()
        with open(self.dummy_file, 'rb') as upload_data:
            resp = client.formdata.upload_file(upload_data, name, raw=True, callback=test_callback)
            for r in resp.output:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), "Test file")
示例#5
0
    def test_file_upload_file_stream_raw(self):

        def test_callback(data, response, progress = [0]):
            self.assertTrue(len(data) > 0)
            progress[0] += len(data)
            total = float(response.headers['Content-Length'])
            print("Progress... {}%".format(int(progress[0]*100/total)))
            self.assertIsNotNone(response)

        config = AutoRestSwaggerBATFormDataServiceConfiguration(base_url="http://localhost:3000")
        config.log_level = log_level
        config.connection.data_block_size = 2
        client = AutoRestSwaggerBATFormDataService(config)

        name = os.path.basename(self.dummy_file)
        result = io.BytesIO()
        with open(self.dummy_file, 'rb') as upload_data:
            resp = client.formdata.upload_file(upload_data, name, raw=True, callback=test_callback)
            for r in resp.output:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), "Test file")
示例#6
0
    def test_file_body_upload_raw(self):

        config = AutoRestSwaggerBATFormDataServiceConfiguration(base_url="http://localhost:3000")
        config.log_level = log_level
        client = AutoRestSwaggerBATFormDataService(config)

        test_string = "Upload file test case"
        test_bytes = bytearray(test_string, encoding='utf-8')
        result = io.BytesIO()
        with io.BytesIO(test_bytes) as stream_data:
            resp = client.formdata.upload_file_via_body(stream_data)
            for r in resp:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), test_string)

        result = io.BytesIO()
        with open(self.dummy_file, 'rb') as upload_data:
            resp = client.formdata.upload_file_via_body(upload_data, raw=True)
            for r in resp.output:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), "Test file")
示例#7
0
    def test_file_upload_stream_raw(self):

        def test_callback(data, response, progress = [0]):
            self.assertTrue(len(data) > 0)
            progress[0] += len(data)
            total = float(response.headers['Content-Length'])
            print("Progress... {}%".format(int(progress[0]*100/total)))
            self.assertIsNotNone(response)

        config = AutoRestSwaggerBATFormDataServiceConfiguration(base_url="http://localhost:3000")
        config.log_level = log_level
        config.connection.data_block_size = 2
        client = AutoRestSwaggerBATFormDataService(config)

        test_string = "Upload file test case"
        test_bytes = bytearray(test_string, encoding='utf-8')
        result = io.BytesIO()
        with io.BytesIO(test_bytes) as stream_data:
            resp = client.formdata.upload_file(stream_data, "UploadFile.txt", raw=True)
            for r in resp.output:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), test_string)
示例#8
0
    def test_file_upload_stream_raw(self):

        def test_callback(data, response, progress = [0]):
            self.assertTrue(len(data) > 0)
            progress[0] += len(data)
            total = float(response.headers['Content-Length'])
            print("Progress... {}%".format(int(progress[0]*100/total)))
            self.assertIsNotNone(response)

        config = AutoRestSwaggerBATFormDataServiceConfiguration(base_url="http://localhost:3000")
        config.log_level = log_level
        config.connection.data_block_size = 2
        client = AutoRestSwaggerBATFormDataService(config)

        test_string = "Upload file test case"
        test_bytes = bytearray(test_string, encoding='utf-8')
        result = io.BytesIO()
        with io.BytesIO(test_bytes) as stream_data:
            resp = client.formdata.upload_file(stream_data, "UploadFile.txt", raw=True)
            for r in resp.output:
                result.write(r)
            self.assertEqual(result.getvalue().decode(), test_string)