Merge in RR/pyinfra from add_tests to master
Squashed commit of the following:
commit aa99d15c0487304a06bb36d990765fdca28bb651
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Mar 4 13:05:27 2022 +0100
RED-3463: Add some important tests
commit 666bb067ae19ee221ee9a4437f5a2c0bc749b3a6
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Mar 4 09:57:03 2022 +0100
blackkky
commit f6ce3be25e32f0c612b76a88e83b473a4d9ce605
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Fri Mar 4 09:56:25 2022 +0100
added tests for processor and analyzer
commit b08f2742742c52400d9b8c984025c66f25c2bede
Author: cdietrich <clarissa.dietrich@iqser.com>
Date: Fri Mar 4 08:19:55 2022 +0100
add tests
commit 7a37b73db0567d6bbb5d854c73c7bdf57fa34043
Merge: a3056c0 cc0c1bb
Author: cdietrich <clarissa.dietrich@iqser.com>
Date: Thu Mar 3 11:58:03 2022 +0100
Merge branch 'master' of ssh://git.iqser.com:2222/rr/pyinfra
commit a3056c0df73091ee766491331f07e3a0377e7887
Author: cdietrich <clarissa.dietrich@iqser.com>
Date: Thu Mar 3 10:24:54 2022 +0100
refactor save response as file
74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
import json
|
|
import logging
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
from pyinfra.exceptions import UnknownClient
|
|
from pyinfra.locations import TEST_DIR
|
|
from pyinfra.storage.adapters.azure import AzureStorageAdapter
|
|
from pyinfra.storage.adapters.s3 import S3StorageAdapter
|
|
from pyinfra.storage.clients.azure import get_azure_client
|
|
from pyinfra.storage.clients.s3 import get_s3_client
|
|
from pyinfra.storage.storage import Storage
|
|
from pyinfra.test.config import CONFIG
|
|
from pyinfra.test.storage.adapter_mock import StorageAdapterMock
|
|
from pyinfra.test.storage.client_mock import StorageClientMock
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
@pytest.fixture
|
|
def bucket_name():
|
|
return "pyinfra-test-bucket"
|
|
|
|
|
|
@pytest.fixture
|
|
def storage_data():
|
|
with open(f"{TEST_DIR}/test_data/test_data.TEXT.json", "r") as f:
|
|
data = json.load(f)
|
|
return data
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_response(storage_data):
|
|
response = Mock(status_code=200)
|
|
response.json.return_value = storage_data
|
|
return response
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_payload():
|
|
return json.dumps({"dossierId": "test", "fileId": "test"})
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_make_load_data():
|
|
def load_data(payload):
|
|
return storage_data
|
|
|
|
return load_data
|
|
|
|
|
|
@pytest.fixture(params=["minio", "aws"])
|
|
def storage(client_name, bucket_name, request):
|
|
logger.debug("Setup for storage")
|
|
storage = Storage(get_adapter(client_name, request.param))
|
|
storage.make_bucket(bucket_name)
|
|
storage.clear_bucket(bucket_name)
|
|
yield storage
|
|
logger.debug("Teardown for storage")
|
|
storage.clear_bucket(bucket_name)
|
|
|
|
|
|
def get_adapter(client_name, s3_backend):
|
|
if client_name == "mock":
|
|
return StorageAdapterMock(StorageClientMock())
|
|
if client_name == "azure":
|
|
return AzureStorageAdapter(get_azure_client(CONFIG.storage.azure.connection_string))
|
|
if client_name == "s3":
|
|
return S3StorageAdapter(get_s3_client(CONFIG.storage[s3_backend]))
|
|
else:
|
|
raise UnknownClient(client_name)
|