예제 #1
0
 def setUp(self):
     super(TestWriter, self).setUp()
     self.vault = create_mock_vault()
     self.chunk_size = 2  # power of 2
     self.part_size = 4  # power of 2
     upload_id = sentinel.upload_id
     self.writer = Writer(self.vault, upload_id, self.part_size,
                          self.chunk_size)
예제 #2
0
파일: test_writer.py 프로젝트: hzy/boto
 def setUp(self):
     super(TestWriter, self).setUp()
     self.vault = create_mock_vault()
     self.chunk_size = 2 # power of 2
     self.part_size = 4 # power of 2
     upload_id = sentinel.upload_id
     self.writer = Writer(
         self.vault, upload_id, self.part_size, self.chunk_size)
예제 #3
0
파일: test_writer.py 프로젝트: hzy/boto
class TestWriter(unittest.TestCase):
    def setUp(self):
        super(TestWriter, self).setUp()
        self.vault = create_mock_vault()
        self.chunk_size = 2 # power of 2
        self.part_size = 4 # power of 2
        upload_id = sentinel.upload_id
        self.writer = Writer(
            self.vault, upload_id, self.part_size, self.chunk_size)

    def check_write(self, write_list):
        for write_data in write_list:
            self.writer.write(write_data)
        self.writer.close()

        data = ''.join(write_list)
        upload_part_calls, data_tree_hashes = calculate_mock_vault_calls(
            data, self.part_size, self.chunk_size)
        check_mock_vault_calls(
            self.vault, upload_part_calls, data_tree_hashes, len(data))

    def test_single_byte_write(self):
        self.check_write(['1'])

    def test_one_part_write(self):
        self.check_write(['1234'])

    def test_split_write_1(self):
        self.check_write(['1', '234'])

    def test_split_write_2(self):
        self.check_write(['12', '34'])

    def test_split_write_3(self):
        self.check_write(['123', '4'])

    def test_one_part_plus_one_write(self):
        self.check_write(['12345'])

    def test_returns_archive_id(self):
        self.writer.write('1')
        self.writer.close()
        self.assertEquals(sentinel.archive_id, self.writer.get_archive_id())

    def test_upload_id(self):
        self.assertEquals(sentinel.upload_id, self.writer.upload_id)
예제 #4
0
class TestWriter(unittest.TestCase):
    def setUp(self):
        super(TestWriter, self).setUp()
        self.vault = create_mock_vault()
        self.chunk_size = 2  # power of 2
        self.part_size = 4  # power of 2
        upload_id = sentinel.upload_id
        self.writer = Writer(self.vault, upload_id, self.part_size,
                             self.chunk_size)

    def check_write(self, write_list):
        for write_data in write_list:
            self.writer.write(write_data)
        self.writer.close()

        data = ''.join(write_list)
        upload_part_calls, data_tree_hashes = calculate_mock_vault_calls(
            data, self.part_size, self.chunk_size)
        check_mock_vault_calls(self.vault, upload_part_calls, data_tree_hashes,
                               len(data))

    def test_single_byte_write(self):
        self.check_write(['1'])

    def test_one_part_write(self):
        self.check_write(['1234'])

    def test_split_write_1(self):
        self.check_write(['1', '234'])

    def test_split_write_2(self):
        self.check_write(['12', '34'])

    def test_split_write_3(self):
        self.check_write(['123', '4'])

    def test_one_part_plus_one_write(self):
        self.check_write(['12345'])

    def test_returns_archive_id(self):
        self.writer.write('1')
        self.writer.close()
        self.assertEquals(sentinel.archive_id, self.writer.get_archive_id())

    def test_upload_id(self):
        self.assertEquals(sentinel.upload_id, self.writer.upload_id)
예제 #5
0
    def create_archive_writer(self, part_size=DefaultPartSize,
                              description=None):
        """
        Create a new archive and begin a multi-part upload to it.
        Returns a file-like object to which the data for the archive
        can be written. Once all the data is written the file-like
        object should be closed, you can then call the get_archive_id
        method on it to get the ID of the created archive.

        :type part_size: int
        :param part_size: The part size for the multipart upload.

        :type description: str
        :param description: An optional description for the archive.

        :rtype: :class:`boto.glacier.writer.Writer`
        :return: A Writer object that to which the archive data
            should be written.
        """
        response = self.layer1.initiate_multipart_upload(self.name,
                                                         part_size,
                                                         description)
        return Writer(self, response['UploadId'], part_size=part_size)
예제 #6
0
파일: test_writer.py 프로젝트: boto/boto
class TestWriter(unittest.TestCase):
    def setUp(self):
        super(TestWriter, self).setUp()
        self.vault = create_mock_vault()
        self.chunk_size = 2 # power of 2
        self.part_size = 4 # power of 2
        upload_id = sentinel.upload_id
        self.writer = Writer(
            self.vault, upload_id, self.part_size, self.chunk_size)

    def check_write(self, write_list):
        for write_data in write_list:
            self.writer.write(write_data)
        self.writer.close()

        data = b''.join(write_list)
        upload_part_calls, data_tree_hashes = calculate_mock_vault_calls(
            data, self.part_size, self.chunk_size)
        check_mock_vault_calls(
            self.vault, upload_part_calls, data_tree_hashes, len(data))

    def test_single_byte_write(self):
        self.check_write([b'1'])

    def test_one_part_write(self):
        self.check_write([b'1234'])

    def test_split_write_1(self):
        self.check_write([b'1', b'234'])

    def test_split_write_2(self):
        self.check_write([b'12', b'34'])

    def test_split_write_3(self):
        self.check_write([b'123', b'4'])

    def test_one_part_plus_one_write(self):
        self.check_write([b'12345'])

    def test_returns_archive_id(self):
        self.writer.write(b'1')
        self.writer.close()
        self.assertEquals(sentinel.archive_id, self.writer.get_archive_id())

    def test_current_tree_hash(self):
        self.writer.write(b'1234')
        self.writer.write(b'567')
        hash_1 = self.writer.current_tree_hash
        self.assertEqual(hash_1,
            b'\x0e\xb0\x11Z\x1d\x1f\n\x10|\xf76\xa6\xf5' +
            b'\x83\xd1\xd5"bU\x0c\x95\xa8<\xf5\x81\xef\x0e\x0f\x95\n\xb7k'
        )

        # This hash will be different, since the content has changed.
        self.writer.write(b'22i3uy')
        hash_2 = self.writer.current_tree_hash
        self.assertEqual(hash_2,
            b'\x7f\xf4\x97\x82U]\x81R\x05#^\xe8\x1c\xd19' +
            b'\xe8\x1f\x9e\xe0\x1aO\xaad\xe5\x06"\xa5\xc0\xa8AdL'
        )
        self.writer.close()

        # Check the final tree hash, post-close.
        final_hash = self.writer.current_tree_hash
        self.assertEqual(final_hash,
            b';\x1a\xb8!=\xf0\x14#\x83\x11\xd5\x0b\x0f' +
            b'\xc7D\xe4\x8e\xd1W\x99z\x14\x06\xb9D\xd0\xf0*\x93\xa2\x8e\xf9'
        )
        # Then assert we don't get a different one on a subsequent call.
        self.assertEqual(final_hash, self.writer.current_tree_hash)

    def test_current_uploaded_size(self):
        self.writer.write(b'1234')
        self.writer.write(b'567')
        size_1 = self.writer.current_uploaded_size
        self.assertEqual(size_1, 4)

        # This hash will be different, since the content has changed.
        self.writer.write(b'22i3uy')
        size_2 = self.writer.current_uploaded_size
        self.assertEqual(size_2, 12)
        self.writer.close()

        # Get the final size, post-close.
        final_size = self.writer.current_uploaded_size
        self.assertEqual(final_size, 13)
        # Then assert we don't get a different one on a subsequent call.
        self.assertEqual(final_size, self.writer.current_uploaded_size)

    def test_upload_id(self):
        self.assertEquals(sentinel.upload_id, self.writer.upload_id)
예제 #7
0
class TestWriter(unittest.TestCase):
    def setUp(self):
        super(TestWriter, self).setUp()
        self.vault = create_mock_vault()
        self.chunk_size = 2  # power of 2
        self.part_size = 4  # power of 2
        upload_id = sentinel.upload_id
        self.writer = Writer(self.vault, upload_id, self.part_size,
                             self.chunk_size)

    def check_write(self, write_list):
        for write_data in write_list:
            self.writer.write(write_data)
        self.writer.close()

        data = b''.join(write_list)
        upload_part_calls, data_tree_hashes = calculate_mock_vault_calls(
            data, self.part_size, self.chunk_size)
        check_mock_vault_calls(self.vault, upload_part_calls, data_tree_hashes,
                               len(data))

    def test_single_byte_write(self):
        self.check_write([b'1'])

    def test_one_part_write(self):
        self.check_write([b'1234'])

    def test_split_write_1(self):
        self.check_write([b'1', b'234'])

    def test_split_write_2(self):
        self.check_write([b'12', b'34'])

    def test_split_write_3(self):
        self.check_write([b'123', b'4'])

    def test_one_part_plus_one_write(self):
        self.check_write([b'12345'])

    def test_returns_archive_id(self):
        self.writer.write(b'1')
        self.writer.close()
        self.assertEquals(sentinel.archive_id, self.writer.get_archive_id())

    def test_current_tree_hash(self):
        self.writer.write(b'1234')
        self.writer.write(b'567')
        hash_1 = self.writer.current_tree_hash
        self.assertEqual(
            hash_1, b'\x0e\xb0\x11Z\x1d\x1f\n\x10|\xf76\xa6\xf5' +
            b'\x83\xd1\xd5"bU\x0c\x95\xa8<\xf5\x81\xef\x0e\x0f\x95\n\xb7k')

        # This hash will be different, since the content has changed.
        self.writer.write(b'22i3uy')
        hash_2 = self.writer.current_tree_hash
        self.assertEqual(
            hash_2, b'\x7f\xf4\x97\x82U]\x81R\x05#^\xe8\x1c\xd19' +
            b'\xe8\x1f\x9e\xe0\x1aO\xaad\xe5\x06"\xa5\xc0\xa8AdL')
        self.writer.close()

        # Check the final tree hash, post-close.
        final_hash = self.writer.current_tree_hash
        self.assertEqual(
            final_hash, b';\x1a\xb8!=\xf0\x14#\x83\x11\xd5\x0b\x0f' +
            b'\xc7D\xe4\x8e\xd1W\x99z\x14\x06\xb9D\xd0\xf0*\x93\xa2\x8e\xf9')
        # Then assert we don't get a different one on a subsequent call.
        self.assertEqual(final_hash, self.writer.current_tree_hash)

    def test_current_uploaded_size(self):
        self.writer.write(b'1234')
        self.writer.write(b'567')
        size_1 = self.writer.current_uploaded_size
        self.assertEqual(size_1, 4)

        # This hash will be different, since the content has changed.
        self.writer.write(b'22i3uy')
        size_2 = self.writer.current_uploaded_size
        self.assertEqual(size_2, 12)
        self.writer.close()

        # Get the final size, post-close.
        final_size = self.writer.current_uploaded_size
        self.assertEqual(final_size, 13)
        # Then assert we don't get a different one on a subsequent call.
        self.assertEqual(final_size, self.writer.current_uploaded_size)

    def test_upload_id(self):
        self.assertEquals(sentinel.upload_id, self.writer.upload_id)