Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andrew Buddenberg
gcis-py-client
Commits
64d30ff4
Commit
64d30ff4
authored
Sep 04, 2014
by
abuddenberg
Browse files
Fixed bug in one of GcisClient's credentials modes. Added test case for same
parent
c9b579ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
gcis_clients/gcis_client.py
View file @
64d30ff4
...
...
@@ -90,7 +90,7 @@ class GcisClient(object):
#User provides url, username, and key
elif
len
(
args
)
==
3
:
self
.
base_url
=
args
[
0
]
username
,
api_key
=
=
args
[
1
:
3
]
username
,
api_key
=
args
[
1
:
3
]
#User provides none or inconsistent args
else
:
print
'Using http://data.globalchange.gov'
...
...
gcis_clients/test/test_suite.py
View file @
64d30ff4
...
...
@@ -10,12 +10,69 @@ import pytest
from
test_data
import
test_figure_json
,
test_image_json
,
webform_json_precip
,
test_dataset_json
from
gcis_clients.domain
import
Gcisbase
,
Figure
,
Image
,
Dataset
,
Chapter
,
Contributor
from
gcis_clients
import
GcisClient
import
__builtin__
from
os
import
getenv
import
gcis_clients
def
test_gcis_client_version
():
assert
True
def
test_gcis_client_init_modes
(
monkeypatch
,
capsys
):
test_user
=
'test.user@domain.com'
test_apikey
=
'testkey'
monkeypatch
.
setattr
(
__builtin__
,
'raw_input'
,
lambda
u
:
test_user
)
monkeypatch
.
setattr
(
'getpass.getpass'
,
lambda
k
:
test_apikey
)
#Test no args
gcis
=
GcisClient
()
out
,
err
=
capsys
.
readouterr
()
assert
out
==
'Using http://data.globalchange.gov
\n
'
assert
gcis
.
base_url
==
'http://data.globalchange.gov'
assert
gcis
.
s
.
auth
==
(
test_user
,
test_apikey
)
#Test one arg (url) mode
gcis
=
GcisClient
(
'http://data.gcis-dev-front.joss.ucar.edu'
)
assert
gcis
.
base_url
==
'http://data.gcis-dev-front.joss.ucar.edu'
assert
gcis
.
s
.
auth
==
(
test_user
,
test_apikey
)
#Test invalid mode
gcis
=
GcisClient
(
'http://data.globalchange.gov'
,
'garbage'
)
assert
gcis
.
base_url
==
'http://data.globalchange.gov'
#assert garbage was ignored
assert
gcis
.
s
.
auth
==
(
test_user
,
test_apikey
)
#Test all three args mode
gcis
=
GcisClient
(
'http://data.globalchange.gov'
,
test_user
,
test_apikey
)
assert
gcis
.
base_url
==
'http://data.globalchange.gov'
assert
gcis
.
s
.
auth
==
(
test_user
,
test_apikey
)
def
test_get_credentials_modes
(
monkeypatch
):
test_user
=
'test.user@domain.com'
test_apikey
=
'testkey'
monkeypatch
.
setattr
(
__builtin__
,
'raw_input'
,
lambda
u
:
test_user
)
monkeypatch
.
setattr
(
'getpass.getpass'
,
lambda
k
:
test_apikey
)
#Test environment variable mode
monkeypatch
.
setenv
(
'GCIS_USER'
,
'env.user@domain.com'
)
monkeypatch
.
setenv
(
'GCIS_KEY'
,
'env.apikey'
)
assert
getenv
(
'GCIS_USER'
)
==
'env.user@domain.com'
#Force __init__ to reread mock env variables
reload
(
gcis_clients
)
gcis
=
GcisClient
(
'http://data.globalchange.gov'
)
assert
gcis
.
base_url
==
'http://data.globalchange.gov'
assert
gcis
.
s
.
auth
==
(
'env.user@domain.com'
,
'env.apikey'
)
def
test_domain
():
f
=
Figure
(
json
.
loads
(
test_figure_json
))
...
...
@@ -117,4 +174,4 @@ def test_dataset_special_properties():
if
__name__
==
"__main__"
and
__package__
is
None
:
__package__
=
"gcis_client.test.test_suite"
#
test_
contributor
s()
test_
get_credentials_mode
s
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment