Skip to content

Commit 3250937

Browse files
committed
Add passing DB test.
1 parent 488d463 commit 3250937

9 files changed

Lines changed: 60 additions & 23 deletions

File tree

.env.example

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
FLASK_APP=wsgi.py
22
FLASK_DEBUG=False
33
SECRET_KEY=yoursecretkey
4-
SQLALCHEMY_DATABASE_URI=mysql+pymysql://myuser:mypassword@host.example.com:1234/mydatabase
4+
5+
SQLALCHEMY_DATABASE_HOST=db.example.com
6+
SQLALCHEMY_DATABASE_TABLE=my_table
7+
SQLALCHEMY_DATABASE_NAME=my_database
8+
SQLALCHEMY_DATABASE_URI=mysql+pymysql://username:password@db.example.com:1234/my_database
9+
SQLALCHEMY_DATABASE_PEM="-----BEGIN CERTIFICATE-----\n[NONSENSICAL_KEY_STORED_ON_SINGLE_LINE]\n-----END CERTIFICATE-----\n"
10+
SQLALCHEMY_DATABASE_URI=mysql+pymysql://myuser:mypassword@db.example.com:1234/my_database
11+
512
COMPRESSOR_DEBUG=True
613
LESS_BIN=/usr/local/bin/lessc
714
ASSETS_DEBUG=False

.github/workflows/python-app.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414
- name: Set up Python
15-
uses: actions/setup-python@v4
15+
uses: actions/setup-python@v5
1616
with:
17-
python-version: "3.10"
17+
python-version: "3.12"
1818

1919
- name: Install dependencies
2020
run: |

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# PythonMyAdmin
22

3-
![Python](https://img.shields.io/badge/Python-^3.10-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4-
![Flask](https://img.shields.io/badge/Flask-2.2.5-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
5-
![Dash](https://img.shields.io/badge/Dash-v^2.14.0-blue.svg?longCache=true&logo=python&longCache=true&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
3+
![Python](https://img.shields.io/badge/Python-^3.12-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4+
![Flask](https://img.shields.io/badge/Flask-3.0.3-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
5+
![Dash](https://img.shields.io/badge/Dash-v^2.18.2-blue.svg?longCache=true&logo=python&longCache=true&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
66
![Flask-SQLAlchemy](https://img.shields.io/badge/Flask--SQLAlchemy-^3.1.1-red.svg?longCache=true&style=flat-square&logo=scala&logoColor=white&colorA=4c566a&colorB=bf616a)
77
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c)
88
[![GitHub Issues](https://img.shields.io/github/issues/toddbirchard/pythonmyadmin.svg?style=flat-square&colorA=4c566a&colorB=ebcb8b)](https://github.com/toddbirchard/pythonmyadmin/issues)

gunicorn.conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
reload = True
2222
workers = 1
2323
threads = 1
24-
bind = ["127.0.0.1:8000"]
24+
bind = ["127.0.0.1:8007"]
2525
elif ENVIRONMENT == "production":
2626
access_log_format = "%(h)s %(l)s %(u)s %(t)s %(r)s %(s)s %(b)s %(f)s %(a)s"
2727
daemon = True

log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def log_formatter(record: dict) -> str:
6464
return "<fg #5278a3>{time:MM-DD-YYYY HH:mm:ss}</fg #5278a3> | <fg #98bedf>{level}</fg #98bedf>: <light-white>{message}</light-white>\n"
6565

6666

67-
def create_logger() -> logger:
67+
def create_logger():
6868
"""
6969
Configure custom logger.
7070

pythonmyadmin/assets.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@
77
def compile_js_assets(app: Flask):
88
"""Build JS bundle."""
99
assets = Environment(app)
10-
Environment.auto_build = True
11-
Environment.debug = False
12-
js_bundle = Bundle("js/*.js", filters="jsmin", output="dist/js/main.js")
13-
assets.register("js_all", js_bundle)
14-
js_bundle.build()
10+
if app.config["ENVIRONMENT"] != "production":
11+
assets.auto_build = True
12+
assets.debug = False
13+
js_bundle = Bundle("js/*.js", filters="jsmin", output="dist/js/main.js")
14+
assets.register("js_all", js_bundle)
15+
js_bundle.build()
1516

1617

1718
def compile_style_assets(app: Flask):
1819
"""Build CSS style bundle."""
1920
assets = Environment(app)
20-
Environment.auto_build = True
21-
Environment.debug = False
22-
less_bundle = Bundle(
23-
"less/main.less",
24-
filters="less,cssmin",
25-
output="dist/css/style.css",
26-
extra={"rel": "stylesheet/less"},
27-
)
28-
assets.register("less_all", less_bundle)
29-
less_bundle.build(force=True)
21+
if app.config["ENVIRONMENT"] != "production":
22+
assets.auto_build = True
23+
assets.debug = False
24+
less_bundle = Bundle(
25+
"less/main.less",
26+
filters="less,cssmin",
27+
output="dist/css/style.css",
28+
extra={"rel": "stylesheet/less"},
29+
)
30+
assets.register("less_all", less_bundle)
31+
less_bundle.build(force=True)

tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""PyTest mocked fixtures."""
2+
3+
import pytest
4+
5+
from clients import Database
6+
from config import settings
7+
8+
9+
@pytest.fixture
10+
def db() -> Database:
11+
"""Return a valid database object."""
12+
return Database(
13+
uri=settings.SQLALCHEMY_DATABASE_URI,
14+
table=settings.SQLALCHEMY_DATABASE_TABLE,
15+
args=settings.SQLALCHEMY_CONNECT_ARGS,
16+
)

tests/test_table_fetch.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Basic tests for validating app functionality."""
2+
3+
import pytest
4+
from pandas import DataFrame
5+
6+
from clients.database import Database
7+
8+
9+
def test_fetch_sql_data(db: Database):
10+
"""Test fetching data from a table."""
11+
data = db.get_table_data()
12+
assert type(data) == DataFrame

0 commit comments

Comments
 (0)