Skip to content

Commit

Permalink
Merge pull request #36 from EGA-archive/ritools
Browse files Browse the repository at this point in the history
Adding unit tests
  • Loading branch information
costero-e authored Jan 24, 2025
2 parents a60c51d + 94b0250 commit 495e58f
Show file tree
Hide file tree
Showing 18 changed files with 1,068 additions and 185 deletions.
6 changes: 3 additions & 3 deletions beacon/auth/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dotenv import load_dotenv

# for keycloak, create aud in mappers, with custom, aud and beacon for audience
mock_access_token = ''
mock_access_token = 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJreS1tUXNxZ0ZYeHdSUVRfRUhuQlJJUGpmbVhfRXZuUTVEbzZWUTJCazdZIn0.eyJleHAiOjE3Mzc3MjA0NDAsImlhdCI6MTczNzcyMDE0MCwianRpIjoiMTllODFkMTQtNDEzZS00ZGU0LWIwNzUtZDJlMjUzNGM1MDZjIiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL2F1dGgvcmVhbG1zL0JlYWNvbiIsImF1ZCI6ImJlYWNvbiIsInN1YiI6IjQ3ZWZmMWIxLTc2MjEtNDU3MC1hMGJiLTAxYTcxOWZiYTBhMiIsInR5cCI6IkJlYXJlciIsImF6cCI6ImJlYWNvbiIsInNlc3Npb25fc3RhdGUiOiI4ZDkwMGU1OS0xNmE1LTQzYzktYjgwNC05ZTFkMmY1ODNiOTYiLCJhY3IiOiIxIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCBtaWNyb3Byb2ZpbGUtand0Iiwic2lkIjoiOGQ5MDBlNTktMTZhNS00M2M5LWI4MDQtOWUxZDJmNTgzYjk2IiwidXBuIjoiamFuZSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwibmFtZSI6IkphbmUgU21pdGgiLCJncm91cHMiOlsib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiIsIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXSwicHJlZmVycmVkX3VzZXJuYW1lIjoiamFuZSIsImdpdmVuX25hbWUiOiJKYW5lIiwiZmFtaWx5X25hbWUiOiJTbWl0aCIsImVtYWlsIjoiamFuZS5zbWl0aEBiZWFjb24uZ2E0Z2gifQ.gOt5RgqH-OQG9mnjybrX_fJes9pPolrkXVMbwtImD4FpFP4cxKa-iZjLUoTCufYzFRAO0qj1rslY_50Q_pRlkr7rFwyzdbofKZ_ZCTCSIiV-rrnjE6fxQNdRKMpL9tZ-6wwGhB016cu4_YcznYdoTwahfRGRV9oiknucidSOd2jEfzfiaL89irFlzsrKYCYUY5iM4Ct21m6un7iQtxVs78RRFunzlKu4WwkKy-xtTBITZtSrLpOL7XI6EJ_P98KDGM5z_0XTTukYos7JqfSApDRMJuaap1A8zCZB4j5yjQUgY-Xb9gKUc2Ro7cNao_NuGmSzlSR788ukIh2XdTxtxQ'
mock_access_token_false = 'public'
#dummy test anonymous
#dummy test login
Expand Down Expand Up @@ -103,7 +103,7 @@ async def test_fetch_user_info():
IDP_JWKS_URL = os.getenv('JWKS_URL')
list_visa_datasets=[]
user, list_visa_datasets = await fetch_user_info(self, mock_access_token, IDP_USER_INFO, IDP_ISSUER, list_visa_datasets)
assert user.get('preferred_username') == 'costero-e'
assert user.get('preferred_username') == 'jane'
loop.run_until_complete(test_fetch_user_info())
loop.run_until_complete(client.close())
def test_auth_authentication(self):
Expand All @@ -113,7 +113,7 @@ def test_auth_authentication(self):
loop.run_until_complete(client.start_server())
async def test_authentication():
user, list_visa_datasets = await authentication(self, mock_access_token)
assert user.get('preferred_username') == 'costero-e'
assert user.get('preferred_username') == 'jane'
loop.run_until_complete(test_authentication())
loop.run_until_complete(client.close())
def test_auth_authentication_false(self):
Expand Down
2 changes: 1 addition & 1 deletion beacon/conf/api_version.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
api_version: v2.0-ed7de15
api_version: v2.0-a60c51d
4 changes: 2 additions & 2 deletions beacon/connections/mongo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pymongo.mongo_client import MongoClient
from beacon.connections.mongo import conf

if conf.database_cluster:
if conf.database_cluster:# pragma: no cover
uri = "mongodb+srv://{}:{}@{}/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000".format(
conf.database_user,
conf.database_password,
Expand All @@ -17,7 +17,7 @@
conf.database_auth_source
)

if conf.database_certificate != '' and conf.database_cafile != '':
if conf.database_certificate != '' and conf.database_cafile != '':# pragma: no cover
uri += '&tls=true&tlsCertificateKeyFile={}&tlsCAFile={}'.format(conf.database_certificate, conf.database_cafile)

client = MongoClient(uri)
18 changes: 3 additions & 15 deletions beacon/connections/mongo/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,12 @@ def get_variants_of_analysis(self, entry_id: Optional[str], qparams: RequestPara
for bioid in bioids:
if bioid == analysis_ids["biosampleId"]:
break
position+=1
if position == len(bioids):
position+=1# pragma: no cover
if position == len(bioids):# pragma: no cover
schema = DefaultSchemas.GENOMICVARIATIONS
return schema, 0, -1, None, dataset
position=str(position)
filters=qparams.query.filters
if filters != []:
for filter in filters:
if filter['id']=='GENO:GENO_0000458':
query_cl={"$or": [{ position: "10", "datasetId": dataset}, { position: "01", "datasetId": dataset}]}
qparams.query.filters.remove(filter)
elif filter['id']=='GENO:GENO_0000136':
query_cl={"$or": [{ position: "11", "datasetId": dataset}]}
qparams.query.filters.remove(filter)
else:
query_cl={"$or": [{ position: "10", "datasetId": dataset},{ position: "11", "datasetId": dataset}, { position: "01", "datasetId": dataset}]}
else:
query_cl={"$or": [{ position: "10", "datasetId": dataset},{ position: "11", "datasetId": dataset}, { position: "01", "datasetId": dataset}]}
query_cl={"$or": [{ position: "10", "datasetId": dataset},{ position: "11", "datasetId": dataset}, { position: "01", "datasetId": dataset}]}
string_of_ids = client.beacon.caseLevelData \
.find(query_cl, {"id": 1, "_id": 0}).limit(qparams.query.pagination.limit).skip(qparams.query.pagination.skip)
HGVSIds=list(string_of_ids)
Expand Down
16 changes: 2 additions & 14 deletions beacon/connections/mongo/biosamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,11 @@ def get_variants_of_biosample(self, entry_id: Optional[str], qparams: RequestPar
if bioid == entry_id:
break
position+=1
if position == len(bioids):
if position == len(bioids):# pragma: no cover
schema = DefaultSchemas.GENOMICVARIATIONS
return schema, 0, -1, None, dataset
position=str(position)
filters=qparams.query.filters
if filters != []:
for filter in filters:
if filter['id']=='GENO:GENO_0000458':
query_cl={"$or": [{ position: "10", "datasetId": dataset}, { position: "01", "datasetId": dataset}]}
qparams.query.filters.remove(filter)
elif filter['id']=='GENO:GENO_0000136':
query_cl={"$or": [{ position: "11", "datasetId": dataset}]}
qparams.query.filters.remove(filter)
else:
query_cl={"$or": [{ position: "10", "datasetId": dataset},{ position: "11", "datasetId": dataset}, { position: "01", "datasetId": dataset}]}
else:
query_cl={"$or": [{ position: "10", "datasetId": dataset},{ position: "11", "datasetId": dataset}, { position: "01", "datasetId": dataset}]}
query_cl={"$or": [{ position: "10", "datasetId": dataset},{ position: "11", "datasetId": dataset}, { position: "01", "datasetId": dataset}]}
string_of_ids = client.beacon.caseLevelData \
.find(query_cl, {"id": 1, "_id": 0}).limit(qparams.query.pagination.limit).skip(qparams.query.pagination.skip)
HGVSIds=list(string_of_ids)
Expand Down
6 changes: 3 additions & 3 deletions beacon/connections/mongo/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ async def execute_function(self, entry_type: str, datasets: list, qparams: Reque
datasets_docs[dataset]=records
datasets_count[dataset]=dataset_count
else:
datasets.remove(dataset)
datasets.remove(dataset)# pragma: no cover
elif include == 'HIT':
if dataset_count != -1 and dataset_count != 0:
new_count+=dataset_count
datasets_docs[dataset]=records
datasets_count[dataset]=dataset_count
else:
datasets.remove(dataset)
else:
if dataset_count == 0:
else:
if dataset_count == 0:# pragma: no cover
new_count+=dataset_count
datasets_docs[dataset]=records
datasets_count[dataset]=dataset_count
Expand Down
Loading

0 comments on commit 495e58f

Please sign in to comment.