Skip to content

Commit

Permalink
Add passing DB test.
Browse files Browse the repository at this point in the history
  • Loading branch information
toddbirchard committed Dec 24, 2024
1 parent 488d463 commit 3250937
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 23 deletions.
9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
FLASK_APP=wsgi.py
FLASK_DEBUG=False
SECRET_KEY=yoursecretkey
SQLALCHEMY_DATABASE_URI=mysql+pymysql://myuser:[email protected]:1234/mydatabase

SQLALCHEMY_DATABASE_HOST=db.example.com
SQLALCHEMY_DATABASE_TABLE=my_table
SQLALCHEMY_DATABASE_NAME=my_database
SQLALCHEMY_DATABASE_URI=mysql+pymysql://username:[email protected]:1234/my_database
SQLALCHEMY_DATABASE_PEM="-----BEGIN CERTIFICATE-----\n[NONSENSICAL_KEY_STORED_ON_SINGLE_LINE]\n-----END CERTIFICATE-----\n"
SQLALCHEMY_DATABASE_URI=mysql+pymysql://myuser:[email protected]:1234/my_database

COMPRESSOR_DEBUG=True
LESS_BIN=/usr/local/bin/lessc
ASSETS_DEBUG=False
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- name: Install dependencies
run: |
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# PythonMyAdmin

![Python](https://img.shields.io/badge/Python-^3.10-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
![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)
![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)
![Python](https://img.shields.io/badge/Python-^3.12-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
![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)
![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)
![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)
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c)
[![GitHub Issues](https://img.shields.io/github/issues/toddbirchard/pythonmyadmin.svg?style=flat-square&colorA=4c566a&colorB=ebcb8b)](https://github.com/toddbirchard/pythonmyadmin/issues)
Expand Down
2 changes: 1 addition & 1 deletion gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
reload = True
workers = 1
threads = 1
bind = ["127.0.0.1:8000"]
bind = ["127.0.0.1:8007"]
elif ENVIRONMENT == "production":
access_log_format = "%(h)s %(l)s %(u)s %(t)s %(r)s %(s)s %(b)s %(f)s %(a)s"
daemon = True
Expand Down
2 changes: 1 addition & 1 deletion log.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def log_formatter(record: dict) -> str:
return "<fg #5278a3>{time:MM-DD-YYYY HH:mm:ss}</fg #5278a3> | <fg #98bedf>{level}</fg #98bedf>: <light-white>{message}</light-white>\n"


def create_logger() -> logger:
def create_logger():
"""
Configure custom logger.
Expand Down
32 changes: 17 additions & 15 deletions pythonmyadmin/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@
def compile_js_assets(app: Flask):
"""Build JS bundle."""
assets = Environment(app)
Environment.auto_build = True
Environment.debug = False
js_bundle = Bundle("js/*.js", filters="jsmin", output="dist/js/main.js")
assets.register("js_all", js_bundle)
js_bundle.build()
if app.config["ENVIRONMENT"] != "production":
assets.auto_build = True
assets.debug = False
js_bundle = Bundle("js/*.js", filters="jsmin", output="dist/js/main.js")
assets.register("js_all", js_bundle)
js_bundle.build()


def compile_style_assets(app: Flask):
"""Build CSS style bundle."""
assets = Environment(app)
Environment.auto_build = True
Environment.debug = False
less_bundle = Bundle(
"less/main.less",
filters="less,cssmin",
output="dist/css/style.css",
extra={"rel": "stylesheet/less"},
)
assets.register("less_all", less_bundle)
less_bundle.build(force=True)
if app.config["ENVIRONMENT"] != "production":
assets.auto_build = True
assets.debug = False
less_bundle = Bundle(
"less/main.less",
filters="less,cssmin",
output="dist/css/style.css",
extra={"rel": "stylesheet/less"},
)
assets.register("less_all", less_bundle)
less_bundle.build(force=True)
File renamed without changes.
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""PyTest mocked fixtures."""

import pytest

from clients import Database
from config import settings


@pytest.fixture
def db() -> Database:
"""Return a valid database object."""
return Database(
uri=settings.SQLALCHEMY_DATABASE_URI,
table=settings.SQLALCHEMY_DATABASE_TABLE,
args=settings.SQLALCHEMY_CONNECT_ARGS,
)
12 changes: 12 additions & 0 deletions tests/test_table_fetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Basic tests for validating app functionality."""

import pytest
from pandas import DataFrame

from clients.database import Database


def test_fetch_sql_data(db: Database):
"""Test fetching data from a table."""
data = db.get_table_data()
assert type(data) == DataFrame

0 comments on commit 3250937

Please sign in to comment.