Skip to content

Commit

Permalink
FF-373 #comment check is part of connection
Browse files Browse the repository at this point in the history
  • Loading branch information
KorayKirli committed Dec 7, 2016
1 parent 3efebd6 commit 5f0f80a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
19 changes: 7 additions & 12 deletions tests/test_fdnDCIC.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@

keypairs = {
"default":
{"server": "https://test.FDN.org",
"key": "keystring",
"secret": "secretstring"
},
"wrong_key":
{"server": "https://data.4dnucleome.org/",
"key": "keystring",
"secret": "secretstring"
},
}
}


Expand Down Expand Up @@ -47,9 +42,9 @@ def test_connection():


def test_test_connection_fail():
key = fdnDCIC.FDN_Key(keypairs, "wrong_key")
key = fdnDCIC.FDN_Key(keypairs, "default")
connection = fdnDCIC.FDN_Connection(key)
assert fdnDCIC.test_Connection_fail(connection) is True
assert connection.check is False


def test_FDN_url():
Expand All @@ -60,10 +55,10 @@ def test_FDN_url():
["trial", "object"],
["trial?some", "object"]
]
expected_url = ["https://test.FDN.org/trial?limit=all",
"https://test.FDN.org/trial?some&limit=all",
"https://test.FDN.org/trial?limit=all&frame=object",
"https://test.FDN.org/trial?some&limit=all&frame=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 = fdnDCIC.FDN_url(case[0], connection, case[1])
Expand Down
12 changes: 6 additions & 6 deletions wranglertools/fdnDCIC.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def __init__(self, key):
self.auth = ()
else:
self.auth = (key.authid, key.authpw)


def test_Connection_fail(connection):
r = requests.get(connection.server, auth=connection.auth)
if r.status_code != 200:
return True
# check connection and find user uuid
me_page = self.server + 'me'
r = requests.get(me_page, auth=self.auth)
self.check = False
if r.status_code == 200:
self.check = True


class FDN_Schema(object):
Expand Down
2 changes: 1 addition & 1 deletion wranglertools/get_field_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def main(): # pragma: no cover
key = fdnDCIC.FDN_Key(args.keyfile, args.key)
connection = fdnDCIC.FDN_Connection(key)
# test connection
if fdnDCIC.test_Connection_fail(connection):
if not connection.check:
print("CONNECTION ERROR: Please check your keys.")
return
fields = get_uploadable_fields(connection, args.type,
Expand Down
2 changes: 1 addition & 1 deletion wranglertools/import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def main(): # pragma: no cover
connection = fdnDCIC.FDN_Connection(key)
print("Running on {server}".format(server=connection.server))
# test connection
if fdnDCIC.test_Connection_fail(connection):
if not connection.check:
print("CONNECTION ERROR: Please check your keys.")
return
# check input file (xls)
Expand Down

0 comments on commit 5f0f80a

Please sign in to comment.