extended tests
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
"""Integration tests for functions exposed by the datastore module."""
|
"""Integration tests for functions exposed by the datastore module."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from io import BytesIO
|
||||||
|
from random import randbytes
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from minio import Minio
|
from minio import Minio
|
||||||
from testcontainers.minio import MinioContainer
|
from testcontainers.minio import MinioContainer
|
||||||
|
|
||||||
from shared.datastore import connect_minio
|
from shared.datastore import connect_minio, get, put
|
||||||
|
from shared.utils import setup_logging
|
||||||
|
|
||||||
minio = MinioContainer()
|
minio = MinioContainer()
|
||||||
MINIO_BUCKET_NAME = 'visual-critical-discourse-analysis'
|
MINIO_BUCKET_NAME = 'visual-critical-discourse-analysis'
|
||||||
@@ -30,10 +33,6 @@ def setup(request):
|
|||||||
os.environ['MINIO_ACCESS_KEY'] = minio.access_key
|
os.environ['MINIO_ACCESS_KEY'] = minio.access_key
|
||||||
os.environ['MINIO_SECRET_KEY'] = minio.secret_key
|
os.environ['MINIO_SECRET_KEY'] = minio.secret_key
|
||||||
os.environ['MINIO_BUCKET_NAME'] = MINIO_BUCKET_NAME
|
os.environ['MINIO_BUCKET_NAME'] = MINIO_BUCKET_NAME
|
||||||
# save random image to Minio
|
|
||||||
pass
|
|
||||||
# save random model to Minio
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def test_connect_minio():
|
def test_connect_minio():
|
||||||
@@ -42,6 +41,49 @@ def test_connect_minio():
|
|||||||
assert isinstance(minio_client, Minio)
|
assert isinstance(minio_client, Minio)
|
||||||
|
|
||||||
|
|
||||||
|
def test_put():
|
||||||
|
"""Test function put."""
|
||||||
|
# connect to minio
|
||||||
|
minio_client = connect_minio()
|
||||||
|
# generate random bytes
|
||||||
|
buffer = BytesIO(randbytes(2**20))
|
||||||
|
# put data in Minio
|
||||||
|
put(
|
||||||
|
client=minio_client,
|
||||||
|
buffer=buffer,
|
||||||
|
bucket_name=MINIO_BUCKET_NAME,
|
||||||
|
object_name='test_put_data',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get():
|
||||||
|
"""Test function get."""
|
||||||
|
# connect to minio
|
||||||
|
minio_client = connect_minio()
|
||||||
|
# generate random bytes
|
||||||
|
buffer = BytesIO(randbytes(2**20))
|
||||||
|
# put data in minio
|
||||||
|
put(
|
||||||
|
client=minio_client,
|
||||||
|
buffer=buffer,
|
||||||
|
bucket_name=MINIO_BUCKET_NAME,
|
||||||
|
object_name='test_get_data',
|
||||||
|
)
|
||||||
|
# get data back from minio
|
||||||
|
buffer_rec = get(
|
||||||
|
client=minio_client,
|
||||||
|
bucket_name=MINIO_BUCKET_NAME,
|
||||||
|
object_name='test_get_data',
|
||||||
|
)
|
||||||
|
# check that data are the same
|
||||||
|
assert buffer.read() == buffer_rec.read()
|
||||||
|
|
||||||
|
|
||||||
|
def test_delete():
|
||||||
|
"""Test function delete."""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
def test_get_image():
|
def test_get_image():
|
||||||
"""Test function get_image."""
|
"""Test function get_image."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
@@ -60,3 +102,9 @@ def test_get_model():
|
|||||||
def test_put_model():
|
def test_put_model():
|
||||||
"""Test function put_model."""
|
"""Test function put_model."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
os.environ['LOG_LEVEL'] = 'debug'
|
||||||
|
setup_logging()
|
||||||
|
pytest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user