Skip to content

Commit

Permalink
pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
dapineyro committed Oct 22, 2024
1 parent 4d56de6 commit 49ab20b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The package requires Python >= 3.7 and the following python packages:
```
click>=8.0.1
pandas>=1.3.4
numpy==1.26.4
requests>=2.26.0
```

Expand Down
2 changes: 1 addition & 1 deletion cloudos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from .clos import Cloudos
from ._version import __version__

__all__ = ['jobs', 'utils', 'clos', 'cohorts']
__all__ = ['jobs', 'utils', 'clos', 'queue']
2 changes: 1 addition & 1 deletion cloudos/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def run(apikey,
print('\t' + str(j))
print('\t...Sending job to CloudOS\n')
if is_module:
if job_queue != None:
if job_queue is not None:
print(f'\t\t[Message] Job queue "{job_queue}" was specified but a the ' +
'workflow is a platform workflow that uses a fixed queue provided ' +
f'by CloudOS. Ignoring job queue "{job_queue}" and using the ' +
Expand Down
5 changes: 3 additions & 2 deletions cloudos/clos.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def process_workflow_list(r, all_fields=False):
"""
COLUMNS = ['_id',
'name',
'isModule',
'archived.status',
'mainFile',
'workflowType',
Expand Down Expand Up @@ -495,8 +496,8 @@ def is_module(self, workflow_name, workspace_id, verify=True):
if len(is_module) == 0:
raise ValueError(f'No workflow found with name: {workflow_name}')
if len(is_module) > 1:
raise ValueError(f'More than one workflow type detected for {workflow_name}: {wt}')
return is_module.values[0].upper() == 'TRUE'
raise ValueError(f'More than one workflow found with name: {workflow_name}')
return is_module.values[0]

def get_project_list(self, workspace_id, verify=True):
"""Get all the project from a CloudOS workspace.
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dependencies:
- requests
- click
- pandas
- numpy==1.26.4
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ click>=8.0.1
requests>=2.26.0
requests-mock>=1.9.3
pandas>=1.3.4
numpy==1.26.4
pytest>=6.2.5
responses>=0.21.0
mock>=3.0.5
mock>=3.0.5
41 changes: 41 additions & 0 deletions tests/test_clos/test_is_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Pytest for method Cloudos.is_module"""
import mock
import responses
from responses import matchers
from cloudos.clos import Cloudos
from tests.functions_for_pytest import load_json_file

INPUT = "tests/test_data/process_workflow_list_initial_request.json"
APIKEY = 'vnoiweur89u2ongs'
CLOUDOS_URL = 'http://cloudos.lifebit.ai'
WORKSPACE_ID = 'lv89ufc838sdig'


@mock.patch('cloudos.clos', mock.MagicMock())
@responses.activate
def test_is_module():
"""
Test 'is_module' to work as intended
API request is mocked and replicated with json files
"""
json_data = load_json_file(INPUT)
params = {"teamId": WORKSPACE_ID, "apikey": APIKEY}
header = {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=UTF-8"
}
search_str = f"teamId={WORKSPACE_ID}&apikey={APIKEY}"
# mock GET method with the .json
responses.add(
responses.GET,
url=f"{CLOUDOS_URL}/api/v1/workflows?{search_str}",
body=json_data,
headers=header,
match=[matchers.query_param_matcher(params)],
status=200)
# start cloudOS service
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
# get mock response
response = clos.is_module(workspace_id=WORKSPACE_ID,
workflow_name="multiqc")
assert response
4 changes: 2 additions & 2 deletions tests/test_data/process_workflow_list_initial_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
"isPredefined": false,
"isCurated": false,
"isFeatured": false,
"isModule": false,
"isModule": true,
"isPublic": false,
"priceAmount": 0,
"priceUnit": "PER_SAMPLE",
Expand All @@ -309,4 +309,4 @@
"workflowType": "docker",
"containerName": "ewels/multiqc"
}
]
]
8 changes: 4 additions & 4 deletions tests/test_data/process_workflow_list_results.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_id,name,archived.status,mainFile,workflowType,repository.name,repository.platform,repository.url,repository.isPrivate
XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX
XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX
XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX
_id,name,isModule,archived.status,mainFile,workflowType,repository.name,repository.platform,repository.url,repository.isPrivate
XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX
XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX
XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX,XXX

0 comments on commit 49ab20b

Please sign in to comment.