50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
|
import os
|
||
|
import random
|
||
|
import tempfile
|
||
|
from string import ascii_letters
|
||
|
|
||
|
from dotenv import dotenv_values
|
||
|
|
||
|
from pytestpavement.helper.filehasher import calc_hash_of_file
|
||
|
from pytestpavement.io.minio import MinioClient
|
||
|
|
||
|
|
||
|
class TestMinio():
|
||
|
|
||
|
#read .env file
|
||
|
config = dotenv_values(".env")
|
||
|
|
||
|
bucket = 'pytest'
|
||
|
|
||
|
client = MinioClient(url=config['S3_HOST'],
|
||
|
access_key=config['S3_ACCESS_KEY'],
|
||
|
secret_key=config['S3_PASSWD'],
|
||
|
secure=False,
|
||
|
bucket=bucket)
|
||
|
|
||
|
def test_init_minio(self) -> None:
|
||
|
return
|
||
|
|
||
|
def test_upload_file(self) -> None:
|
||
|
"""
|
||
|
generate dummy file and upload to s3 bucket
|
||
|
|
||
|
"""
|
||
|
|
||
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||
|
|
||
|
#generate testfile
|
||
|
n = 1024**2
|
||
|
n = 1000
|
||
|
|
||
|
file_orig = os.path.join(tmpdirname, 'textfile.txt')
|
||
|
with open(file_orig, 'w') as f:
|
||
|
f.write(''.join(
|
||
|
[random.choice(ascii_letters) for l in range(n)]))
|
||
|
|
||
|
filehash_orig = calc_hash_of_file(file_orig)
|
||
|
|
||
|
self.client.compress_and_upload_file(file_orig,
|
||
|
'test',
|
||
|
metadata={'lab': '123'})
|