mirror of https://github.com/stijndcl/didier
Fiddle with action
parent
6d61056dc4
commit
00e805d535
|
@ -24,6 +24,18 @@ jobs:
|
||||||
tests:
|
tests:
|
||||||
needs: [dependencies]
|
needs: [dependencies]
|
||||||
runs-on: ubuntu-latest
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
|
@ -41,6 +53,9 @@ jobs:
|
||||||
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
||||||
- name: Run Pytest
|
- name: Run Pytest
|
||||||
run: pytest tests
|
run: pytest tests
|
||||||
|
env:
|
||||||
|
DB_TEST_SQLITE: false
|
||||||
|
DB_NAME: didier_action
|
||||||
linting:
|
linting:
|
||||||
needs: [dependencies]
|
needs: [dependencies]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -154,3 +154,6 @@ cython_debug/
|
||||||
|
|
||||||
# PyCharm
|
# PyCharm
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
# SQLite testing database
|
||||||
|
tests.db
|
|
@ -6,8 +6,18 @@ from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
encoded_password = quote_plus(settings.DB_PASSWORD)
|
# Run local tests against SQLite instead of Postgres
|
||||||
engine = create_async_engine(
|
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(
|
URL.create(
|
||||||
drivername="postgresql+asyncpg",
|
drivername="postgresql+asyncpg",
|
||||||
username=settings.DB_USERNAME,
|
username=settings.DB_USERNAME,
|
||||||
|
@ -17,6 +27,6 @@ engine = create_async_engine(
|
||||||
database=settings.DB_NAME,
|
database=settings.DB_NAME,
|
||||||
),
|
),
|
||||||
pool_pre_ping=True,
|
pool_pre_ping=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
DBSession = sessionmaker(autocommit=False, autoflush=False, bind=engine, class_=AsyncSession, expire_on_commit=False)
|
DBSession = sessionmaker(autocommit=False, autoflush=False, bind=engine, class_=AsyncSession, expire_on_commit=False)
|
||||||
|
|
|
@ -19,3 +19,8 @@ good-names = ["i"]
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
asyncio_mode = "auto"
|
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_PASSWORD: str = env.str("DB_PASSWORD", "")
|
||||||
DB_HOST: str = env.str("DB_HOST", "localhost")
|
DB_HOST: str = env.str("DB_HOST", "localhost")
|
||||||
DB_PORT: int = env.int("DB_PORT", "5432")
|
DB_PORT: int = env.int("DB_PORT", "5432")
|
||||||
|
DB_TEST_SQLITE: bool = env.bool("DB_TEST_SQLITE", True)
|
||||||
|
|
||||||
"""Discord"""
|
"""Discord"""
|
||||||
DISCORD_TOKEN: str = env.str("DISC_TOKEN")
|
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():
|
import settings
|
||||||
assert True
|
|
||||||
|
|
||||||
|
def test_dummy(tables):
|
||||||
|
assert settings.DB_TEST_SQLITE
|
||||||
|
|
Loading…
Reference in New Issue