tests_for_datastore #63

Merged
brian merged 45 commits from tests_for_datastore into main 2024-12-21 17:31:14 +01:00
Showing only changes of commit 169e0531d9 - Show all commits
+83
View File
@@ -0,0 +1,83 @@
"""Definition of unittests for get function."""
import random
import string
import unittest
from io import BytesIO
from unittest.mock import Mock
from minio import Minio
from shared.datastore import get
class TestGet(unittest.TestCase):
def setUp(self):
# mock minio client
self.client = Mock(spec=Minio)
# set bucket name
self.bucket_name = 'test-bucket'
# set object name
self.object_name = ''.join(
random.choices(
string.ascii_uppercase + string.digits,
k=24,
),
)
# mock response object
self.client.get_object.return_value.status = 200
buffer = BytesIO(random.randbytes(2**20))
self.client.return_value.get_object = buffer
self.client.get_object.return_value.read = buffer.getvalue()
def test_should_fail_on_wrong_input_type_client(self):
with self.assertRaises(AssertionError):
get(
client='not-minio-type',
bucket_name=self.bucket_name,
object_name=self.object_name,
)
def test_should_fail_on_wrong_input_type_bucket_name(self):
with self.assertRaises(AssertionError):
get(
client=self.client,
bucket_name=0.0,
object_name=self.object_name,
)
def test_should_fail_on_wrong_input_length_bucket_name(self):
with self.assertRaises(AssertionError):
get(
client=self.client,
bucket_name='',
object_name=self.object_name,
)
def test_should_fail_on_wrong_input_type_object_name(self):
with self.assertRaises(AssertionError):
get(
client=self.client,
bucket_name=self.bucket_name,
object_name=0.0,
)
def test_should_fail_on_wrong_input_length_object_name(self):
with self.assertRaises(AssertionError):
get(
client=self.client,
bucket_name=self.bucket_name,
object_name='',
)
def test_should_call_client__get_object(self):
get(
client=self.client,
bucket_name=self.bucket_name,
object_name=self.object_name,
)
self.client.get_object.assert_called_with(
bucket_name=self.bucket_name,
object_name=self.object_name,
)