Ejemplo n.º 1
0
    def test_create_file_from_bytes_with_progress(self):
        # parallel tests introduce random order of requests, can only run live
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        file_name = self._get_file_reference()
        data = self.get_random_bytes(LARGE_FILE_SIZE)
        file_client = FileClient(
            self.get_file_url(),
            share=self.share_name,
            file_path=file_name,
            credential=self.settings.STORAGE_ACCOUNT_KEY)

        # Act
        progress = []
        def callback(response):
            current = response.context['upload_stream_current']
            total = response.context['data_stream_total']
            if current is not None:
                progress.append((current, total))

        file_client.upload_file(data, max_connections=2, raw_response_hook=callback)

        # Assert
        self.assertFileEqual(file_client, data)
Ejemplo n.º 2
0
    def test_create_file_from_path_with_progress(self):
        # parallel tests introduce random order of requests, can only run live
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange        
        file_name = self._get_file_reference()
        data = self.get_random_bytes(LARGE_FILE_SIZE)
        with open(INPUT_FILE_PATH, 'wb') as stream:
            stream.write(data)
        file_client = FileClient(
            self.get_file_url(),
            share=self.share_name,
            file_path=file_name,
            credential=self.settings.STORAGE_ACCOUNT_KEY,
            max_range_size=4 * 1024)

        # Act
        progress = []
        def callback(response):
            current = response.context['upload_stream_current']
            total = response.context['data_stream_total']
            if current is not None:
                progress.append((current, total))

        with open(INPUT_FILE_PATH, 'rb') as stream:
            file_client.upload_file(stream, max_connections=2, raw_response_hook=callback)

        # Assert
        self.assertFileEqual(file_client, data)
        self.assert_upload_progress(
            len(data),
            self.fsc._config.max_range_size,
            progress, unknown_size=False)
Ejemplo n.º 3
0
    def test_create_file_from_stream_non_seekable(self):
        # parallel tests introduce random order of requests, can only run live
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        file_name = self._get_file_reference()
        data = self.get_random_bytes(LARGE_FILE_SIZE)
        with open(INPUT_FILE_PATH, 'wb') as stream:
            stream.write(data)
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path=file_name,
                                 credential=self.settings.STORAGE_ACCOUNT_KEY)

        # Act
        file_size = len(data)
        with open(INPUT_FILE_PATH, 'rb') as stream:
            non_seekable_file = StorageFileTest.NonSeekableFile(stream)
            file_client.upload_file(non_seekable_file,
                                    length=file_size,
                                    max_connections=1)

        # Assert
        self.assertFileEqual(file_client, data[:file_size])
Ejemplo n.º 4
0
    def test_create_file_with_md5_small(self):
        # Arrange
        file_name = self._get_file_reference()
        data = self.get_random_bytes(512)
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path=file_name,
                                 credential=self.settings.STORAGE_ACCOUNT_KEY,
                                 max_range_size=4 * 1024)

        # Act
        file_client.upload_file(data, validate_content=True)
Ejemplo n.º 5
0
    def test_unicode_get_file_unicode_name(self):
        # Arrange
        file_name = '啊齄丂狛狜'
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path=file_name,
                                 credential=self.settings.STORAGE_ACCOUNT_KEY)
        file_client.upload_file(b'hello world')

        # Act
        content = file_client.download_file().content_as_bytes()

        # Assert
        self.assertEqual(content, b'hello world')
Ejemplo n.º 6
0
    def test_file_unicode_data(self):
        # Arrange
        file_name = self._get_file_reference()
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path=file_name,
                                 credential=self.settings.STORAGE_ACCOUNT_KEY)

        # Act
        data = u'hello world啊齄丂狛狜'.encode('utf-8')
        file_client.upload_file(data)

        # Assert
        content = file_client.download_file().content_as_bytes()
        self.assertEqual(content, data)
Ejemplo n.º 7
0
    def test_create_file_with_md5_large(self):
        # parallel tests introduce random order of requests, can only run live
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        file_name = self._get_file_reference()
        data = self.get_random_bytes(LARGE_FILE_SIZE)
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path=file_name,
                                 credential=self.settings.STORAGE_ACCOUNT_KEY,
                                 max_range_size=4 * 1024)

        # Act
        file_client.upload_file(data, validate_content=True, max_connections=2)
Ejemplo n.º 8
0
    def test_create_file_from_text_with_encoding(self):
        # Arrange
        file_name = self._get_file_reference()
        text = u'hello 啊齄丂狛狜 world'
        data = text.encode('utf-16')
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path=file_name,
                                 credential=self.settings.STORAGE_ACCOUNT_KEY,
                                 max_range_size=4 * 1024)

        # Act
        file_client.upload_file(text, encoding='UTF-16')

        # Assert
        self.assertFileEqual(file_client, data)
Ejemplo n.º 9
0
    def test_unicode_get_file_binary_data(self):
        # Arrange
        base64_data = 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w=='
        binary_data = base64.b64decode(base64_data)

        file_name = self._get_file_reference()
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path=file_name,
                                 credential=self.settings.STORAGE_ACCOUNT_KEY)
        file_client.upload_file(binary_data)

        # Act
        content = file_client.download_file().content_as_bytes()

        # Assert
        self.assertEqual(content, binary_data)
Ejemplo n.º 10
0
    def test_create_file_from_bytes_with_index(self):
        # parallel tests introduce random order of requests, can only run live
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        file_name = self._get_file_reference()
        data = self.get_random_bytes(LARGE_FILE_SIZE)
        index = 1024
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path=file_name,
                                 credential=self.settings.STORAGE_ACCOUNT_KEY)

        # Act
        file_client.upload_file(data[index:], max_connections=2)

        # Assert
        self.assertFileEqual(file_client, data[1024:])
Ejemplo n.º 11
0
    def test_create_file_from_text_chunked_upload(self):
        # parallel tests introduce random order of requests, can only run live
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        file_name = self._get_file_reference()
        data = self.get_random_text_data(LARGE_FILE_SIZE)
        encoded_data = data.encode('utf-8')
        file_client = FileClient(self.get_file_url(),
                                 share=self.share_name,
                                 file_path=file_name,
                                 credential=self.settings.STORAGE_ACCOUNT_KEY,
                                 max_range_size=4 * 1024)

        # Act
        file_client.upload_file(data)

        # Assert
        self.assertFileEqual(file_client, encoded_data)