Buckets:

download
raw
3.59 kB
from pytest import mark, raises
from sqlalchemy.engine import Engine
from limberframework.database.connections import (
PostgresConnection,
SqliteConnection,
make_connection,
)
@mark.parametrize(
"config",
[
(
{
"username": "root",
"password": "toor",
"host": "localhost",
"port": 5432,
"database": "public",
}
),
(
{
"username": "admin",
"password": "pass1234",
"host": "postgres",
"port": 2500,
"database": "test",
}
),
],
)
def test_postgres_connection(config):
postgres_connection = PostgresConnection(**config)
assert isinstance(postgres_connection, PostgresConnection)
assert isinstance(postgres_connection.engine, Engine)
assert postgres_connection.username == config["username"]
assert postgres_connection.password == config["password"]
assert postgres_connection.host == config["host"]
assert postgres_connection.port == config["port"]
assert postgres_connection.database == config["database"]
@mark.parametrize(
"path", [("./sqlite.db"), ("../database"), ("./database/file.db")]
)
def test_sqlite_connection(path):
sqlite_connection = SqliteConnection(path)
assert isinstance(sqlite_connection, SqliteConnection)
assert isinstance(sqlite_connection.engine, Engine)
assert sqlite_connection.path == path
@mark.parametrize(
"config,expected_url",
[
(
{
"username": "root",
"password": "toor",
"host": "localhost",
"port": 5432,
"database": "public",
},
"postgresql://root:toor@localhost:5432/public",
),
(
{
"username": "admin",
"password": "pass1234",
"host": "postgres",
"port": 2500,
"database": "test",
},
"postgresql://admin:pass1234@postgres:2500/test",
),
],
)
def test_pgsql_connection_get_url(config, expected_url):
postgres_connection = PostgresConnection(**config)
url = postgres_connection.get_url()
assert expected_url in url
@mark.parametrize(
"path,expected_url",
[
("./sqlite.db", "sqlite:///./sqlite.db"),
("../database", "sqlite:///../database"),
("./database/file.db", "sqlite:///./database/file.db"),
],
)
def test_sqlite_connection_get_url(path, expected_url):
sqlite_connection = SqliteConnection(path)
url = sqlite_connection.get_url()
assert expected_url in url
@mark.asyncio
async def test_make_connection_with_invalid_config():
config = {"driver": "sqlite"}
with raises(KeyError) as exception:
await make_connection(config)
assert "path" in str(exception.value)
@mark.asyncio
async def test_make_connection_with_invalid_driver():
config = {"driver": "invalid_driver"}
with raises(Exception) as exception:
await make_connection(config)
assert f"Unsupported driver {config['driver']}" in str(exception.value)
@mark.asyncio
async def test_make_connection_pgsql():
config = {
"driver": "pgsql",
"username": "test",
"password": "test",
"host": "test",
"port": 5432,
"database": "test",
}
response = await make_connection(config)
assert isinstance(response, PostgresConnection)

Xet Storage Details

Size:
3.59 kB
·
Xet hash:
28e5e87a1e2137a90051ccd8dd698383026b8823c49f3b8d960e93f1adcfc586

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.