mirror of https://github.com/stijndcl/didier
Fiddle with action
parent
6d61056dc4
commit
00e805d535
|
@ -24,6 +24,18 @@ jobs:
|
|||
tests:
|
||||
needs: [dependencies]
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:14
|
||||
env:
|
||||
POSTGRES_DB: didier_action
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 5432:5432
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup Python
|
||||
|
@ -41,6 +53,9 @@ jobs:
|
|||
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
||||
- name: Run Pytest
|
||||
run: pytest tests
|
||||
env:
|
||||
DB_TEST_SQLITE: false
|
||||
DB_NAME: didier_action
|
||||
linting:
|
||||
needs: [dependencies]
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
@ -154,3 +154,6 @@ cython_debug/
|
|||
|
||||
# PyCharm
|
||||
.idea/
|
||||
|
||||
# SQLite testing database
|
||||
tests.db
|
|
@ -6,6 +6,16 @@ from sqlalchemy.orm import sessionmaker
|
|||
|
||||
import settings
|
||||
|
||||
# Run local tests against SQLite instead of Postgres
|
||||
if settings.DB_TEST_SQLITE:
|
||||
engine = create_async_engine(
|
||||
URL.create(
|
||||
drivername="sqlite+aiosqlite",
|
||||
database="tests.db",
|
||||
),
|
||||
connect_args={"check_same_thread": False},
|
||||
)
|
||||
else:
|
||||
encoded_password = quote_plus(settings.DB_PASSWORD)
|
||||
engine = create_async_engine(
|
||||
URL.create(
|
||||
|
|
|
@ -19,3 +19,8 @@ good-names = ["i"]
|
|||
|
||||
[tool.pytest.ini_options]
|
||||
asyncio_mode = "auto"
|
||||
env = [
|
||||
"DB_NAME = didier-tests",
|
||||
"DB_USERNAME = postgres",
|
||||
"DB_HOST = postgres"
|
||||
]
|
|
@ -14,6 +14,7 @@ DB_USERNAME: str = env.str("DB_USERNAME", "postgres")
|
|||
DB_PASSWORD: str = env.str("DB_PASSWORD", "")
|
||||
DB_HOST: str = env.str("DB_HOST", "localhost")
|
||||
DB_PORT: int = env.int("DB_PORT", "5432")
|
||||
DB_TEST_SQLITE: bool = env.bool("DB_TEST_SQLITE", True)
|
||||
|
||||
"""Discord"""
|
||||
DISCORD_TOKEN: str = env.str("DISC_TOKEN")
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import pytest
|
||||
|
||||
from alembic import command, config
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def tables():
|
||||
"""Initialize a database before the tests, and then tear it down again
|
||||
Starts from an empty database and runs through all the migrations to check those as well
|
||||
while we're at it
|
||||
"""
|
||||
alembic_config = config.Config("alembic.ini")
|
||||
command.upgrade(alembic_config, "head")
|
||||
yield
|
||||
command.downgrade(alembic_config, "base")
|
|
@ -1,2 +1,5 @@
|
|||
def test_dummy():
|
||||
assert True
|
||||
import settings
|
||||
|
||||
|
||||
def test_dummy(tables):
|
||||
assert settings.DB_TEST_SQLITE
|
||||
|
|
Loading…
Reference in New Issue