Skip to content

Commit

Permalink
Update connection parameters (#239)
Browse files Browse the repository at this point in the history
* Update default user/dbname

As per the new changes in core, update default user name and database name to admin and omnisci respectively
Similar updates to documentation
Update connection parameters unit tests

* Fix dashboard test to rerun them successfully

* Fix test error handling

* Update additional fields add omnisci dbname

* flake8 fixes
  • Loading branch information
wamsiv committed Jun 19, 2019
1 parent 4297568 commit 0028b9d
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 60 deletions.
4 changes: 2 additions & 2 deletions docs/source/index.rst
Expand Up @@ -13,8 +13,8 @@ the `Apache Arrow`_-based `cudf GPU DataFrame`_ format for efficient data interc
.. code-block:: python
>>> from pymapd import connect
>>> con = connect(user="mapd", password="HyperInteractive", host="localhost",
... dbname="mapd")
>>> con = connect(user="admin", password="HyperInteractive", host="localhost",
... dbname="omnisci")
>>> df = con.select_ipc_gpu("SELECT depdelay, arrdelay"
... "FROM flights_2008_10k"
... "LIMIT 100")
Expand Down
14 changes: 7 additions & 7 deletions docs/source/usage.rst
Expand Up @@ -73,19 +73,19 @@ To create a :class:`Connection` using the ``connect()`` method along with ``user
.. code-block:: python
>>> from pymapd import connect
>>> con = connect(user="mapd", password="HyperInteractive", host="localhost",
... dbname="mapd")
>>> con = connect(user="admin", password="HyperInteractive", host="localhost",
... dbname="omnisci")
>>> con
Connection(mapd://mapd:***@localhost:6274/mapd?protocol=binary)
Connection(mapd://admin:***@localhost:6274/omnisci?protocol=binary)
Alternatively, you can pass in a `SQLAlchemy`_-compliant connection string to
the ``connect()`` method:

.. code-block:: python
>>> uri = "mapd://mapd:HyperInteractive@localhost:6274/mapd?protocol=binary"
>>> uri = "mapd://admin:HyperInteractive@localhost:6274/omnisci?protocol=binary"
>>> con = connect(uri=uri)
Connection(mapd://mapd:***@localhost:6274/mapd?protocol=binary)
Connection(mapd://admin:***@localhost:6274/omnisci?protocol=binary)
OmniSci Cloud
*************
Expand Down Expand Up @@ -170,8 +170,8 @@ install, ``pandas.read_sql()`` works everywhere):
>>> from pymapd import connect
>>> import pandas as pd
>>> con = connect(user="mapd", password="HyperInteractive", host="localhost",
... dbname="mapd")
>>> con = connect(user="admin", password="HyperInteractive", host="localhost",
... dbname="omnisci")
>>> df = pd.read_sql("SELECT depdelay, arrdelay FROM flights_2008_10k limit 100", con)
Expand Down
10 changes: 5 additions & 5 deletions pymapd/connection.py
Expand Up @@ -67,12 +67,12 @@ def connect(uri=None,
You can either pass a string ``uri``, all the individual components,
or an existing sessionid excluding user, password, and database
>>> connect('mapd://mapd:HyperInteractive@localhost:6274/mapd?'
>>> connect('mapd://admin:HyperInteractive@localhost:6274/omnisci?'
... 'protocol=binary')
Connection(mapd://mapd:***@localhost:6274/mapd?protocol=binary)
>>> connect(user='mapd', password='HyperInteractive', host='localhost',
... port=6274, dbname='mapd')
>>> connect(user='admin', password='HyperInteractive', host='localhost',
... port=6274, dbname='omnisci')
>>> connect(sessionid='XihlkjhdasfsadSDoasdllMweieisdpo', host='localhost',
... port=6273, protocol='http')
Expand Down Expand Up @@ -206,8 +206,8 @@ def __init__(self,
"for more details.")

def __repr__(self):
tpl = ('Connection(mapd://{user}:***@{host}:{port}/{dbname}?protocol'
'={protocol})')
tpl = ('Connection(omnisci://{user}:***@{host}:{port}/{dbname}?'
'protocol={protocol})')
return tpl.format(user=self._user, host=self._host, port=self._port,
dbname=self._dbname, protocol=self._protocol)

Expand Down
4 changes: 2 additions & 2 deletions scripts/bench.py
Expand Up @@ -218,9 +218,9 @@ def main(args=None):
logger.addHandler(fh)

con = pymapd.connect(
user='mapd',
user='admin',
password='HyperInteractive',
dbname='mapd',
dbname='omnisci',
host='localhost')

grid = product(selects.keys(), _benchmarks)
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Expand Up @@ -51,8 +51,8 @@ def con(mapd_server):
"""
Fixture to provide Connection for tests run against live OmniSci instance
"""
return connect(user="mapd", password='HyperInteractive', host='localhost',
port=6274, protocol='binary', dbname='mapd')
return connect(user="admin", password='HyperInteractive', host='localhost',
port=6274, protocol='binary', dbname='omnisci')


@pytest.fixture
Expand Down
16 changes: 8 additions & 8 deletions tests/test_connection.py
Expand Up @@ -19,8 +19,8 @@ def test_raises_right_exception(self):
connect(host='localhost', protocol='binary', port=1234)

def test_close(self):
conn = connect(user='mapd', password='HyperInteractive',
host='localhost', dbname='mapd')
conn = connect(user='admin', password='HyperInteractive',
host='localhost', dbname='omnisci')
assert conn.closed == 0
conn.close()
assert conn.closed == 1
Expand All @@ -36,8 +36,8 @@ def test_bad_protocol(self, mock_client):
assert m.match('fake-proto')

def test_session_logon_success(self):
conn = connect(user='mapd', password='HyperInteractive',
host='localhost', dbname='mapd')
conn = connect(user='admin', password='HyperInteractive',
host='localhost', dbname='omnisci')
sessionid = conn._session
connnew = connect(sessionid=sessionid, host='localhost')
assert connnew._session == sessionid
Expand All @@ -51,15 +51,15 @@ def test_session_logon_failure(self):
class TestURI:

def test_parse_uri(self):
uri = ('mapd://mapd:HyperInteractive@localhost:6274/mapd?'
uri = ('omnisci://admin:HyperInteractive@localhost:6274/omnisci?'
'protocol=binary')
result = _parse_uri(uri)
expected = ConnectionInfo("mapd", "HyperInteractive", "localhost",
6274, "mapd", "binary")
expected = ConnectionInfo("admin", "HyperInteractive", "localhost",
6274, "omnisci", "binary")
assert result == expected

def test_both_raises(self):
uri = ('mapd://mapd:HyperInteractive@localhost:6274/mapd?'
uri = ('omnisci://admin:HyperInteractive@localhost:6274/omnisci?'
'protocol=binary')
with pytest.raises(TypeError):
connect(uri=uri, user='my user')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_deallocate.py
Expand Up @@ -17,10 +17,10 @@ def _data(self):

def _connect(self):

return connect(user="mapd",
return connect(user="admin",
password='HyperInteractive',
host='localhost',
port=6274, protocol='binary', dbname='mapd')
port=6274, protocol='binary', dbname='omnisci')

def _transact(self, con):
drop = 'drop table if exists iris;'
Expand Down
82 changes: 50 additions & 32 deletions tests/test_integration.py
Expand Up @@ -29,33 +29,33 @@
class TestIntegration:

def test_connect_binary(self):
con = connect(user="mapd", password='HyperInteractive',
con = connect(user="admin", password='HyperInteractive',
host='localhost', port=6274, protocol='binary',
dbname='mapd')
dbname='omnisci')
assert con is not None

def test_connect_http(self):
con = connect(user="mapd", password='HyperInteractive',
con = connect(user="admin", password='HyperInteractive',
host='localhost', port=6278, protocol='http',
dbname='mapd')
dbname='omnisci')
assert con is not None

def test_connect_uri(self):
uri = ('mapd://mapd:HyperInteractive@localhost:6274/mapd?protocol='
'binary')
uri = ('omnisci://admin:HyperInteractive@localhost:6274/omnisci?'
'protocol=binary')
con = connect(uri=uri)
assert con._user == 'mapd'
assert con._user == 'admin'
assert con._password == 'HyperInteractive'
assert con._host == 'localhost'
assert con._port == 6274
assert con._dbname == 'mapd'
assert con._dbname == 'omnisci'
assert con._protocol == 'binary'

def test_connect_uri_and_others_raises(self):
uri = ('mapd://mapd:HyperInteractive@localhost:6274/mapd?protocol='
'binary')
uri = ('omnisci://admin:HyperInteractive@localhost:6274/omnisci?'
'protocol=binary')
with pytest.raises(TypeError):
connect(username='mapd', uri=uri)
connect(username='omnisci', uri=uri)

def test_invalid_sql(self, con):
with pytest.raises(ProgrammingError) as r:
Expand Down Expand Up @@ -337,35 +337,53 @@ def test_dashboard_duplication_remap(self, con):
"title": new_dashboard_name
}
}
dashboard_id = ""
dashboards = []

# Create testing dashboard
con._client.create_dashboard(
session=con._session,
dashboard_name=old_dashboard_name,
dashboard_state=(
base64.b64encode(json.dumps(old_dashboard_state).encode(
"utf-8"))),
image_hash="",
dashboard_metadata=json.dumps(meta_data),
)

# Grab our testing dashboard id from the database
dashboards = con._client.get_dashboards(session=con._session)
for dashboard in dashboards:
if dashboard.dashboard_name == old_dashboard_name:
dashboard_id = dashboard.dashboard_id
try:
dashboard_id = con._client.create_dashboard(
session=con._session,
dashboard_name=old_dashboard_name,
dashboard_state=(
base64.b64encode(json.dumps(old_dashboard_state).encode(
"utf-8"))),
image_hash="",
dashboard_metadata=json.dumps(meta_data),
)
except TMapDException:
dashboards = con._client.get_dashboards(con._session)
for dash in dashboards:
if dash.dashboard_name == old_dashboard_name:
con._client.delete_dashboard(con._session,
dash.dashboard_id)
break
dashboard_id = con._client.create_dashboard(
session=con._session,
dashboard_name=old_dashboard_name,
dashboard_state=(
base64.b64encode(json.dumps(old_dashboard_state).encode(
"utf-8"))),
image_hash="",
dashboard_metadata=json.dumps(meta_data),
)

# Duplicate and remap our dashboard
con.duplicate_dashboard(
try:
dashboard_id = con.duplicate_dashboard(
dashboard_id, new_dashboard_name, remap
)
except TMapDException:
dashboards = con._client.get_dashboards(con._session)
for dash in dashboards:
if dash.dashboard_name == new_dashboard_name:
con._client.delete_dashboard(con._session,
dash.dashboard_id)
break
dashboard_id = con.duplicate_dashboard(
dashboard_id, new_dashboard_name, remap
)

# Get our new dashboard from the database
dashboards = con._client.get_dashboards(session=con._session)
for dashboard in dashboards:
if dashboard.dashboard_name == new_dashboard_name:
dashboard_id = dashboard.dashboard_id
d = con._client.get_dashboard(
session=con._session,
dashboard_id=dashboard_id
Expand Down

0 comments on commit 0028b9d

Please sign in to comment.