mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-18 14:13:10 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""Tests for UserLogsRepository against a real Postgres instance.
|
|
|
|
The repository is now write-only: the read path is the unified timeline
|
|
in ``api/user/analytics/routes.py`` (GetUserLogs), covered by the route
|
|
tests. Inserts are verified with raw SQL here.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import text
|
|
|
|
from docsgpt.storage.db.repositories.user_logs import UserLogsRepository
|
|
|
|
|
|
def _rows(conn, user_id):
|
|
result = conn.execute(
|
|
text(
|
|
"SELECT * FROM user_logs WHERE user_id = :u ORDER BY timestamp DESC"
|
|
),
|
|
{"u": user_id},
|
|
)
|
|
return [dict(r._mapping) for r in result.fetchall()]
|
|
|
|
|
|
class TestInsert:
|
|
def test_inserts_log(self, pg_conn):
|
|
repo = UserLogsRepository(pg_conn)
|
|
repo.insert(user_id="u1", endpoint="/api/answer", data={"question": "hi"})
|
|
rows = _rows(pg_conn, "u1")
|
|
assert len(rows) == 1
|
|
assert rows[0]["data"]["question"] == "hi"
|
|
assert rows[0]["endpoint"] == "/api/answer"
|
|
|
|
def test_allows_null_data(self, pg_conn):
|
|
repo = UserLogsRepository(pg_conn)
|
|
repo.insert(user_id="u1")
|
|
rows = _rows(pg_conn, "u1")
|
|
assert len(rows) == 1
|
|
assert rows[0]["data"] is None
|
|
|
|
def test_explicit_timestamp_is_stored(self, pg_conn):
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
repo = UserLogsRepository(pg_conn)
|
|
earlier = datetime.now(timezone.utc) - timedelta(minutes=5)
|
|
repo.insert(user_id="u1", data={"order": "first"}, timestamp=earlier)
|
|
repo.insert(user_id="u1", data={"order": "second"})
|
|
rows = _rows(pg_conn, "u1")
|
|
assert rows[0]["data"]["order"] == "second"
|
|
assert rows[1]["data"]["order"] == "first"
|