reorganize directory structure, dependency management, and tests
parent
64deeef8e2
commit
6301de5518
@ -1,3 +0,0 @@
|
||||
flask==2.0.2
|
||||
gunicorn==20.1.0
|
||||
flask-cors==3.0.10
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.7 KiB |
@ -0,0 +1 @@
|
||||
requirements.in
|
@ -0,0 +1,4 @@
|
||||
flask==2.0.2
|
||||
psycopg-binary==3.0.4
|
||||
gunicorn==20.1.0
|
||||
flask-cors==3.0.10
|
@ -0,0 +1,31 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile with python 3.8
|
||||
# To update, run:
|
||||
#
|
||||
# pip-compile --output-file=backend/requirements.txt backend/requirements.in
|
||||
#
|
||||
click==8.0.3
|
||||
# via flask
|
||||
flask==2.0.2
|
||||
# via
|
||||
# -r backend/requirements.in
|
||||
# flask-cors
|
||||
flask-cors==3.0.10
|
||||
# via -r backend/requirements.in
|
||||
gunicorn==20.1.0
|
||||
# via -r backend/requirements.in
|
||||
itsdangerous==2.0.1
|
||||
# via flask
|
||||
jinja2==3.0.3
|
||||
# via flask
|
||||
markupsafe==2.0.1
|
||||
# via jinja2
|
||||
psycopg-binary==3.0.4
|
||||
# via -r backend/requirements.in
|
||||
six==1.16.0
|
||||
# via flask-cors
|
||||
werkzeug==2.0.2
|
||||
# via flask
|
||||
|
||||
# The following packages are considered to be unsafe in a requirements file:
|
||||
# setuptools
|
@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
|
||||
def build_postgres_uri(
|
||||
host, user, dbname, port, sslmode=None, passwd=None, params=None
|
||||
):
|
||||
"""Builds a PostgreSQL uri.
|
||||
|
||||
See https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING for additional details.
|
||||
"""
|
||||
|
||||
if passwd:
|
||||
uri = f"postgresql://{user}:{passwd}@{host}:{port}/{dbname}"
|
||||
else:
|
||||
uri = f"postgresql://{user}@{host}:{port}/{dbname}"
|
||||
if sslmode:
|
||||
uri = f"{uri}?sslmode={sslmode}"
|
||||
return uri
|
||||
|
||||
|
||||
POSTGRES_HOST = os.getenv("POSTGRES_HOST")
|
||||
POSTGRES_USER = os.getenv("POSTGRES_USER")
|
||||
POSTGRES_APP_DATABASE = os.getenv("POSTGRES_APP_DATABASE")
|
||||
POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD")
|
||||
POSTGRES_PORT = os.getenv("POSTGRES_PORT", default="5432")
|
||||
POSTGRES_SSL_MODE = os.getenv("POSTGRES_SSL_MODE", default="prefer")
|
||||
POSTGRES_PARAMS = os.getenv("POSTGRES_PARAMS")
|
@ -0,0 +1,3 @@
|
||||
black==21.10b0
|
||||
pip-tools==6.4.0
|
||||
pytest==6.2.5
|
@ -0,0 +1,52 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile with python 3.8
|
||||
# To update, run:
|
||||
#
|
||||
# pip-compile dev_requirements.in
|
||||
#
|
||||
attrs==21.2.0
|
||||
# via pytest
|
||||
black==21.10b0
|
||||
# via -r dev_requirements.in
|
||||
click==8.0.3
|
||||
# via
|
||||
# black
|
||||
# pip-tools
|
||||
iniconfig==1.1.1
|
||||
# via pytest
|
||||
mypy-extensions==0.4.3
|
||||
# via black
|
||||
packaging==21.2
|
||||
# via pytest
|
||||
pathspec==0.9.0
|
||||
# via black
|
||||
pep517==0.12.0
|
||||
# via pip-tools
|
||||
pip-tools==6.4.0
|
||||
# via -r dev_requirements.in
|
||||
platformdirs==2.4.0
|
||||
# via black
|
||||
pluggy==1.0.0
|
||||
# via pytest
|
||||
py==1.11.0
|
||||
# via pytest
|
||||
pyparsing==2.4.7
|
||||
# via packaging
|
||||
pytest==6.2.5
|
||||
# via -r dev_requirements.in
|
||||
regex==2021.11.10
|
||||
# via black
|
||||
toml==0.10.2
|
||||
# via pytest
|
||||
tomli==1.2.2
|
||||
# via
|
||||
# black
|
||||
# pep517
|
||||
typing-extensions==4.0.0
|
||||
# via black
|
||||
wheel==0.37.0
|
||||
# via pip-tools
|
||||
|
||||
# The following packages are considered to be unsafe in a requirements file:
|
||||
# pip
|
||||
# setuptools
|
@ -0,0 +1,56 @@
|
||||
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
|
Loading…
Reference in New Issue