Skip to content

Commit

Permalink
Merge 23ccb05 into 34ca664
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-esch committed Dec 8, 2017
2 parents 34ca664 + 23ccb05 commit 7670d27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions cartoframes/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,24 @@ def __init__(self, base_url=None, api_key=None, creds=None, session=None,
session=session)
self.sql_client = SQLClient(self.auth_client)
self.creds.username(self.auth_client.username)
self._is_authenticated()
self.is_org = self._is_org_user()

self._map_templates = {}
self._srcdoc = None
self._verbose = verbose

def _is_authenticated(self):
"""Checks if credentials allow for authenticated carto access"""
try:
self.sql_client.send(
'select * from information_schema.tables limit 0')
except CartoException as err:
raise CartoException('Cannot authenticate user `{0}`. Check '
'credentials ({1}).'.format(
self.creds.username(),
err))

def _is_org_user(self):
"""Report whether user is in a multiuser CARTO organization or not"""
res = self.sql_client.send('SHOW search_path', **DEFAULT_SQL_ARGS)
Expand Down
6 changes: 3 additions & 3 deletions test/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def test_cartocontext(self):
self.assertEqual(cc.creds.base_url(), self.baseurl.strip('/'))
self.assertEqual(cc.creds.username(), self.username)
self.assertTrue(not cc.is_org)
# TODO: how to test instances of a class?
# self.assertTrue(cc.auth_client.__dict__ == self.auth_client.__dict__)
# self.assertTrue(cc.sql_client.__dict__ == self.sql_client.__dict__)
with self.assertRaises(CartoException):
cartoframes.CartoContext(base_url=self.baseurl,
api_key='notavalidkey')

@unittest.skipIf(WILL_SKIP, 'no carto credentials, skipping this test')
def test_cartocontext_credentials(self):
Expand Down

0 comments on commit 7670d27

Please sign in to comment.