Skip to content

Commit

Permalink
build: upgrade FOCA to 0.13.0 (#52)
Browse files Browse the repository at this point in the history
* build: upgrade FOCA version
  • Loading branch information
jvkersch committed Jun 18, 2024
1 parent bf420d0 commit da53984
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 104 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##### BASE IMAGE #####
FROM elixircloud/foca:20201114
FROM elixircloud/foca:20240520-py3.12


##### METADATA #####
Expand Down
5 changes: 3 additions & 2 deletions drs_filer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import logging

from foca.foca import foca
from foca import Foca

from drs_filer.ga4gh.drs.endpoints.service_info import RegisterServiceInfo

logger = logging.getLogger(__name__)


def main():
app = foca("config.yaml")
foca = Foca("config.yaml")
app = foca.create_app()

# register service info
with app.app.app_context():
Expand Down
20 changes: 11 additions & 9 deletions drs_filer/ga4gh/drs/endpoints/register_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@ 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
was_replaced = False
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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions drs_filer/ga4gh/drs/endpoints/service_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
6 changes: 3 additions & 3 deletions drs_filer/ga4gh/drs/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand All @@ -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
)

Expand Down
4 changes: 4 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
flake8
mongomock
pytest
pytest-cov
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
foca==0.6.0
foca==0.13.0
gunicorn==20.0.4
setuptools==65.5.1
setuptools==70.0.0
16 changes: 8 additions & 8 deletions tests/ga4gh/drs/endpoints/test_register_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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"}
Expand All @@ -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": []}
Expand All @@ -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():
Expand Down
48 changes: 24 additions & 24 deletions tests/ga4gh/drs/endpoints/test_service_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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():
Expand All @@ -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():
Expand All @@ -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():
Expand All @@ -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():
Expand All @@ -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()
Expand All @@ -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():
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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,
)
Expand Down
Loading

0 comments on commit da53984

Please sign in to comment.