diff --git a/Dockerfile b/Dockerfile index e3ac6be..b59f1df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ##### BASE IMAGE ##### -FROM elixircloud/foca:20201114 +FROM elixircloud/foca:20240520-py3.12 ##### METADATA ##### diff --git a/drs_filer/app.py b/drs_filer/app.py index 00d4187..a436fb9 100644 --- a/drs_filer/app.py +++ b/drs_filer/app.py @@ -2,7 +2,7 @@ import logging -from foca.foca import foca +from foca import Foca from drs_filer.ga4gh.drs.endpoints.service_info import RegisterServiceInfo @@ -10,7 +10,8 @@ def main(): - app = foca("config.yaml") + foca = Foca("config.yaml") + app = foca.create_app() # register service info with app.app.app_context(): diff --git a/drs_filer/ga4gh/drs/endpoints/register_objects.py b/drs_filer/ga4gh/drs/endpoints/register_objects.py index da2d79b..18d5fb3 100644 --- a/drs_filer/ga4gh/drs/endpoints/register_objects.py +++ b/drs_filer/ga4gh/drs/endpoints/register_objects.py @@ -31,14 +31,15 @@ def register_object( A unique identifier for the object. """ # Set parameters + foca_config = current_app.config.foca db_collection = ( - current_app.config['FOCA'].db.dbs['drsStore']. + foca_config.db.dbs['drsStore']. collections['objects'].client ) - url_prefix = current_app.config['FOCA'].endpoints['url_prefix'] - external_host = current_app.config['FOCA'].endpoints['external_host'] - external_port = current_app.config['FOCA'].endpoints['external_port'] - api_path = current_app.config['FOCA'].endpoints['api_path'] + url_prefix = foca_config.endpoints['url_prefix'] + external_host = foca_config.endpoints['external_host'] + external_port = foca_config.endpoints['external_port'] + api_path = foca_config.endpoints['api_path'] # Set flags and parameters for POST/PUT routes replace = True @@ -46,10 +47,10 @@ def register_object( if object_id is None: replace = False id_length = ( - current_app.config['FOCA'].endpoints['objects']['id_length'] + foca_config.endpoints['objects']['id_length'] ) id_charset: str = ( - current_app.config['FOCA'].endpoints['objects']['id_charset'] + foca_config.endpoints['objects']['id_charset'] ) # evaluate character set expression or interpret literal string as set try: @@ -120,11 +121,12 @@ def __add_access_ids(data: List) -> List: Returns: Access methods metadata complete with unique access identifiers. """ + foca_config = current_app.config.foca id_charset = eval( - current_app.config['FOCA'].endpoints['access_methods']['id_charset'] + foca_config.endpoints['access_methods']['id_charset'] ) id_length = ( - current_app.config['FOCA'].endpoints['access_methods']['id_length'] + foca_config.endpoints['access_methods']['id_length'] ) access_ids = [] for method in data: diff --git a/drs_filer/ga4gh/drs/endpoints/service_info.py b/drs_filer/ga4gh/drs/endpoints/service_info.py index 3c13f5f..c19dc58 100644 --- a/drs_filer/ga4gh/drs/endpoints/service_info.py +++ b/drs_filer/ga4gh/drs/endpoints/service_info.py @@ -34,14 +34,14 @@ def __init__(self) -> None: db_coll_info: Database collection storing service info objects. conf_info: Service info details as per enpoints config. """ - conf = current_app.config['FOCA'].endpoints + conf = current_app.config.foca.endpoints self.url_prefix = conf['url_prefix'] self.host_name = conf['external_host'] self.external_port = conf['external_port'] self.api_path = conf['api_path'] self.conf_info = conf['service_info'] self.db_coll_info = ( - current_app.config['FOCA'].db.dbs['drsStore'] + current_app.config.foca.db.dbs['drsStore'] .collections['service_info'].client ) diff --git a/drs_filer/ga4gh/drs/server.py b/drs_filer/ga4gh/drs/server.py index 84a6f0a..fc9c0b5 100644 --- a/drs_filer/ga4gh/drs/server.py +++ b/drs_filer/ga4gh/drs/server.py @@ -34,7 +34,7 @@ def GetObject(object_id: str) -> Dict: DRS object as dictionary, JSONified if returned in app context. """ db_collection = ( - current_app.config['FOCA'].db.dbs['drsStore']. + current_app.config.foca.db.dbs['drsStore']. collections['objects'].client ) obj = db_collection.find_one({"id": object_id}) @@ -112,7 +112,7 @@ def DeleteObject(object_id): """ db_collection = ( - current_app.config['FOCA'].db.dbs['drsStore']. + current_app.config.foca.db.dbs['drsStore']. collections['objects'].client ) obj = db_collection.find_one({"id": object_id}) @@ -138,7 +138,7 @@ def DeleteAccessMethod(object_id: str, access_id: str) -> str: """ db_collection = ( - current_app.config['FOCA'].db.dbs['drsStore']. + current_app.config.foca.db.dbs['drsStore']. collections['objects'].client ) diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..a024d5e --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,4 @@ +flake8 +mongomock +pytest +pytest-cov \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 79c3bcb..4e4f742 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -foca==0.6.0 +foca==0.13.0 gunicorn==20.0.4 -setuptools==65.5.1 +setuptools==70.0.0 diff --git a/tests/ga4gh/drs/endpoints/test_register_objects.py b/tests/ga4gh/drs/endpoints/test_register_objects.py index b4057b1..2424414 100644 --- a/tests/ga4gh/drs/endpoints/test_register_objects.py +++ b/tests/ga4gh/drs/endpoints/test_register_objects.py @@ -52,12 +52,12 @@ def test_register_object_literal_id_charset(): app = Flask(__name__) endpoint_config = deepcopy(ENDPOINT_CONFIG) endpoint_config['objects']['id_charset'] = 'abcdef' - app.config['FOCA'] = \ + app.config.foca = \ Config( db=MongoConfig(**MONGO_CONFIG), endpoints=endpoint_config, ) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().db.collection request_data = {"name": "mock_name"} @@ -71,12 +71,12 @@ def test_register_object_invalid_config(): app = Flask(__name__) endpoint_config = deepcopy(ENDPOINT_CONFIG) del endpoint_config['url_prefix'] - app.config['FOCA'] = \ + app.config.foca = \ Config( db=MongoConfig(**MONGO_CONFIG), endpoints=endpoint_config, ) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().db.collection request_data = {"name": "mock_name"} @@ -90,15 +90,15 @@ def test_register_object_exceed_retries(): identifier. """ app = Flask(__name__) - app.config['FOCA'] = \ + app.config.foca = \ Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) mock_resp = MagicMock(side_effect=DuplicateKeyError('')) - app.config['FOCA'].db.dbs['drsStore'].collections['objects']. \ + app.config.foca.db.dbs['drsStore'].collections['objects']. \ client = MagicMock() - app.config['FOCA'].db.dbs['drsStore'].collections['objects']. \ + app.config.foca.db.dbs['drsStore'].collections['objects']. \ client.insert_one = mock_resp request_data = {"name": "mock_name", "access_methods": []} @@ -110,7 +110,7 @@ def test_register_object_exceed_retries(): def test_add_access_ids(): """Test for __add_access_ids().""" app = Flask(__name__) - app.config['FOCA'] = Config(endpoints=ENDPOINT_CONFIG) + app.config.foca = Config(endpoints=ENDPOINT_CONFIG) objects = json.loads(open(data_objects_path, "r").read()) mock_data = objects[0]['access_methods'] with app.app_context(): diff --git a/tests/ga4gh/drs/endpoints/test_service_info.py b/tests/ga4gh/drs/endpoints/test_service_info.py index 3993458..4f94886 100644 --- a/tests/ga4gh/drs/endpoints/test_service_info.py +++ b/tests/ga4gh/drs/endpoints/test_service_info.py @@ -92,14 +92,14 @@ def test_get_service_info(): """Test for getting service info.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) mock_resp = deepcopy(SERVICE_INFO_CONFIG) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client.insert_one(mock_resp) with app.app_context(): @@ -109,11 +109,11 @@ def test_get_service_info(): def test_get_service_info_na(): """Test for getting service info if unavailable.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection with app.app_context(): @@ -124,11 +124,11 @@ def test_get_service_info_na(): def test_set_service_info_from_config(): """Test for setting service info from config.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection with app.app_context(): @@ -142,11 +142,11 @@ def test_set_service_info_from_config_corrupt(): app = Flask(__name__) mock_resp = deepcopy(ENDPOINT_CONFIG) del mock_resp['service_info']['id'] - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=mock_resp, ) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection with app.app_context(): @@ -160,14 +160,14 @@ def test_set_service_info_from_config_skip(): available. """ app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) mock_resp = deepcopy(SERVICE_INFO_CONFIG) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client.insert_one(mock_resp) with app.app_context(): @@ -179,20 +179,20 @@ def test_set_service_info_from_config_skip(): def test_get_service_info_duplicatekey(): """Test for duplicated service info config.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection mock = MagicMock(side_effect=[DuplicateKeyError(''), None]) - app.config['FOCA'].db.dbs['drsStore'] \ + app.config.foca.db.dbs['drsStore'] \ .collections['service_info'].client.insert_one = mock mock_db_call = MagicMock(name="Find_Obj") mock_db_call.return_value.sort.return_value \ .limit.return_value.next.return_value = deepcopy(SERVICE_INFO_CONFIG) - app.config['FOCA'].db.dbs['drsStore'] \ + app.config.foca.db.dbs['drsStore'] \ .collections['service_info'].client.find = mock_db_call with app.app_context(): get_service_info = RegisterServiceInfo().get_service_info() @@ -202,11 +202,11 @@ def test_get_service_info_duplicatekey(): def test_set_service_info_from_app_context(): """Test for setting service info from app context.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection with app.app_context(): @@ -220,11 +220,11 @@ def test_set_service_info_from_app_context(): def test__upsert_service_info_insert(): """Test for creating service info document in database.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection data = deepcopy(SERVICE_INFO_CONFIG) @@ -239,14 +239,14 @@ def test__upsert_service_info_insert(): def test__upsert_service_info_update(): """Test for replacing service info document in database.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) mock_resp = deepcopy(SERVICE_INFO_CONFIG) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client.insert_one(mock_resp) data = deepcopy(SERVICE_INFO_CONFIG) @@ -261,7 +261,7 @@ def test__upsert_service_info_update(): def test__get_headers(): """Test for response headers getter.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) diff --git a/tests/ga4gh/drs/test_server.py b/tests/ga4gh/drs/test_server.py index 777cafa..2c4557b 100644 --- a/tests/ga4gh/drs/test_server.py +++ b/tests/ga4gh/drs/test_server.py @@ -101,12 +101,12 @@ def test_GetObject(): """Test for getting DRSObject meta-data using `object_id`""" app = Flask(__name__) - app.config['FOCA'] = Config(db=MongoConfig(**MONGO_CONFIG)) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca = Config(db=MongoConfig(**MONGO_CONFIG)) + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - obj['_id'] = app.config['FOCA'].db.dbs['drsStore']. \ + obj['_id'] = app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj).inserted_id del objects[0]['_id'] with app.app_context(): @@ -117,13 +117,13 @@ def test_GetObject(): def test_GetObject_Not_Found(): with pytest.raises(ObjectNotFound): app = Flask(__name__) - app.config['FOCA'] = Config(db=MongoConfig(**MONGO_CONFIG)) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca = Config(db=MongoConfig(**MONGO_CONFIG)) + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().\ db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - obj['_id'] = app.config['FOCA'].db.dbs['drsStore']. \ + obj['_id'] = app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj).inserted_id del objects[0]['_id'] with app.app_context(): @@ -134,12 +134,12 @@ def test_GetAccessURL(): """Test for getting DRSObject access url using `object_id` and `access_id` """ app = Flask(__name__) - app.config['FOCA'] = Config(db=MongoConfig(**MONGO_CONFIG)) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca = Config(db=MongoConfig(**MONGO_CONFIG)) + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - obj['_id'] = app.config['FOCA'].db.dbs['drsStore']. \ + obj['_id'] = app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj).inserted_id del objects[0]['_id'] with app.app_context(): @@ -158,13 +158,13 @@ def test_GetAccessURL_Not_Found(): """ with pytest.raises(URLNotFound): app = Flask(__name__) - app.config['FOCA'] = Config(db=MongoConfig(**MONGO_CONFIG)) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca = Config(db=MongoConfig(**MONGO_CONFIG)) + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().\ db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - obj['_id'] = app.config['FOCA'].db.dbs['drsStore']. \ + obj['_id'] = app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj).inserted_id del objects[0]['_id'] with app.app_context(): @@ -183,13 +183,13 @@ def test_GetAccessURL_Object_Not_Found(): """ with pytest.raises(ObjectNotFound): app = Flask(__name__) - app.config['FOCA'] = Config(db=MongoConfig(**MONGO_CONFIG)) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca = Config(db=MongoConfig(**MONGO_CONFIG)) + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().\ db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - obj['_id'] = app.config['FOCA'].db.dbs['drsStore']. \ + obj['_id'] = app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj).inserted_id del objects[0]['_id'] with app.app_context(): @@ -201,13 +201,13 @@ def test_GetAccessURL_Key_Error(): are not there""" with pytest.raises(InternalServerError): app = Flask(__name__) - app.config['FOCA'] = Config(db=MongoConfig(**MONGO_CONFIG)) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca = Config(db=MongoConfig(**MONGO_CONFIG)) + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().\ db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - obj['_id'] = app.config['FOCA'].db.dbs['drsStore']. \ + obj['_id'] = app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj).inserted_id del objects[0]['_id'] with app.app_context(): @@ -218,13 +218,13 @@ def test_GetAccessURL_Duplicate_Access_Id(): """GetAccessURL should return Internal Server Error on duplicate access keys. """ app = Flask(__name__) - app.config['FOCA'] = Config(db=MongoConfig(**MONGO_CONFIG)) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca = Config(db=MongoConfig(**MONGO_CONFIG)) + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().\ db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - obj['_id'] = app.config['FOCA'].db.dbs['drsStore']. \ + obj['_id'] = app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj).inserted_id del objects[0]['_id'] with app.app_context(): @@ -235,13 +235,13 @@ def test_GetAccessURL_Duplicate_Access_Id(): def test_DeleteObject(): """DeleteObject should return the id of the deleted object""" app = Flask(__name__) - app.config['FOCA'] = \ + app.config.foca = \ Config(db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - obj['_id'] = app.config['FOCA'].db.dbs['drsStore']. \ + obj['_id'] = app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj).inserted_id del objects[0]['_id'] with app.app_context(): @@ -252,13 +252,13 @@ def test_DeleteObject(): def test_DeleteObject_Not_Found(): """ObjectNotFound should be raised if object id is not found""" app = Flask(__name__) - app.config['FOCA'] = \ + app.config.foca = \ Config(db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - obj['_id'] = app.config['FOCA'].db.dbs['drsStore']. \ + obj['_id'] = app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj).inserted_id del objects[0]['_id'] with app.app_context(): @@ -271,15 +271,15 @@ def test_DeleteAccessMethod(): with a given `object_id`. """ app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['objects'].client = \ + app.config.foca.db.dbs['drsStore'].collections['objects'].client = \ mongomock.MongoClient().db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj) with app.app_context(): res = DeleteAccessMethod.__wrapped__("a011", "2") @@ -292,11 +292,11 @@ def test_DeleteAccessMethod_ObjectNotFound(): not available. """ app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['objects'].client = \ + app.config.foca.db.dbs['drsStore'].collections['objects'].client = \ mongomock.MongoClient().db.collection with app.app_context(): with pytest.raises(ObjectNotFound): @@ -309,15 +309,15 @@ def test_DeleteAccessMethod_AccessMethodNotFound(): identifier is not available. """ app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['objects'].client = \ + app.config.foca.db.dbs['drsStore'].collections['objects'].client = \ mongomock.MongoClient().db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj) with app.app_context(): with pytest.raises(AccessMethodNotFound): @@ -330,15 +330,15 @@ def test_DeleteAcessMethod_BadRequest(monkeypatch): access method associated with object. """ app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['objects'].client = \ + app.config.foca.db.dbs['drsStore'].collections['objects'].client = \ mongomock.MongoClient().db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj) with app.app_context(): with pytest.raises(BadRequest): @@ -359,15 +359,15 @@ def __init__(self, modified_count): lambda *args, **kwargs: mock_response ) app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['objects'].client = \ + app.config.foca.db.dbs['drsStore'].collections['objects'].client = \ mongomock.MongoClient().db.collection objects = json.loads(open(data_objects_path, "r").read()) for obj in objects: - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(obj) with app.app_context(): with pytest.raises(InternalServerError): @@ -377,9 +377,9 @@ def __init__(self, modified_count): def test_PostObject(): """Test for creating a new object with an auto-generated identifier.""" app = Flask(__name__) - app.config['FOCA'] = \ + app.config.foca = \ Config(db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().db.collection with app.test_request_context(json={"name": "drsObject"}): @@ -390,9 +390,9 @@ def test_PostObject(): def test_PutObject(): """Test for creating a new object with a user-supplied identigier.""" app = Flask(__name__) - app.config['FOCA'] = \ + app.config.foca = \ Config(db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().db.collection with app.test_request_context(json={"name": "drsObject"}): @@ -403,11 +403,11 @@ def test_PutObject(): def test_PutObject_update(): """Test for updating an existing object.""" app = Flask(__name__) - app.config['FOCA'] = \ + app.config.foca = \ Config(db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG) - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client = mongomock.MongoClient().db.collection - app.config['FOCA'].db.dbs['drsStore']. \ + app.config.foca.db.dbs['drsStore']. \ collections['objects'].client.insert_one(MOCK_DATA_OBJECT) with app.test_request_context(json={"name": "drsObject"}): @@ -419,14 +419,14 @@ def test_PutObject_update(): def test_getServiceInfo(): """Test for getting service info.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) mock_resp = deepcopy(SERVICE_INFO_CONFIG) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client.insert_one(mock_resp) with app.app_context(): @@ -438,11 +438,11 @@ def test_getServiceInfo(): def test_postServiceInfo(): """Test for creating service info.""" app = Flask(__name__) - app.config['FOCA'] = Config( + app.config.foca = Config( db=MongoConfig(**MONGO_CONFIG), endpoints=ENDPOINT_CONFIG, ) - app.config['FOCA'].db.dbs['drsStore'].collections['service_info'] \ + app.config.foca.db.dbs['drsStore'].collections['service_info'] \ .client = mongomock.MongoClient().db.collection with app.test_request_context(json=deepcopy(SERVICE_INFO_CONFIG)):