mirror of
https://github.com/arc53/DocsGPT.git
synced 2026-05-10 12:31:21 +00:00
* feat: postgres tests * feat: mongo cutoff * feat: mongo cutoff * feat: adjust docs and compose files * fix: mini code mongo removals * fix: tests and k8s mongo stuff * feat: test fixes * fix: ruff * fix: vale * Potential fix for pull request finding 'CodeQL / Clear-text logging of sensitive information' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix: mini suggestions * vale lint fix 2 * fix: codeql columns thing * fix: test mongo * fix: tests coverage * feat: better tests 4 * feat: more tests * feat: decent coverage * fix: ruff fixes * fix: remove mongo mock * feat: enhance workflow engine and API routes; add document retrieval and source handling * feat: e2e tests * fix: mcp, mongo and more * fix: mini codeql warning * fix: agent chunk view * fix: mini issues * fix: more pg fixes * feat: postgres prep on start * feat: qa tests * fix: mini improvements * fix: tests --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Siddhant Rai <siddhant.rai.5686@gmail.com>
167 lines
3.7 KiB
Python
167 lines
3.7 KiB
Python
|
|
import pytest
|
|
from flask import Flask
|
|
|
|
|
|
@pytest.fixture
|
|
def app():
|
|
app = Flask(__name__)
|
|
return app
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestGetUserId:
|
|
pass
|
|
|
|
def test_returns_user_id_from_decoded_token(self, app):
|
|
from application.api.user.utils import get_user_id
|
|
|
|
with app.test_request_context():
|
|
from flask import request
|
|
|
|
request.decoded_token = {"sub": "user_123"}
|
|
assert get_user_id() == "user_123"
|
|
|
|
def test_returns_none_when_no_decoded_token(self, app):
|
|
from application.api.user.utils import get_user_id
|
|
|
|
with app.test_request_context():
|
|
assert get_user_id() is None
|
|
|
|
def test_returns_none_when_decoded_token_has_no_sub(self, app):
|
|
from application.api.user.utils import get_user_id
|
|
|
|
with app.test_request_context():
|
|
from flask import request
|
|
|
|
request.decoded_token = {}
|
|
assert get_user_id() is None
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestRequireAuth:
|
|
pass
|
|
|
|
def test_allows_authenticated_request(self, app):
|
|
from application.api.user.utils import require_auth
|
|
|
|
@require_auth
|
|
def protected():
|
|
return "ok"
|
|
|
|
with app.test_request_context():
|
|
from flask import request
|
|
|
|
request.decoded_token = {"sub": "user_123"}
|
|
assert protected() == "ok"
|
|
|
|
def test_returns_401_when_unauthenticated(self, app):
|
|
from application.api.user.utils import require_auth
|
|
|
|
@require_auth
|
|
def protected():
|
|
return "ok"
|
|
|
|
with app.test_request_context():
|
|
result = protected()
|
|
assert result.status_code == 401
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestSuccessResponse:
|
|
pass
|
|
|
|
def test_default_success_response(self, app):
|
|
from application.api.user.utils import success_response
|
|
|
|
with app.app_context():
|
|
resp = success_response()
|
|
assert resp.status_code == 200
|
|
assert resp.json["success"] is True
|
|
|
|
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestErrorResponse:
|
|
pass
|
|
|
|
def test_error_response_custom_status(self, app):
|
|
from application.api.user.utils import error_response
|
|
|
|
with app.app_context():
|
|
resp = error_response("Not found", 404)
|
|
assert resp.status_code == 404
|
|
|
|
def test_error_response_extra_kwargs(self, app):
|
|
from application.api.user.utils import error_response
|
|
|
|
with app.app_context():
|
|
resp = error_response("Bad", 400, errors=["field1", "field2"])
|
|
assert resp.json["errors"] == ["field1", "field2"]
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestValidateObjectId:
|
|
pass
|
|
|
|
@pytest.mark.unit
|
|
class TestValidatePagination:
|
|
pass
|
|
|
|
@pytest.mark.unit
|
|
class TestCheckResourceOwnership:
|
|
pass
|
|
|
|
@pytest.mark.unit
|
|
class TestSerializeObjectId:
|
|
pass
|
|
|
|
@pytest.mark.unit
|
|
class TestSerializeList:
|
|
pass
|
|
|
|
@pytest.mark.unit
|
|
class TestRequireFields:
|
|
pass
|
|
|
|
def test_allows_valid_request(self, app):
|
|
from application.api.user.utils import require_fields
|
|
|
|
@require_fields(["name", "email"])
|
|
def handler():
|
|
return "ok"
|
|
|
|
with app.test_request_context(
|
|
"/", method="POST", json={"name": "Alice", "email": "a@b.com"}
|
|
):
|
|
assert handler() == "ok"
|
|
|
|
|
|
def test_rejects_empty_body(self, app):
|
|
from application.api.user.utils import require_fields
|
|
|
|
@require_fields(["name"])
|
|
def handler():
|
|
return "ok"
|
|
|
|
with app.test_request_context(
|
|
"/", method="POST", json={}
|
|
):
|
|
result = handler()
|
|
assert result.status_code == 400
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestSafeDbOperation:
|
|
pass
|
|
|
|
@pytest.mark.unit
|
|
class TestValidateEnum:
|
|
pass
|
|
|
|
@pytest.mark.unit
|
|
class TestExtractSortParams:
|
|
pass
|
|
|