test: add test suite with 65 tests, 73% coverage

- Unit tests: password hashing, notification providers, webhook field parsing
- Integration tests: auth routes (register/login/confirm-email/logout),
  invite flow, Evotor webhooks (/user/create, /user/verify, /user/token),
  admin panel (access control, activate/suspend/delete/reset-password)
- conftest: SQLite in-memory engine, transactional sessions, factory-boy
  factories (UserFactory with UserRoleEnum variants)
- Fix bcrypt: replace passlib (broken on Python 3.14 + bcrypt 5.x) with
  direct bcrypt calls; drop passlib from requirements.txt
- Fix datetime.utcnow() deprecation across routes and tests
- Fix Jinja2 TemplateResponse signature (request as first positional arg)
- Add coverage config to pyproject.toml

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mguschin
2026-04-28 12:27:42 +03:00
parent 5ead89e0cf
commit fc65e591b3
18 changed files with 882 additions and 31 deletions

View File

@@ -0,0 +1,40 @@
"""Unit tests for _parse_custom_fields — no DB or HTTP needed."""
import json
from web.routes.evotor_webhooks import _parse_custom_fields
def test_none_returns_empty():
assert _parse_custom_fields(None) == {}
def test_dict_passthrough():
d = {"email": "a@b.com", "phone": "+79001234567"}
assert _parse_custom_fields(d) == d
def test_json_string_parsed():
raw = json.dumps({"email": "a@b.com", "firstName": "Иван"})
result = _parse_custom_fields(raw)
assert result["email"] == "a@b.com"
assert result["firstName"] == "Иван"
def test_plain_string_returns_empty():
# A plain non-JSON string cannot be parsed into fields
assert _parse_custom_fields("just some text") == {}
def test_json_array_returns_empty():
# A JSON array is not a dict — treat as unparseable
assert _parse_custom_fields("[1, 2, 3]") == {}
def test_empty_string_returns_empty():
assert _parse_custom_fields("") == {}
def test_nested_values_preserved():
raw = {"email": "x@y.com", "meta": {"key": "val"}}
result = _parse_custom_fields(raw)
assert result["meta"]["key"] == "val"