You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB
Python

import pytest
from backend.settings import build_postgres_uri
@pytest.mark.parametrize(
"kwargs,expected",
[
# No password / No SSL
(
{
"host": "localhost",
"user": "superman",
"port": "5432",
"dbname": "sample",
},
"postgresql://superman@localhost:5432/sample",
),
# No password / with SSL
(
{
"host": "my-postgres.hostname.io",
"user": "superman",
"port": "5432",
"dbname": "sample",
"sslmode": "prefer",
},
"postgresql://superman@my-postgres.hostname.io:5432/sample?sslmode=prefer",
),
# No password / no SSL
(
{
"host": "my-postgres.hostname.io",
"user": "superman",
"passwd": "supersecret",
"port": "5432",
"dbname": "sample",
},
"postgresql://superman:supersecret@my-postgres.hostname.io:5432/sample",
),
# password / SSL
(
{
"host": "254.254.254.254",
"user": "superman",
"passwd": "supersecret",
"port": "15432",
"dbname": "sample",
},
"postgresql://superman:supersecret@254.254.254.254:15432/sample",
),
],
)
def test_build_postgres_uri(kwargs, expected):
result = build_postgres_uri(**kwargs)
assert result == expected