Commit 64d30ff4 authored by abuddenberg's avatar abuddenberg
Browse files

Fixed bug in one of GcisClient's credentials modes. Added test case for same

parent c9b579ef
......@@ -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'
......
......@@ -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_contributors()
test_get_credentials_modes()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment