cloudos-cli 2.17.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cloudos_cli/__init__.py +11 -0
- cloudos_cli/__main__.py +1297 -0
- cloudos_cli/_version.py +1 -0
- cloudos_cli/clos.py +726 -0
- cloudos_cli/jobs/__init__.py +8 -0
- cloudos_cli/jobs/job.py +555 -0
- cloudos_cli/queue/__init__.py +8 -0
- cloudos_cli/queue/queue.py +139 -0
- cloudos_cli/utils/__init__.py +9 -0
- cloudos_cli/utils/errors.py +32 -0
- cloudos_cli/utils/requests.py +75 -0
- cloudos_cli-2.17.0.dist-info/LICENSE +674 -0
- cloudos_cli-2.17.0.dist-info/METADATA +1060 -0
- cloudos_cli-2.17.0.dist-info/RECORD +41 -0
- cloudos_cli-2.17.0.dist-info/WHEEL +5 -0
- cloudos_cli-2.17.0.dist-info/entry_points.txt +2 -0
- cloudos_cli-2.17.0.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/functions_for_pytest.py +7 -0
- tests/test_clos/__init__.py +0 -0
- tests/test_clos/test_create_cromwell_header.py +35 -0
- tests/test_clos/test_cromwell_switch.py +77 -0
- tests/test_clos/test_detect_workflow.py +47 -0
- tests/test_clos/test_get_cromwell_status.py +77 -0
- tests/test_clos/test_get_curated_workflow_list.py +72 -0
- tests/test_clos/test_get_job_list.py +79 -0
- tests/test_clos/test_get_job_status.py +75 -0
- tests/test_clos/test_get_project_list.py +74 -0
- tests/test_clos/test_get_user_info.py +68 -0
- tests/test_clos/test_get_workflow_list.py +87 -0
- tests/test_clos/test_is_module.py +48 -0
- tests/test_clos/test_process_job_list.py +74 -0
- tests/test_clos/test_process_project_list.py +36 -0
- tests/test_clos/test_process_workflow_list.py +36 -0
- tests/test_clos/test_wait_job_completion.py +40 -0
- tests/test_clos/test_workflow_import.py +77 -0
- tests/test_jobs/__init__.py +0 -0
- tests/test_jobs/test_convert_nextflow_to_json.py +104 -0
- tests/test_jobs/test_project_id.py +67 -0
- tests/test_jobs/test_send_job.py +84 -0
- tests/test_jobs/test_workflow_id.py +67 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
cloudos_cli/__init__.py,sha256=hvFji3Y-MNkzlntH6U3mCDTb1YHlL_7vTZUhvmXDyPA,207
|
|
2
|
+
cloudos_cli/__main__.py,sha256=fSoJZv7zp53GTkJiBGPlvgBrtc4mcy28lab6ghvhGC4,57990
|
|
3
|
+
cloudos_cli/_version.py,sha256=VbVbyojkpf-OG6U9Cui7JN--quTGvbXi7xNeQd1PnVI,23
|
|
4
|
+
cloudos_cli/clos.py,sha256=lPurwlEx-tYRP9DQn1c0RbUWpRPNNgxAOvqzJUE2Gsg,28316
|
|
5
|
+
cloudos_cli/jobs/__init__.py,sha256=epbZK5WB45L8Nsrp6BWoOSGtFK3tGwkFvbxFFHVu-Ww,89
|
|
6
|
+
cloudos_cli/jobs/job.py,sha256=a2X2TFi4W8jIbhHVGKZq8Q9-5vwjAzVjryE2UdE_V_M,24591
|
|
7
|
+
cloudos_cli/queue/__init__.py,sha256=ArVVMHjW93Il8mrRHkW-PFz5L_P-dUZAoLQbjTMsXSA,101
|
|
8
|
+
cloudos_cli/queue/queue.py,sha256=SEKQ3ht3FdGnh4HFAbJseGFIiDUt4HrY2oyNZOw7eUI,5175
|
|
9
|
+
cloudos_cli/utils/__init__.py,sha256=UYSUJjTBxc06NQPe9OPJ6w_GxeIPzf4ZxZIKVRJYzpk,222
|
|
10
|
+
cloudos_cli/utils/errors.py,sha256=u71WmIRs0EQKQuGPrBigHR-nWqWdx21OLwUw0q3mCwU,939
|
|
11
|
+
cloudos_cli/utils/requests.py,sha256=C7A5O4ObX_dgX_lFugBD0si6p4HjMn7l4EI55aiM0aM,2091
|
|
12
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
tests/functions_for_pytest.py,sha256=VFEkBjbKMlCRuBsFwZZ0xfmUqng8G88C4FXqOxozoN4,185
|
|
14
|
+
tests/test_clos/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
tests/test_clos/test_create_cromwell_header.py,sha256=dIWwcvOC3F00-XO3skLoPE8npTXJPTt4hEDE2P9LEXY,1136
|
|
16
|
+
tests/test_clos/test_cromwell_switch.py,sha256=0a_YOYoudbgwq_1xJo9CBZrOXfeoTQ8gY-5QAbx2km0,2696
|
|
17
|
+
tests/test_clos/test_detect_workflow.py,sha256=Dx7cbRYGZLAyMiYTtfgY3BY_OlVyhYy-enw52WECSdA,1638
|
|
18
|
+
tests/test_clos/test_get_cromwell_status.py,sha256=YComArwnMBGkLqWtD_UUZvJBAu3qdE-6HvG7bROJGww,2685
|
|
19
|
+
tests/test_clos/test_get_curated_workflow_list.py,sha256=yWQMnZc3sRU3dnY0Jk3IklCndMALyh7h-bmcI2ouElk,2716
|
|
20
|
+
tests/test_clos/test_get_job_list.py,sha256=-NfEQAvDnY658UWpDahzXGJTPPG24RZNFSSKIMQvhLM,2797
|
|
21
|
+
tests/test_clos/test_get_job_status.py,sha256=nSS9eWScR3cK6QgYTK00eG54RFVtftM-Wmn9xDslzlA,2472
|
|
22
|
+
tests/test_clos/test_get_project_list.py,sha256=bPzN42-X7gRllEzWtILXlopsrLe1LhCpoND7Scp_y7E,2499
|
|
23
|
+
tests/test_clos/test_get_user_info.py,sha256=r_Q0lqG4hWuRV3pK41cwq5wF8vy-tG3ktQvFLyZWJ4w,2160
|
|
24
|
+
tests/test_clos/test_get_workflow_list.py,sha256=ra70urC9EouQu8uYWWg1a0OWjPLoquZWhmHjUAvbZLg,3108
|
|
25
|
+
tests/test_clos/test_is_module.py,sha256=5WMAFKxPGHDQ0fhV6zw64ZsIW4c3fYroxaM4xjSS8Gc,1631
|
|
26
|
+
tests/test_clos/test_process_job_list.py,sha256=pu3MYFoxklRujuGzodFFp4gaIA43Os3T7OANkYZFY7I,3085
|
|
27
|
+
tests/test_clos/test_process_project_list.py,sha256=um6GWqFbRgmm3gv11h7itwANu-vxgnJGaqlI1vlJJZg,1398
|
|
28
|
+
tests/test_clos/test_process_workflow_list.py,sha256=_DafszHbNO3F6ZuzeT01Carho5Op8UT2SY4F5mneilg,1459
|
|
29
|
+
tests/test_clos/test_wait_job_completion.py,sha256=0a_AqkI6LQR0ymHl7YEn_zQeI2jmN-jZeyfmnl5EcLs,1339
|
|
30
|
+
tests/test_clos/test_workflow_import.py,sha256=b-L2MSxGf4DD-kkpJ4aF4h_qXH1Dn69PFlvC7F_Eviw,2798
|
|
31
|
+
tests/test_jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
|
+
tests/test_jobs/test_convert_nextflow_to_json.py,sha256=mK9RBfkjFaV1yoGyyTjxaY7Gsv48YWkcBhp1JjpZZgQ,4050
|
|
33
|
+
tests/test_jobs/test_project_id.py,sha256=zYSSJlW0o7Aka4_0msXNA0YmNUTpQI3TU3DlOAB0rNk,2338
|
|
34
|
+
tests/test_jobs/test_send_job.py,sha256=FLGLdhvE4FuPxMTQF_hp6U9WhgXtShHKbmB_BLedVAI,2854
|
|
35
|
+
tests/test_jobs/test_workflow_id.py,sha256=wA4t4GiF45xQ79-W1VI81wqbRj3DB1ry5VviNdLXDyc,2296
|
|
36
|
+
cloudos_cli-2.17.0.dist-info/LICENSE,sha256=YF6QR6Vjxcg5b_sYIyqkME7FZYau5TfEUGTG-0JeRK0,35129
|
|
37
|
+
cloudos_cli-2.17.0.dist-info/METADATA,sha256=Cmj5wO0kjgyVp5Mrw80W2zahgPzsHeiZe9MJ1lWz9t0,36780
|
|
38
|
+
cloudos_cli-2.17.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
39
|
+
cloudos_cli-2.17.0.dist-info/entry_points.txt,sha256=fCtLi-mJodD8JcK0Rjz6bA2dsee8w2MVWPD2YSJIU_w,65
|
|
40
|
+
cloudos_cli-2.17.0.dist-info/top_level.txt,sha256=kUqISvpmJxwrb9Y2xHAsgVqqFkBt5fMp8cSbDHa-3PE,18
|
|
41
|
+
cloudos_cli-2.17.0.dist-info/RECORD,,
|
tests/__init__.py
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from cloudos_cli.clos import Cloudos
|
|
2
|
+
|
|
3
|
+
TOKEN = "lifebit_test_token"
|
|
4
|
+
URL = "lifebit.ai"
|
|
5
|
+
|
|
6
|
+
EXPECTED_OUTPUT_APIKEY = {
|
|
7
|
+
"Accept": "application/json",
|
|
8
|
+
"apikey": TOKEN
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
EXPECTED_OUTPUT_CROMWELL_TOKEN = {
|
|
12
|
+
"Accept": "application/json",
|
|
13
|
+
"Authorization": f'Bearer {TOKEN}'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_create_cromwell_header_apikey():
|
|
18
|
+
"""Testing only apikey is provided."""
|
|
19
|
+
clos = Cloudos(apikey=TOKEN, cromwell_token=None, cloudos_url=URL)
|
|
20
|
+
output = clos._create_cromwell_header()
|
|
21
|
+
assert output == EXPECTED_OUTPUT_APIKEY
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_create_cromwell_header_cromwell_token():
|
|
25
|
+
"""Test only cromwell_token is provided."""
|
|
26
|
+
clos = Cloudos(apikey=None, cromwell_token=TOKEN, cloudos_url=URL)
|
|
27
|
+
output = clos._create_cromwell_header()
|
|
28
|
+
assert output == EXPECTED_OUTPUT_CROMWELL_TOKEN
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_create_cromwell_header_both():
|
|
32
|
+
"""Test both cromwell_token and apikey are provided."""
|
|
33
|
+
clos = Cloudos(apikey=TOKEN, cromwell_token=TOKEN, cloudos_url=URL)
|
|
34
|
+
output = clos._create_cromwell_header()
|
|
35
|
+
assert output == EXPECTED_OUTPUT_CROMWELL_TOKEN
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Pytests for function Cloudos.cromwell_switch"""
|
|
2
|
+
import json
|
|
3
|
+
import mock
|
|
4
|
+
import pytest
|
|
5
|
+
import requests
|
|
6
|
+
import responses
|
|
7
|
+
from responses import matchers
|
|
8
|
+
from cloudos_cli.clos import Cloudos
|
|
9
|
+
from cloudos_cli.utils.errors import BadRequestException
|
|
10
|
+
|
|
11
|
+
APIKEY = 'vnoiweur89u2ongs'
|
|
12
|
+
CLOUDOS_URL = 'http://cloudos.lifebit.ai'
|
|
13
|
+
WORKSPACE_ID = 'lv89ufc838sdig'
|
|
14
|
+
CROMWELL_ACTION = "stop"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
18
|
+
@responses.activate
|
|
19
|
+
def test_cromwell_switch():
|
|
20
|
+
"""
|
|
21
|
+
Test 'get_cromwell_switch' to work as intended
|
|
22
|
+
API request is mocked and replicated with json files
|
|
23
|
+
"""
|
|
24
|
+
create_json = json.dumps({"mock": "response"})
|
|
25
|
+
params = {"teamId": WORKSPACE_ID}
|
|
26
|
+
header = {
|
|
27
|
+
"Accept": "application/json, text/plain, */*",
|
|
28
|
+
"Content-Type": "application/json;charset=UTF-8"
|
|
29
|
+
}
|
|
30
|
+
search_str = f"{CROMWELL_ACTION}?teamId={WORKSPACE_ID}"
|
|
31
|
+
# mock GET method with the .json
|
|
32
|
+
responses.add(
|
|
33
|
+
responses.PUT,
|
|
34
|
+
url=f"{CLOUDOS_URL}/api/v1/cromwell/{search_str}",
|
|
35
|
+
body=create_json,
|
|
36
|
+
headers=header,
|
|
37
|
+
match=[matchers.query_param_matcher(params)],
|
|
38
|
+
status=200)
|
|
39
|
+
# start cloudOS service
|
|
40
|
+
clos = Cloudos(apikey=None, cromwell_token=APIKEY, cloudos_url=CLOUDOS_URL)
|
|
41
|
+
# get mock response
|
|
42
|
+
response = clos.cromwell_switch(WORKSPACE_ID, CROMWELL_ACTION)
|
|
43
|
+
# check the response
|
|
44
|
+
assert response.status_code == 200
|
|
45
|
+
assert isinstance(response, requests.models.Response)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
49
|
+
@responses.activate
|
|
50
|
+
def test_cromwell_switch_incorrect_response():
|
|
51
|
+
"""
|
|
52
|
+
Test 'cromwell_switch' to fail with '400' response
|
|
53
|
+
"""
|
|
54
|
+
# prepare error message
|
|
55
|
+
error_message = {"statusCode": 400, "code": "BadRequest",
|
|
56
|
+
"message": "Bad Request.", "time": "2022-11-23_17:31:07"}
|
|
57
|
+
error_json = json.dumps(error_message)
|
|
58
|
+
params = {"teamId": WORKSPACE_ID}
|
|
59
|
+
header = {
|
|
60
|
+
"Accept": "application/json, text/plain, */*",
|
|
61
|
+
"Content-Type": "application/json;charset=UTF-8"
|
|
62
|
+
}
|
|
63
|
+
search_str = f"{CROMWELL_ACTION}?teamId={WORKSPACE_ID}"
|
|
64
|
+
# mock GET method with the .json
|
|
65
|
+
responses.add(
|
|
66
|
+
responses.PUT,
|
|
67
|
+
url=f"{CLOUDOS_URL}/api/v1/cromwell/{search_str}",
|
|
68
|
+
body=error_json,
|
|
69
|
+
headers=header,
|
|
70
|
+
match=[matchers.query_param_matcher(params)],
|
|
71
|
+
status=400)
|
|
72
|
+
# raise 400 error
|
|
73
|
+
with pytest.raises(BadRequestException) as error:
|
|
74
|
+
# check if it failed
|
|
75
|
+
clos = Cloudos(apikey=None, cromwell_token=APIKEY, cloudos_url=CLOUDOS_URL)
|
|
76
|
+
clos.cromwell_switch(WORKSPACE_ID, CROMWELL_ACTION)
|
|
77
|
+
assert "Bad Request" in (str(error))
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Pytest for method Cloudos.detect_workflow"""
|
|
2
|
+
import mock
|
|
3
|
+
import responses
|
|
4
|
+
from responses import matchers
|
|
5
|
+
from cloudos_cli.clos import Cloudos
|
|
6
|
+
from tests.functions_for_pytest import load_json_file
|
|
7
|
+
|
|
8
|
+
INPUT = "tests/test_data/process_workflow_list_initial_request.json"
|
|
9
|
+
APIKEY = 'vnoiweur89u2ongs'
|
|
10
|
+
CLOUDOS_URL = 'http://cloudos.lifebit.ai'
|
|
11
|
+
WORKSPACE_ID = 'lv89ufc838sdig'
|
|
12
|
+
PAGE_SIZE = 10
|
|
13
|
+
PAGE = 1
|
|
14
|
+
ARCHIVED_STATUS = "false"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
18
|
+
@responses.activate
|
|
19
|
+
def test_detect_workflow():
|
|
20
|
+
"""
|
|
21
|
+
Test 'get_workflow_list' to work as intended
|
|
22
|
+
API request is mocked and replicated with json files
|
|
23
|
+
"""
|
|
24
|
+
json_data = load_json_file(INPUT)
|
|
25
|
+
params = {"teamId": WORKSPACE_ID,
|
|
26
|
+
"pageSize": PAGE_SIZE,
|
|
27
|
+
"page": PAGE,
|
|
28
|
+
"archived.status": ARCHIVED_STATUS}
|
|
29
|
+
header = {
|
|
30
|
+
"Accept": "application/json, text/plain, */*",
|
|
31
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
32
|
+
"apikey": APIKEY
|
|
33
|
+
}
|
|
34
|
+
search_str = f"teamId={WORKSPACE_ID}&pageSize={PAGE_SIZE}&page={PAGE}&archived.status={ARCHIVED_STATUS}"
|
|
35
|
+
# mock GET method with the .json
|
|
36
|
+
responses.add(
|
|
37
|
+
responses.GET,
|
|
38
|
+
url=f"{CLOUDOS_URL}/api/v3/workflows?{search_str}",
|
|
39
|
+
body=json_data,
|
|
40
|
+
headers=header,
|
|
41
|
+
match=[matchers.query_param_matcher(params)],
|
|
42
|
+
status=200)
|
|
43
|
+
# start cloudOS service
|
|
44
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
45
|
+
# get mock response
|
|
46
|
+
response = clos.detect_workflow(workspace_id=WORKSPACE_ID, workflow_name="picard")
|
|
47
|
+
assert response == 'docker'
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Pytests for function Cloudos.get_cromwell_status"""
|
|
2
|
+
import json
|
|
3
|
+
import mock
|
|
4
|
+
import pytest
|
|
5
|
+
import requests
|
|
6
|
+
import responses
|
|
7
|
+
from responses import matchers
|
|
8
|
+
from cloudos_cli.clos import Cloudos
|
|
9
|
+
from cloudos_cli.utils.errors import BadRequestException
|
|
10
|
+
from tests.functions_for_pytest import load_json_file
|
|
11
|
+
|
|
12
|
+
INPUT = "tests/test_data/process_job_list_initial_json.json"
|
|
13
|
+
APIKEY = 'vnoiweur89u2ongs'
|
|
14
|
+
CLOUDOS_URL = 'http://cloudos.lifebit.ai'
|
|
15
|
+
WORKSPACE_ID = 'lv89ufc838sdig'
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
19
|
+
@responses.activate
|
|
20
|
+
def test_get_cromwell_status_correct_response():
|
|
21
|
+
"""
|
|
22
|
+
Test 'get_cromwell_status' to work as intended
|
|
23
|
+
API request is mocked and replicated with json files
|
|
24
|
+
"""
|
|
25
|
+
create_json = load_json_file(INPUT)
|
|
26
|
+
params = {"teamId": WORKSPACE_ID}
|
|
27
|
+
header = {
|
|
28
|
+
"Accept": "application/json, text/plain, */*",
|
|
29
|
+
"Content-Type": "application/json;charset=UTF-8"
|
|
30
|
+
}
|
|
31
|
+
search_str = f"teamId={WORKSPACE_ID}"
|
|
32
|
+
# mock GET method with the .json
|
|
33
|
+
responses.add(
|
|
34
|
+
responses.GET,
|
|
35
|
+
url=f"{CLOUDOS_URL}/api/v1/cromwell?{search_str}",
|
|
36
|
+
body=create_json,
|
|
37
|
+
headers=header,
|
|
38
|
+
match=[matchers.query_param_matcher(params)],
|
|
39
|
+
status=200)
|
|
40
|
+
# start cloudOS service
|
|
41
|
+
clos = Cloudos(apikey=None, cromwell_token=APIKEY, cloudos_url=CLOUDOS_URL)
|
|
42
|
+
# get mock response
|
|
43
|
+
response = clos.get_cromwell_status(WORKSPACE_ID)
|
|
44
|
+
# check the response
|
|
45
|
+
assert response.status_code == 200
|
|
46
|
+
assert isinstance(response, requests.models.Response)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
50
|
+
@responses.activate
|
|
51
|
+
def test_get_cromwell_incorrect_response():
|
|
52
|
+
"""
|
|
53
|
+
Test 'get_cromwell_status' to fail with '400' response
|
|
54
|
+
"""
|
|
55
|
+
# prepare error message
|
|
56
|
+
error_message = {"statusCode": 400, "time": "2022-11-23_17:31:07"}
|
|
57
|
+
error_json = json.dumps(error_message)
|
|
58
|
+
params = {"teamId": WORKSPACE_ID}
|
|
59
|
+
header = {
|
|
60
|
+
"Accept": "application/json, text/plain, */*",
|
|
61
|
+
"Content-Type": "application/json;charset=UTF-8"
|
|
62
|
+
}
|
|
63
|
+
search_str = f"teamId={WORKSPACE_ID}"
|
|
64
|
+
# mock GET method with the .json
|
|
65
|
+
responses.add(
|
|
66
|
+
responses.GET,
|
|
67
|
+
url=f"{CLOUDOS_URL}/api/v1/cromwell?{search_str}",
|
|
68
|
+
body=error_json,
|
|
69
|
+
headers=header,
|
|
70
|
+
match=[matchers.query_param_matcher(params)],
|
|
71
|
+
status=400)
|
|
72
|
+
# raise 400 error
|
|
73
|
+
with pytest.raises(BadRequestException) as error:
|
|
74
|
+
# check if it failed
|
|
75
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
76
|
+
clos.get_cromwell_status(WORKSPACE_ID)
|
|
77
|
+
assert "Server returned status 400." in (str(error))
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import mock
|
|
2
|
+
import json
|
|
3
|
+
import pytest
|
|
4
|
+
import responses
|
|
5
|
+
from responses import matchers
|
|
6
|
+
from cloudos_cli.clos import Cloudos
|
|
7
|
+
from cloudos_cli.utils.errors import BadRequestException
|
|
8
|
+
from tests.functions_for_pytest import load_json_file
|
|
9
|
+
|
|
10
|
+
OUTPUT = "tests/test_data/workflows/curated_workflows.json"
|
|
11
|
+
APIKEY = 'vnoiweur89u2ongs'
|
|
12
|
+
CLOUDOS_URL = 'http://cloudos.lifebit.ai'
|
|
13
|
+
WORKSPACE_ID = 'lv89ufc838sdig'
|
|
14
|
+
PAGE = 1
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
18
|
+
@responses.activate
|
|
19
|
+
def test_get_curated_workflow_list_correct_response():
|
|
20
|
+
"""
|
|
21
|
+
Test 'get_curated_workflow_list' to work as intended
|
|
22
|
+
API request is mocked and replicated with json files
|
|
23
|
+
"""
|
|
24
|
+
create_json = load_json_file(OUTPUT)
|
|
25
|
+
params = {"teamId": WORKSPACE_ID,
|
|
26
|
+
"groups[]": ["curated", "featured", "predefined"],
|
|
27
|
+
"page": PAGE}
|
|
28
|
+
header = {
|
|
29
|
+
"Accept": "application/json, text/plain, */*",
|
|
30
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
31
|
+
"apikey": APIKEY}
|
|
32
|
+
search_str = f"search=&groups[]=curated&groups[]=featured&groups[]=predefined&page={PAGE}&teamId={WORKSPACE_ID}"
|
|
33
|
+
# mock GET method with the .json
|
|
34
|
+
responses.add(
|
|
35
|
+
responses.GET,
|
|
36
|
+
url=f"{CLOUDOS_URL}/api/v3/workflows?{search_str}",
|
|
37
|
+
body=create_json,
|
|
38
|
+
headers=header,
|
|
39
|
+
match=[matchers.query_param_matcher(params)],
|
|
40
|
+
status=200)
|
|
41
|
+
# start cloudOS service
|
|
42
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
43
|
+
# get mock response
|
|
44
|
+
response = clos.get_curated_workflow_list(WORKSPACE_ID)
|
|
45
|
+
# check the response
|
|
46
|
+
assert isinstance(response, list)
|
|
47
|
+
assert len(response) == 1
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
51
|
+
@responses.activate
|
|
52
|
+
def test_get_curated_workflow_list_incorrect_response():
|
|
53
|
+
"""
|
|
54
|
+
Test 'get_curated_workflow_list' to fail with '400' response
|
|
55
|
+
"""
|
|
56
|
+
# prepare error message
|
|
57
|
+
error_message = {"statusCode": 400, "code": "BadRequest",
|
|
58
|
+
"message": "Bad Request.", "time": "2022-11-23_17:31:07"}
|
|
59
|
+
error_json = json.dumps(error_message)
|
|
60
|
+
search_str = f"search=&groups[]=curated&groups[]=featured&groups[]=predefined&page={PAGE}&teamId={WORKSPACE_ID}"
|
|
61
|
+
# mock GET method with the .json
|
|
62
|
+
responses.add(
|
|
63
|
+
responses.GET,
|
|
64
|
+
url=f"{CLOUDOS_URL}/api/v3/workflows?{search_str}",
|
|
65
|
+
body=error_json,
|
|
66
|
+
status=400)
|
|
67
|
+
# raise 400 error
|
|
68
|
+
with pytest.raises(BadRequestException) as error:
|
|
69
|
+
# check if it failed
|
|
70
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
71
|
+
clos.get_curated_workflow_list(WORKSPACE_ID)
|
|
72
|
+
assert "Server returned status 400." in (str(error))
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import mock
|
|
2
|
+
import json
|
|
3
|
+
import pytest
|
|
4
|
+
import responses
|
|
5
|
+
from responses import matchers
|
|
6
|
+
from cloudos_cli.clos import Cloudos
|
|
7
|
+
from cloudos_cli.utils.errors import BadRequestException
|
|
8
|
+
from tests.functions_for_pytest import load_json_file
|
|
9
|
+
|
|
10
|
+
INPUT = "tests/test_data/process_job_list_initial_json.json"
|
|
11
|
+
APIKEY = 'vnoiweur89u2ongs'
|
|
12
|
+
CLOUDOS_URL = 'http://cloudos.lifebit.ai'
|
|
13
|
+
WORKSPACE_ID = 'lv89ufc838sdig'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
17
|
+
@responses.activate
|
|
18
|
+
def test_get_job_list_correct_response():
|
|
19
|
+
"""
|
|
20
|
+
Test 'get_job_list' to work as intended
|
|
21
|
+
API request is mocked and replicated with json files
|
|
22
|
+
"""
|
|
23
|
+
create_json = load_json_file(INPUT)
|
|
24
|
+
params = {"teamId": WORKSPACE_ID, "page": 1,
|
|
25
|
+
"archived.status": "false"}
|
|
26
|
+
header = {
|
|
27
|
+
"Accept": "application/json, text/plain, */*",
|
|
28
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
29
|
+
"apikey": APIKEY
|
|
30
|
+
}
|
|
31
|
+
search_str = f"teamId={WORKSPACE_ID}&page=1&archived.status=false"
|
|
32
|
+
# mock GET method with the .json
|
|
33
|
+
responses.add(
|
|
34
|
+
responses.GET,
|
|
35
|
+
url=f"{CLOUDOS_URL}/api/v2/jobs?{search_str}",
|
|
36
|
+
body=create_json,
|
|
37
|
+
headers=header,
|
|
38
|
+
match=[matchers.query_param_matcher(params)],
|
|
39
|
+
status=200)
|
|
40
|
+
# start cloudOS service
|
|
41
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
42
|
+
# get mock response
|
|
43
|
+
response = clos.get_job_list(WORKSPACE_ID, last_n_jobs=1)
|
|
44
|
+
# check the response
|
|
45
|
+
assert isinstance(response, list)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
49
|
+
@responses.activate
|
|
50
|
+
def test_get_job_list_incorrect_response():
|
|
51
|
+
"""
|
|
52
|
+
Test 'get_job_list' to fail with '400' response
|
|
53
|
+
"""
|
|
54
|
+
# prepare error message
|
|
55
|
+
error_message = {"statusCode": 400, "code": "BadRequest",
|
|
56
|
+
"message": "Bad Request.", "time": "2022-11-23_17:31:07"}
|
|
57
|
+
error_json = json.dumps(error_message)
|
|
58
|
+
params = {"teamId": WORKSPACE_ID, "page": 1,
|
|
59
|
+
"archived.status": "false"}
|
|
60
|
+
header = {
|
|
61
|
+
"Accept": "application/json, text/plain, */*",
|
|
62
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
63
|
+
"apikey": APIKEY
|
|
64
|
+
}
|
|
65
|
+
search_str = f"teamId={WORKSPACE_ID}&page=1&archived.status=false"
|
|
66
|
+
# mock GET method with the .json
|
|
67
|
+
responses.add(
|
|
68
|
+
responses.GET,
|
|
69
|
+
url=f"{CLOUDOS_URL}/api/v2/jobs?{search_str}",
|
|
70
|
+
body=error_json,
|
|
71
|
+
headers=header,
|
|
72
|
+
match=[matchers.query_param_matcher(params)],
|
|
73
|
+
status=400)
|
|
74
|
+
# raise 400 error
|
|
75
|
+
with pytest.raises(BadRequestException) as error:
|
|
76
|
+
# check if it failed
|
|
77
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
78
|
+
clos.get_job_list(WORKSPACE_ID)
|
|
79
|
+
assert "Bad Request" in (str(error))
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Pytest added for function get_job_status"""
|
|
2
|
+
import json
|
|
3
|
+
import mock
|
|
4
|
+
import pytest
|
|
5
|
+
import requests
|
|
6
|
+
import responses
|
|
7
|
+
from cloudos_cli.clos import Cloudos
|
|
8
|
+
from cloudos_cli.utils.errors import BadRequestException
|
|
9
|
+
from tests.functions_for_pytest import load_json_file
|
|
10
|
+
|
|
11
|
+
INPUT = "tests/test_data/get_job_status.json"
|
|
12
|
+
APIKEY = 'vnoiweur89u2ongs'
|
|
13
|
+
CLOUDOS_URL = 'http://cloudos.lifebit.ai'
|
|
14
|
+
JOB_ID = "616ee9681b866a01d69fa1cd"
|
|
15
|
+
JOB_STATUS = "running"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
19
|
+
@responses.activate
|
|
20
|
+
def test_get_job_status_correct_response():
|
|
21
|
+
"""
|
|
22
|
+
Test 'get_job_status' to work as intended
|
|
23
|
+
API request is mocked and replicated with json files
|
|
24
|
+
"""
|
|
25
|
+
create_json = load_json_file(INPUT)
|
|
26
|
+
header = {
|
|
27
|
+
"Content-type": "application/json",
|
|
28
|
+
"apikey": APIKEY
|
|
29
|
+
}
|
|
30
|
+
# mock GET method with the .json
|
|
31
|
+
responses.add(
|
|
32
|
+
responses.GET,
|
|
33
|
+
url=f"{CLOUDOS_URL}/api/v1/jobs/{JOB_ID}",
|
|
34
|
+
body=create_json,
|
|
35
|
+
headers=header,
|
|
36
|
+
status=200)
|
|
37
|
+
# start cloudOS service
|
|
38
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
39
|
+
# get mock response
|
|
40
|
+
response = clos.get_job_status(j_id=JOB_ID)
|
|
41
|
+
# check the response
|
|
42
|
+
result_string = response.content.decode("utf-8")
|
|
43
|
+
result_json = json.loads(result_string)
|
|
44
|
+
assert result_json["status"] == JOB_STATUS
|
|
45
|
+
assert response.status_code == 200
|
|
46
|
+
assert isinstance(response, requests.models.Response)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
50
|
+
@responses.activate
|
|
51
|
+
def test_get_job_status_incorrect_response():
|
|
52
|
+
"""
|
|
53
|
+
Test 'get_job_status' to fail with '400' response
|
|
54
|
+
"""
|
|
55
|
+
# prepare error message
|
|
56
|
+
error_message = {"statusCode": 400, "code": "BadRequest",
|
|
57
|
+
"message": "Bad Request.", "time": "2022-11-23_17:31:07"}
|
|
58
|
+
error_json = json.dumps(error_message)
|
|
59
|
+
header = {
|
|
60
|
+
"Content-type": "application/json",
|
|
61
|
+
"apikey": APIKEY
|
|
62
|
+
}
|
|
63
|
+
# mock GET method with the .json
|
|
64
|
+
responses.add(
|
|
65
|
+
responses.GET,
|
|
66
|
+
url=f"{CLOUDOS_URL}/api/v1/jobs/{JOB_ID}",
|
|
67
|
+
body=error_json,
|
|
68
|
+
headers=header,
|
|
69
|
+
status=400)
|
|
70
|
+
# raise 400 error
|
|
71
|
+
with pytest.raises(BadRequestException) as error:
|
|
72
|
+
# check if it failed
|
|
73
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
74
|
+
clos.get_job_status(JOB_ID)
|
|
75
|
+
assert "Bad Request" in (str(error))
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import mock
|
|
2
|
+
import json
|
|
3
|
+
import pytest
|
|
4
|
+
import requests
|
|
5
|
+
import responses
|
|
6
|
+
from responses import matchers
|
|
7
|
+
from cloudos_cli.clos import Cloudos
|
|
8
|
+
from cloudos_cli.utils.errors import BadRequestException
|
|
9
|
+
|
|
10
|
+
APIKEY = 'vnoiweur89u2ongs'
|
|
11
|
+
CLOUDOS_URL = 'http://cloudos.lifebit.ai'
|
|
12
|
+
WORKSPACE_ID = 'lv89ufc838sdig'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
16
|
+
@responses.activate
|
|
17
|
+
def test_get_project_list_correct_response():
|
|
18
|
+
"""
|
|
19
|
+
Test 'get_project_list' to work as intended
|
|
20
|
+
"""
|
|
21
|
+
params = {"teamId": WORKSPACE_ID}
|
|
22
|
+
header = {
|
|
23
|
+
"Accept": "application/json, text/plain, */*",
|
|
24
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
25
|
+
"apikey": APIKEY
|
|
26
|
+
}
|
|
27
|
+
search_str = f"teamId={WORKSPACE_ID}"
|
|
28
|
+
# mock GET method with the .json
|
|
29
|
+
responses.add(
|
|
30
|
+
responses.GET,
|
|
31
|
+
url=f"{CLOUDOS_URL}/api/v1/projects?{search_str}",
|
|
32
|
+
headers=header,
|
|
33
|
+
match=[matchers.query_param_matcher(params)],
|
|
34
|
+
status=200)
|
|
35
|
+
# start cloudOS service
|
|
36
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
37
|
+
# get mock response
|
|
38
|
+
response = clos.get_project_list(WORKSPACE_ID)
|
|
39
|
+
# check the response
|
|
40
|
+
assert response.status_code == 200
|
|
41
|
+
assert isinstance(response, requests.models.Response)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@mock.patch('cloudos_cli.clos', mock.MagicMock())
|
|
45
|
+
@responses.activate
|
|
46
|
+
def test_get_project_list_incorrect_response():
|
|
47
|
+
"""
|
|
48
|
+
Test 'get_project_list' to fail with '400' response
|
|
49
|
+
"""
|
|
50
|
+
# prepare error message
|
|
51
|
+
error_message = {"statusCode": 400, "code": "BadRequest",
|
|
52
|
+
"message": "Bad Request.", "time": "2022-11-23_17:31:07"}
|
|
53
|
+
error_json = json.dumps(error_message)
|
|
54
|
+
params = {"teamId": WORKSPACE_ID}
|
|
55
|
+
header = {
|
|
56
|
+
"Accept": "application/json, text/plain, */*",
|
|
57
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
58
|
+
"apikey": APIKEY
|
|
59
|
+
}
|
|
60
|
+
search_str = f"teamId={WORKSPACE_ID}"
|
|
61
|
+
# mock GET method with the .json
|
|
62
|
+
responses.add(
|
|
63
|
+
responses.GET,
|
|
64
|
+
url=f"{CLOUDOS_URL}/api/v1/projects?{search_str}",
|
|
65
|
+
body=error_json,
|
|
66
|
+
headers=header,
|
|
67
|
+
match=[matchers.query_param_matcher(params)],
|
|
68
|
+
status=400)
|
|
69
|
+
# raise 400 error
|
|
70
|
+
with pytest.raises(BadRequestException) as error:
|
|
71
|
+
# check if it failed
|
|
72
|
+
clos = Cloudos(apikey=APIKEY, cromwell_token=None, cloudos_url=CLOUDOS_URL)
|
|
73
|
+
clos.get_project_list(WORKSPACE_ID)
|
|
74
|
+
assert "Server returned status 400." in (str(error))
|