added unittest

This commit is contained in:
brian
2024-11-08 22:27:58 +00:00
parent 53d179663b
commit cddfced177
2 changed files with 84 additions and 6 deletions
@@ -0,0 +1,77 @@
"""Definition of unittests for delete function."""
import random
import string
import unittest
from unittest.mock import Mock
from minio import Minio
from shared.datastore import delete
class TestDelete(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,
),
)
def test_should_fail_on_wrong_input_type_client(self):
with self.assertRaises(AssertionError):
delete(
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):
delete(
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):
delete(
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):
delete(
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):
delete(
client=self.client,
bucket_name=self.bucket_name,
object_name='',
)
def test_should_call_client__remove_object(self):
delete(
client=self.client,
bucket_name=self.bucket_name,
object_name=self.object_name,
)
self.client.remove_object.assert_called_with(
bucket_name=self.bucket_name,
object_name=self.object_name,
)