-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from rethinkdb/support-db-url-schemas
Implement DB URL connection support
- Loading branch information
Showing
5 changed files
with
275 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import pytest | ||
|
||
from rethinkdb import r | ||
from tests.helpers import IntegrationTestCaseBase, INTEGRATION_TEST_DB | ||
|
||
|
||
@pytest.mark.integration | ||
class TestConnect(IntegrationTestCaseBase): | ||
def setup_method(self): | ||
super(TestConnect, self).setup_method() | ||
|
||
def test_connect(self): | ||
db_url = "rethinkdb://{host}".format(host=self.rethinkdb_host) | ||
|
||
assert self.r.connect(url=db_url) is not None | ||
|
||
def test_connect_with_username(self): | ||
db_url = "rethinkdb://admin@{host}".format(host=self.rethinkdb_host) | ||
|
||
assert self.r.connect(url=db_url) is not None | ||
|
||
def test_connect_to_db(self): | ||
db_url = "rethinkdb://{host}/{database}".format( | ||
host=self.rethinkdb_host, | ||
database=INTEGRATION_TEST_DB | ||
) | ||
|
||
assert self.r.connect(url=db_url) is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
import pytest | ||
from mock import Mock, ANY | ||
from rethinkdb.net import make_connection, DefaultConnection, DEFAULT_PORT | ||
|
||
|
||
@pytest.mark.unit | ||
class TestMakeConnection(object): | ||
def setup_method(self): | ||
self.reconnect = Mock() | ||
self.conn_type = Mock() | ||
self.conn_type.return_value.reconnect.return_value = self.reconnect | ||
|
||
self.host = "myhost" | ||
self.port = 1234 | ||
self.db = "mydb" | ||
self.auth_key = None | ||
self.user = "gabor" | ||
self.password = "strongpass" | ||
self.timeout = 20 | ||
|
||
|
||
def test_make_connection(self): | ||
ssl = dict() | ||
_handshake_version = 10 | ||
|
||
conn = make_connection( | ||
self.conn_type, | ||
host=self.host, | ||
port=self.port, | ||
db=self.db, | ||
auth_key=self.auth_key, | ||
user=self.user, | ||
password=self.password, | ||
timeout=self.timeout, | ||
) | ||
|
||
assert conn == self.reconnect | ||
self.conn_type.assert_called_once_with( | ||
self.host, | ||
self.port, | ||
self.db, | ||
self.auth_key, | ||
self.user, | ||
self.password, | ||
self.timeout, | ||
ssl, | ||
_handshake_version | ||
) | ||
|
||
|
||
def test_make_connection_db_url(self): | ||
url = "rethinkdb://gabor:strongpass@myhost:1234/mydb?auth_key=mykey&timeout=30" | ||
ssl = dict() | ||
_handshake_version = 10 | ||
|
||
conn = make_connection(self.conn_type, url=url) | ||
|
||
assert conn == self.reconnect | ||
self.conn_type.assert_called_once_with( | ||
self.host, | ||
self.port, | ||
self.db, | ||
"mykey", | ||
self.user, | ||
self.password, | ||
30, | ||
ssl, | ||
_handshake_version | ||
) | ||
|
||
|
||
def test_make_connection_no_host(self): | ||
conn = make_connection( | ||
self.conn_type, | ||
port=self.port, | ||
db=self.db, | ||
auth_key=self.auth_key, | ||
user=self.user, | ||
password=self.password, | ||
timeout=self.timeout, | ||
) | ||
|
||
assert conn == self.reconnect | ||
self.conn_type.assert_called_once_with( | ||
"localhost", | ||
self.port, | ||
self.db, | ||
self.auth_key, | ||
self.user, | ||
self.password, | ||
self.timeout, | ||
ANY, | ||
ANY | ||
) | ||
|
||
|
||
def test_make_connection_no_port(self): | ||
conn = make_connection( | ||
self.conn_type, | ||
host=self.host, | ||
db=self.db, | ||
auth_key=self.auth_key, | ||
user=self.user, | ||
password=self.password, | ||
timeout=self.timeout, | ||
) | ||
|
||
assert conn == self.reconnect | ||
self.conn_type.assert_called_once_with( | ||
self.host, | ||
DEFAULT_PORT, | ||
self.db, | ||
self.auth_key, | ||
self.user, | ||
self.password, | ||
self.timeout, | ||
ANY, | ||
ANY | ||
) | ||
|
||
|
||
def test_make_connection_no_user(self): | ||
conn = make_connection( | ||
self.conn_type, | ||
host=self.host, | ||
port=self.port, | ||
db=self.db, | ||
auth_key=self.auth_key, | ||
password=self.password, | ||
timeout=self.timeout, | ||
) | ||
|
||
assert conn == self.reconnect | ||
self.conn_type.assert_called_once_with( | ||
self.host, | ||
self.port, | ||
self.db, | ||
self.auth_key, | ||
"admin", | ||
self.password, | ||
self.timeout, | ||
ANY, | ||
ANY | ||
) | ||
|
||
|
||
def test_make_connection_with_ssl(self): | ||
ssl = dict() | ||
|
||
conn = make_connection( | ||
self.conn_type, | ||
host=self.host, | ||
port=self.port, | ||
db=self.db, | ||
auth_key=self.auth_key, | ||
user=self.user, | ||
password=self.password, | ||
timeout=self.timeout, | ||
ssl=ssl, | ||
) | ||
|
||
assert conn == self.reconnect | ||
self.conn_type.assert_called_once_with( | ||
self.host, | ||
self.port, | ||
self.db, | ||
self.auth_key, | ||
self.user, | ||
self.password, | ||
self.timeout, | ||
ssl, | ||
ANY | ||
) | ||
|
||
|
||
def test_make_connection_different_handshake_version(self): | ||
conn = make_connection( | ||
self.conn_type, | ||
host=self.host, | ||
port=self.port, | ||
db=self.db, | ||
auth_key=self.auth_key, | ||
user=self.user, | ||
password=self.password, | ||
timeout=self.timeout, | ||
_handshake_version=20, | ||
) | ||
|
||
assert conn == self.reconnect | ||
self.conn_type.assert_called_once_with( | ||
self.host, | ||
self.port, | ||
self.db, | ||
self.auth_key, | ||
self.user, | ||
self.password, | ||
self.timeout, | ||
ANY, | ||
20 | ||
) |