diff --git a/minio/commonconfig.py b/minio/commonconfig.py index 993e6967..6e5eaf6a 100644 --- a/minio/commonconfig.py +++ b/minio/commonconfig.py @@ -466,12 +466,12 @@ def build_headers(self, object_size: int, etag: str): @property def object_size(self) -> Optional[int]: """Get object size.""" - if self.object_size is None: + if self._object_size is None: raise MinioException( "build_headers() must be called prior to " "this method invocation", ) - return self.object_size + return self._object_size @property def headers(self) -> dict[str, str]: diff --git a/tests/functional/tests.py b/tests/functional/tests.py index 58935976..3b3b6aa5 100644 --- a/tests/functional/tests.py +++ b/tests/functional/tests.py @@ -53,10 +53,13 @@ from minio.time import to_http_header from minio.versioningconfig import SUSPENDED, VersioningConfig +# pylint: disable=invalid-name _CLIENT = None # initialized in main(). _TEST_FILE = None # initialized in main(). _LARGE_FILE = None # initialized in main(). _IS_AWS = None # initialized in main(). +# pylint: enable=invalid-name + KB = 1024 MB = 1024 * KB HTTP = urllib3.PoolManager( diff --git a/tests/unit/composesource_test.py b/tests/unit/composesource_test.py new file mode 100644 index 00000000..c1114a2c --- /dev/null +++ b/tests/unit/composesource_test.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015, 2016 MinIO, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from unittest import TestCase + +from minio.commonconfig import ComposeSource +from minio.error import MinioException + + +class ComposeSourceTest(TestCase): + def test_object_size(self): + source = ComposeSource(bucket_name="my-bucket", + object_name="my-object") + with self.assertRaises(MinioException) as exc: + _ = source.object_size + + msg = "build_headers() must be called prior to this method invocation" + self.assertEqual(msg, str(exc.exception))