From d1420a6a512e3a393bd873d808a88f4d89038f6c Mon Sep 17 00:00:00 2001 From: Henty Date: Wed, 24 Jul 2024 11:10:00 +0100 Subject: [PATCH] Forgot a db --- .github/workflows/main.yml | 8 ++++---- chronos/settings.py | 4 ++-- chronos/worker.py | 2 +- pyproject.toml | 9 +++------ requirements.txt | 3 ++- tests/test_worker.py | 5 +++-- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c00b4aa..10f78af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,17 +17,18 @@ jobs: env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - POSTGRES_DB: hermes_test + POSTGRES_DB: test_chronos ports: - 5432:5432 options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 redis: image: redis ports: - - 6379:6379s + - 6379:6379 options: --entrypoint redis-server + env: - DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/chronos_test' + DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/test_chronos' steps: - uses: actions/checkout@v2 @@ -46,7 +47,6 @@ jobs: - name: test run: | - make reset-db make test - name: codecov diff --git a/chronos/settings.py b/chronos/settings.py index 221fd5a..363fe24 100644 --- a/chronos/settings.py +++ b/chronos/settings.py @@ -18,8 +18,8 @@ class Settings(BaseSettings): # Postgres # pg_dsn: PostgresDsn = Field('postgres://postgres@localhost:5432/chronos', validation_alias='DATABASE_URL') - pg_dsn: str = 'postgresql://postgres@localhost:5432/chronos' - test_pg_dsn: str = 'postgresql://postgres@localhost:5432/test_chronos' + pg_dsn: str = 'postgresql://postgres:postgres@localhost:5432/chronos' + test_pg_dsn: str = 'postgresql://postgres:postgres@localhost:5432/test_chronos' # # Redis # redis_dsn: RedisDsn = Field('redis://localhost:6399', validation_alias='REDISCLOUD_URL') diff --git a/chronos/worker.py b/chronos/worker.py index 2a0315f..380ed62 100644 --- a/chronos/worker.py +++ b/chronos/worker.py @@ -92,7 +92,7 @@ async def delete_old_logs_job(): @celery_app.task def _delete_old_logs_job(): with Session(engine) as db: - statement = select(WebhookLog).where(WebhookLog.timestamp >= datetime.utcnow() - timedelta(days=15)) + statement = select(WebhookLog).where(WebhookLog.timestamp > datetime.utcnow() - timedelta(days=15)) results = db.exec(statement).all() delete_statement = delete(WebhookLog).where(col(WebhookLog.id).in_([whl.id for whl in results])) diff --git a/pyproject.toml b/pyproject.toml index 1c746f8..b27af5e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,15 +15,12 @@ [tool.pytest.ini_options] addopts = '--tb=native' - filterwarnings = [ - 'ignore::DeprecationWarning:fastapi_admin.resources*', # Remove when fastapi-admin is updated - 'ignore::DeprecationWarning:fastapi.applications.*', # Remove when tortoise is updated -] + filterwarnings = [] [tool.coverage.run] - source = ['app'] + source = ['chronos'] branch = true - omit = ['app/main.py'] + omit = ['chronos/main.py'] [tool.coverage.report] precision = 2 diff --git a/requirements.txt b/requirements.txt index 7df8941..e62dace 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,4 +15,5 @@ psycopg2==2.9.9 sentry-sdk==2.11.0 opentelemetry-instrumentation-fastapi==0.46b0 fastapi-utilities==0.2.0 -redis==5.0.7 \ No newline at end of file +redis==5.0.7 +pytest-cov==5.0.0 \ No newline at end of file diff --git a/tests/test_worker.py b/tests/test_worker.py index 6cec799..1f0e4d4 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -192,7 +192,7 @@ def test_delete_old_logs(self, db: Session, client: TestClient, celery_session_w for i in range(1, 31): whl = create_webhook_log_from_dft_data( endpoint_id=ep.id, - timestamp=datetime.now() - timedelta(days=i), + timestamp=datetime.utcnow() - timedelta(days=i), ) db.add(whl) db.commit() @@ -202,4 +202,5 @@ def test_delete_old_logs(self, db: Session, client: TestClient, celery_session_w _delete_old_logs_job() logs = db.exec(select(WebhookLog)).all() - assert len(logs) == 15 + # The log from 15 days ago is seconds older than the check and thus doesn't get deleted + assert len(logs) == 16