Test support for sqlite. (#68)

This commit is contained in:
Tyler Kennedy 2022-12-01 11:53:45 -05:00 committed by GitHub
parent 9fd70424bb
commit ee9ac29cca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 9 deletions

View File

@ -10,10 +10,19 @@ on:
jobs:
test:
name: test py${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
db:
- "postgres://postgres:postgres@localhost/postgres"
- "sqlite:///takahe.db"
include:
- db: "sqlite:///takahe.db"
search: false
- db: "postgres://postgres:postgres@localhost/postgres"
search: true
services:
postgres:
image: postgres:15
@ -22,7 +31,11 @@ jobs:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports: ["5432:5432"]
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
@ -35,7 +48,8 @@ jobs:
python -m pip install -r requirements-dev.txt
- name: Run pytest
env:
TAKAHE_DATABASE_SERVER: "postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres"
TAKAHE_DATABASE_SERVER: ${{ matrix.db }}
TAKAHE_SEARCH: ${{ matrix.search }}
TAKAHE_ENVIRONMENT: "test"
TAKAHE_SECRET_KEY: "testing_secret"
TAKAHE_MAIN_DOMAIN: "example.com"

View File

@ -7,12 +7,16 @@ from typing import List, Literal, Optional, Union
import dj_database_url
import sentry_sdk
from pydantic import AnyUrl, BaseSettings, EmailStr, Field, PostgresDsn, validator
from pydantic import AnyUrl, BaseSettings, EmailStr, Field, validator
from sentry_sdk.integrations.django import DjangoIntegration
BASE_DIR = Path(__file__).resolve().parent.parent
class ImplicitHostname(AnyUrl):
host_required = False
class MediaBackendUrl(AnyUrl):
host_required = False
allowed_schemes = {"s3", "gcs", "local"}
@ -35,11 +39,6 @@ TAKAHE_ENV_FILE = os.environ.get(
)
TAKAHE_ENV_FILE = os.environ.get(
"TAKAHE_ENV_FILE", "test.env" if "pytest" in sys.modules else ".env"
)
class Settings(BaseSettings):
"""
Pydantic-powered settings, to provide consistent error messages, strong
@ -47,7 +46,7 @@ class Settings(BaseSettings):
"""
#: The default database.
DATABASE_SERVER: Optional[PostgresDsn]
DATABASE_SERVER: Optional[ImplicitHostname]
#: The currently running environment, used for things such as sentry
#: error reporting.
@ -91,6 +90,10 @@ class Settings(BaseSettings):
MEDIA_ROOT: str = str(BASE_DIR / "media")
MEDIA_BACKEND: Optional[MediaBackendUrl] = None
#: If search features like full text search should be enabled.
#: (placeholder setting, no effect)
SEARCH: bool = True
PGHOST: Optional[str] = None
PGPORT: Optional[int] = 5432
PGNAME: str = "takahe"