-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
091f091
commit 9464748
Showing
12 changed files
with
357 additions
and
117 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
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,81 @@ | ||
import pytest | ||
from mysql import connector | ||
|
||
|
||
class TestConnectionURIMySQL: | ||
def test_connect_with_non_existing_database(self): | ||
from dataloom import Loom | ||
from dataloom.keys import MySQLConfig | ||
|
||
mysql_loom = Loom( | ||
dialect="mysql", | ||
connection_uri=f"mysql://{MySQLConfig.user}:{MySQLConfig.password}@{MySQLConfig.host}:{MySQLConfig.port}/non-exists", | ||
) | ||
with pytest.raises(connector.errors.ProgrammingError) as exc_info: | ||
conn = mysql_loom.connect() | ||
conn.close() | ||
assert exc_info.value.msg == "Unknown database 'non-exists'" | ||
assert exc_info.value.errno == 1049 | ||
|
||
def test_connect_with_wrong_password(self): | ||
from dataloom import Loom | ||
from dataloom.keys import MySQLConfig | ||
|
||
mysql_loom = Loom( | ||
dialect="mysql", | ||
connection_uri=f"mysql://{MySQLConfig.user}:{MySQLConfig.password+'me'}@{MySQLConfig.host}:{MySQLConfig.port}/hi", | ||
) | ||
with pytest.raises(connector.errors.ProgrammingError) as exc_info: | ||
conn = mysql_loom.connect() | ||
conn.close() | ||
|
||
assert str(exc_info.value.msg).startswith( | ||
"Access denied for user 'root'@'" | ||
) and str(exc_info.value.msg).endswith("(using password: YES)") | ||
assert exc_info.value.errno == 1045 | ||
|
||
def test_connect_with_wrong_user(self): | ||
from dataloom import Loom | ||
from dataloom.keys import MySQLConfig | ||
|
||
mysql_loom = Loom( | ||
dialect="mysql", | ||
connection_uri=f"mysql://hey:{MySQLConfig.password}@{MySQLConfig.host}:{MySQLConfig.port}/hi", | ||
) | ||
with pytest.raises(connector.errors.ProgrammingError) as exc_info: | ||
conn = mysql_loom.connect() | ||
conn.close() | ||
assert str(exc_info.value.msg).startswith( | ||
"Access denied for user 'hey'@" | ||
) and str(exc_info.value.msg).endswith("(using password: YES)") | ||
assert exc_info.value.errno == 1045 | ||
|
||
def test_connect_with_wrong_dialect(self): | ||
from dataloom import Loom | ||
from dataloom.keys import MySQLConfig | ||
from dataloom.exceptions import UnsupportedDialectException | ||
|
||
with pytest.raises(UnsupportedDialectException) as exc_info: | ||
mysql_loom = Loom( | ||
dialect="dialect", | ||
connection_uri=f"mysql://{MySQLConfig.user}:{MySQLConfig.password}@{MySQLConfig.host}:{MySQLConfig.port}/hi", | ||
) | ||
conn = mysql_loom.connect() | ||
conn.close() | ||
|
||
assert ( | ||
str(exc_info.value) | ||
== "The dialect passed is not supported the supported dialects are: {'postgres', 'mysql', 'sqlite'}" | ||
) | ||
|
||
def test_connect_correct_connection(self): | ||
from dataloom import Loom | ||
from dataloom.keys import MySQLConfig | ||
|
||
mysql_loom = Loom( | ||
dialect="mysql", | ||
connection_uri=f"mysql://{MySQLConfig.user}:{MySQLConfig.password}@{MySQLConfig.host}:{MySQLConfig.port}/hi", | ||
) | ||
conn = mysql_loom.connect() | ||
conn.close() | ||
assert conn is not None |
2 changes: 1 addition & 1 deletion
2
...loom/tests/postgres/test_connection_pg.py → ...ts/postgres/test_connection_options_pg.py
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,83 @@ | ||
import pytest | ||
|
||
|
||
class TestConnectionURIPG: | ||
def test_connect_with_non_existing_database(self): | ||
from dataloom import Loom | ||
from dataloom.keys import PgConfig | ||
|
||
pg_loom = Loom( | ||
dialect="postgres", | ||
connection_uri=f"postgresql://{PgConfig.user}:{PgConfig.password}@{PgConfig.host}:{PgConfig.port}/mew", | ||
) | ||
with pytest.raises(Exception) as exc_info: | ||
conn = pg_loom.connect() | ||
conn.close() | ||
assert ( | ||
str(exc_info.value.args[0]).strip() | ||
== 'connection to server at "localhost" (::1), port 5432 failed: FATAL: database "mew" does not exist' | ||
) | ||
|
||
def test_connect_with_wrong_password(self): | ||
from dataloom import Loom | ||
from dataloom.keys import PgConfig | ||
|
||
pg_loom = Loom( | ||
dialect="postgres", | ||
connection_uri=f"postgresql://{PgConfig.user}:{PgConfig.password+'-'}@{PgConfig.host}:{PgConfig.port}/hi", | ||
) | ||
with pytest.raises(Exception) as exc_info: | ||
conn = pg_loom.connect() | ||
conn.close() | ||
|
||
assert ( | ||
str(exc_info.value.args[0]).strip() | ||
== 'connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "postgres"' | ||
) | ||
|
||
def test_connect_with_wrong_user(self): | ||
from dataloom import Loom | ||
from dataloom.keys import PgConfig | ||
|
||
pg_loom = Loom( | ||
dialect="postgres", | ||
connection_uri=f"postgresql://postgre-u:{PgConfig.password}@{PgConfig.host}:{PgConfig.port}/hi", | ||
) | ||
with pytest.raises(Exception) as exc_info: | ||
conn = pg_loom.connect() | ||
conn.close() | ||
|
||
assert ( | ||
str(exc_info.value.args[0]).strip() | ||
== 'connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "postgre-u"' | ||
) | ||
|
||
def test_connect_with_wrong_dialect(self): | ||
from dataloom import Loom | ||
from dataloom.exceptions import UnsupportedDialectException | ||
from dataloom.keys import PgConfig | ||
|
||
with pytest.raises(UnsupportedDialectException) as exc_info: | ||
pg_loom = Loom( | ||
dialect="peew", | ||
connection_uri=f"postgresql://{PgConfig.user}:{PgConfig.password}@{PgConfig.host}:{PgConfig.port}/hi", | ||
) | ||
conn = pg_loom.connect() | ||
conn.close() | ||
assert ( | ||
str(exc_info.value) | ||
== "The dialect passed is not supported the supported dialects are: {'postgres', 'mysql', 'sqlite'}" | ||
) | ||
|
||
def test_connect_correct_connection(self): | ||
from dataloom import Loom | ||
from dataloom.keys import PgConfig | ||
|
||
pg_loom = Loom( | ||
dialect="postgres", | ||
connection_uri=f"postgresql://{PgConfig.user}:{PgConfig.password}@{PgConfig.host}:{PgConfig.port}/hi", | ||
) | ||
conn = pg_loom.connect() | ||
conn.close() | ||
|
||
assert conn is not None |
Oops, something went wrong.