diff --git a/README.md b/README.md index 4ded965..7937a4b 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,10 @@ Kubernetes ``` kubectl create -f deployment/minio.yml ``` + +### Tests + +Run tests +``` +pytest app/tests/ +``` \ No newline at end of file diff --git a/app/requirements-dev.txt b/app/requirements-dev.txt new file mode 100644 index 0000000..c5bbb1f --- /dev/null +++ b/app/requirements-dev.txt @@ -0,0 +1,3 @@ +-r requirements.txt +pytest==7.4.4 +pytest-mock==3.12.0 diff --git a/app/tests/__init__.py b/app/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/tests/helpers/__init__.py b/app/tests/helpers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/tests/helpers/storage/__init__.py b/app/tests/helpers/storage/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/tests/helpers/storage/test_minio.py b/app/tests/helpers/storage/test_minio.py new file mode 100644 index 0000000..3384ad0 --- /dev/null +++ b/app/tests/helpers/storage/test_minio.py @@ -0,0 +1,34 @@ +import pytest +from src.helpers.storage.minio import MinioClient + +@pytest.fixture +def minio_client(): + endpoint_url = 'http://localhost:9000' + access_key = 'minio_access_key' + secret_key = 'minio_secret_key' + return MinioClient(endpoint_url, access_key, secret_key) + +def test_create_bucket(mocker, minio_client): + mock_s3 = mocker.patch.object(minio_client.s3_client, 'create_bucket') + minio_client.create_bucket('testbucket') + mock_s3.assert_called_once_with(Bucket='testbucket') + +def test_upload_file(mocker, minio_client): + mock_upload_file = mocker.patch.object(minio_client.s3_client, 'upload_file') + minio_client.upload_file('testbucket', 'test.txt', '/path/to/test.txt') + mock_upload_file.assert_called_once_with('/path/to/test.txt', 'testbucket', 'test.txt') + +def test_download_file(mocker, minio_client): + mock_download_file = mocker.patch.object(minio_client.s3_client, 'download_file') + minio_client.download_file('testbucket', 'test.txt', '/path/to/downloaded/test.txt') + mock_download_file.assert_called_once_with('testbucket', 'test.txt', '/path/to/downloaded/test.txt') + +def test_delete_file(mocker, minio_client): + mock_delete_object = mocker.patch.object(minio_client.s3_client, 'delete_object') + minio_client.delete_file('testbucket', 'test.txt') + mock_delete_object.assert_called_once_with(Bucket='testbucket', Key='test.txt') + +def test_delete_bucket(mocker, minio_client): + mock_delete_bucket = mocker.patch.object(minio_client.s3_client, 'delete_bucket') + minio_client.delete_bucket('testbucket') + mock_delete_bucket.assert_called_once_with(Bucket='testbucket')