Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_connection_success(mocker, mkey, returned_user_me_submit_for_one_lab,
returned_lab_w_one_award):
email = 'bil022@ucsd.edu'
lab2chk = '/labs/bing-ren-lab/'
awd2chk = '/awards/1U54DK107977-01/'
with mocker.patch('dcicutils.submit_utils.requests.get',
side_effect=[returned_user_me_submit_for_one_lab,
returned_lab_w_one_award]):
connection = submit_utils.FDN_Connection(mkey)
assert connection.check is True
assert connection.email == email
assert lab2chk in connection.labs
assert connection.lab == lab2chk
assert connection.award == awd2chk
def test_connection_prompt_for_lab_award_multi_lab_award(
mocker, monkeypatch, mkey, returned_user_me_submit_for_two_labs,
returned_lab_w_two_awards, returned_otherlab_w_two_awards):
defaultlab = '/labs/bing-ren-lab/'
defaultaward = '/awards/1U54DK107977-01/'
chosenlab = '/labs/ben-ring-lab/'
chosenaward = '/awards/7777777/'
with mocker.patch('dcicutils.submit_utils.requests.get',
side_effect=[returned_user_me_submit_for_two_labs,
returned_lab_w_two_awards,
returned_otherlab_w_two_awards]):
connection = submit_utils.FDN_Connection(mkey)
assert connection.lab == defaultlab
assert connection.award == defaultaward
# monkeypatch the "input" function, so that it returns "2".
# This simulates the user entering "2" in the terminal:
monkeypatch.setitem(__builtins__, 'input', lambda x: "2")
connection.prompt_for_lab_award()
assert connection.lab == chosenlab
assert connection.award == chosenaward
def test_FDN_url():
key = submit_utils.FDN_Key(keypairs, "default")
connection = submit_utils.FDN_Connection(key)
test_objid_frame = [["trial", None],
["trial?some", None],
["trial", "object"],
["trial?some", "object"]
]
expected_url = ["https://data.4dnucleome.org/trial?limit=all",
"https://data.4dnucleome.org/trial?some&limit=all",
"https://data.4dnucleome.org/trial?limit=all&frame=object",
"https://data.4dnucleome.org/trial?some&limit=all&frame=object"
]
for n, case in enumerate(test_objid_frame):
t_url = submit_utils.FDN_url(case[0], connection, case[1])
assert t_url == expected_url[n]
def test_connection():
key = submit_utils.FDN_Key(keypairs, "default")
connection = submit_utils.FDN_Connection(key)
assert(connection)
assert(connection.auth)
assert(connection.server)
def test_connection_prompt_for_lab_award_multi_lab(
mocker, monkeypatch, mkey, returned_user_me_submit_for_two_labs,
returned_lab_w_one_award, returned_otherlab_w_one_award):
defaultlab = '/labs/bing-ren-lab/'
defaultaward = '/awards/1U54DK107977-01/'
chosenlab = '/labs/ben-ring-lab/'
chosenaward = '/awards/1U01ES017166-01/'
with mocker.patch('dcicutils.submit_utils.requests.get',
side_effect=[returned_user_me_submit_for_two_labs,
returned_lab_w_one_award,
returned_otherlab_w_one_award]):
connection = submit_utils.FDN_Connection(mkey)
assert connection.lab == defaultlab
assert connection.award == defaultaward
# monkeypatch the "input" function, so that it returns "2".
# This simulates the user entering "2" in the terminal:
monkeypatch.setitem(__builtins__, 'input', lambda x: "2")
connection.prompt_for_lab_award()
assert connection.lab == chosenlab
assert connection.award == chosenaward
def test_test_connection_fail():
key = submit_utils.FDN_Key(keypairs, "default")
connection = submit_utils.FDN_Connection(key)
assert connection.check is False
def test_connection_prompt_for_lab_award_no_prompt_for_one_each(
mocker, mkey, returned_user_me_submit_for_one_lab,
returned_lab_w_one_award):
lab2chk = '/labs/bing-ren-lab/'
awd2chk = '/awards/1U54DK107977-01/'
with mocker.patch('dcicutils.submit_utils.requests.get',
side_effect=[returned_user_me_submit_for_one_lab,
returned_lab_w_one_award,
returned_lab_w_one_award]):
connection = submit_utils.FDN_Connection(mkey)
connection.prompt_for_lab_award()
assert connection.lab == lab2chk
assert connection.award == awd2chk
def test_connection_for_user_with_no_submits_for(
mocker, mkey, returned_user_me_submit_for_no_lab):
with mocker.patch('dcicutils.submit_utils.requests.get',
return_value=returned_user_me_submit_for_no_lab):
connection = submit_utils.FDN_Connection(mkey)
assert connection.check is True
assert not connection.labs
def test_connection_prompt_for_lab_award_multi_award(
mocker, monkeypatch, mkey, returned_user_me_submit_for_one_lab,
returned_lab_w_two_awards):
'''this not only tests if the correct award is chosen if given the
choice but also that multiple awards are linked
to a lab the first is set as the defaul on init
'''
defaultlab = '/labs/bing-ren-lab/'
defaultaward = '/awards/1U54DK107977-01/'
chosenaward = '/awards/1U01ES017166-01/'
with mocker.patch('dcicutils.submit_utils.requests.get',
side_effect=[returned_user_me_submit_for_one_lab,
returned_lab_w_two_awards,
returned_lab_w_two_awards]):
connection = submit_utils.FDN_Connection(mkey)
assert connection.lab == defaultlab
assert connection.award == defaultaward
# monkeypatch the "input" function, so that it returns "2".
# This simulates the user entering "2" in the terminal:
monkeypatch.setitem(__builtins__, 'input', lambda x: "2")
connection.prompt_for_lab_award()
assert connection.lab == defaultlab
assert connection.award == chosenaward