コード例 #1
0
 def test_init_defaults(self, mock_init):
     """Test init providing only required arguments."""
     obj = gcs_object.Object()
     mock_init.assert_called_once_with(None, None)
     self.assertIsNone(obj.name)
     self.assertIsNone(obj.bucket)
     self.assertIsNone(obj.generation)
コード例 #2
0
 def test_repr(self, mock_get_data):
     """Test repr representation."""
     mock_get_data.return_value = {'items': []}
     bucket = 'bucket'
     name = 'name'
     generation = 'generation'
     obj = gcs_object.Object(bucket, name, generation)
     self.assertEqual(
         "gcs_client.gcs_object.Object('%s', '%s', '%s') "
         "#etag: ?" % (bucket, name, generation), repr(obj))
コード例 #3
0
    def test_get_data(self, request_mock):
        """Test _get_data used when accessing non existent attributes."""
        bucket = 'bucket'
        name = 'name'
        request_mock.return_value.json.return_value = {'size': '1'}
        obj = gcs_object.Object(bucket, name, mock.sentinel.generation,
                                mock.Mock(), mock.sentinel.retry_params)

        result = obj._get_data()
        self.assertEqual({'size': '1'}, result)
        request_mock.assert_called_once_with(
            parse=True, generation=mock.sentinel.generation)
コード例 #4
0
 def test_init(self, mock_init):
     """Test init providing all arguments."""
     creds = mock.Mock()
     obj = gcs_object.Object(mock.sentinel.bucket, mock.sentinel.name,
                             mock.sentinel.generation, creds,
                             mock.sentinel.retry_params)
     mock_init.assert_called_once_with(creds, mock.sentinel.retry_params)
     self.assertEqual(mock.sentinel.name, obj.name)
     self.assertEqual(mock.sentinel.bucket, obj.bucket)
     self.assertEqual(mock.sentinel.generation, obj.generation)
     self.assertEqual('storage#objects', obj.kind)
     self.assertDictEqual({}, obj.metadata)
     self.assertIsNone(obj.timeDeleted)
コード例 #5
0
 def test_open(self, mock_file):
     """Test open object."""
     creds = mock.Mock()
     obj = gcs_object.Object(mock.sentinel.bucket, mock.sentinel.name,
                             mock.sentinel.generation, creds,
                             mock.sentinel.retry_params,
                             mock.sentinel.chunksize)
     self.assertEqual(mock_file.return_value, obj.open(mock.sentinel.mode))
     mock_file.assert_called_once_with(mock.sentinel.bucket,
                                       mock.sentinel.name, creds,
                                       mock.sentinel.mode,
                                       mock.sentinel.chunksize,
                                       mock.sentinel.retry_params,
                                       mock.sentinel.generation)
コード例 #6
0
    def open(self, name, mode='r', generation=None, chunksize=None):
        """Open an object from the Bucket.

        :param name: Name of the file to open.
        :type name: String
        :param mode: Mode to open the file with, 'r' for read and 'w' for
                     writing are only supported formats.  Default is 'r' if
                     this argument is not provided.
        :type mode: String
        :param generation: If present, selects a specific revision of this
                           object (as opposed to the latest version, the
                           default).
        :type generation: long
        :param chunksize: Size in bytes of the payload to send/receive to/from
                          GCS.  Default is gcs_client.DEFAULT_BLOCK_SIZE
        :type chunksize: int
        """
        obj = gcs_object.Object(self.name, name, generation, self.credentials,
                                self.retry_params, chunksize)
        return obj.open(mode)
コード例 #7
0
    def test_delete(self, request_mock):
        """Test object delete."""
        bucket = 'bucket'
        name = 'filename'
        obj = gcs_object.Object(bucket, name, mock.sentinel.generation,
                                mock.Mock(), mock.sentinel.retry_params)

        obj.delete(mock.sentinel.specific_generation,
                   mock.sentinel.if_generation_match,
                   mock.sentinel.if_generation_not_match,
                   mock.sentinel.if_metageneration_match,
                   mock.sentinel.if_metageneration_not_match)

        request_mock.assert_called_once_with(
            op='DELETE',
            ok=(requests.codes.no_content, ),
            generation=mock.sentinel.specific_generation,
            ifGenerationMatch=mock.sentinel.if_generation_match,
            ifGenerationNotMatch=mock.sentinel.if_generation_not_match,
            ifMetagenerationMatch=mock.sentinel.if_metageneration_match,
            ifMetagenerationNotMatch=mock.sentinel.if_metageneration_not_match)
コード例 #8
0
 def test_str(self):
     """Test string representation."""
     obj = gcs_object.Object('bucket', 'name')
     self.assertEqual('bucket/name', str(obj))