Fiddle with action

pull/115/head
stijndcl 2022-06-17 00:43:55 +02:00
parent 6d61056dc4
commit 00e805d535
7 changed files with 67 additions and 15 deletions

View File

@ -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

3
.gitignore vendored
View File

@ -154,3 +154,6 @@ cython_debug/
# PyCharm # PyCharm
.idea/ .idea/
# SQLite testing database
tests.db

View File

@ -6,17 +6,27 @@ 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:
URL.create( engine = create_async_engine(
drivername="postgresql+asyncpg", URL.create(
username=settings.DB_USERNAME, drivername="sqlite+aiosqlite",
password=encoded_password, database="tests.db",
host=settings.DB_HOST, ),
port=settings.DB_PORT, connect_args={"check_same_thread": False},
database=settings.DB_NAME, )
), else:
pool_pre_ping=True, encoded_password = quote_plus(settings.DB_PASSWORD)
) engine = create_async_engine(
URL.create(
drivername="postgresql+asyncpg",
username=settings.DB_USERNAME,
password=encoded_password,
host=settings.DB_HOST,
port=settings.DB_PORT,
database=settings.DB_NAME,
),
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)

View File

@ -18,4 +18,9 @@ max-line-length = 120
good-names = ["i"] 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"
]

View File

@ -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")

15
tests/conftest.py 100644
View File

@ -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")

View File

@ -1,2 +1,5 @@
def test_dummy(): import settings
assert True
def test_dummy(tables):
assert settings.DB_TEST_SQLITE