opencode-config/.opencode/templates/backend/{{cookiecutter.project_name}}/tests/unit/test_user.py
Sergey 35b6c6e542
feat(infra): cookiecutter templates backend fullstack cli (#235)
* feat(infra): backend cookiecutter template with fastapi tortoise

* feat(infra): cli cookiecutter template with typer entry point

* feat(infra): fullstack cookiecutter template with sveltekit frontend

* test(infra): cookiecutter template tests and render fixes

* style(infra): ruff cleanup for cookiecutter template tests

* style(infra): ruff format cookiecutter template tests

* fix(infra): handle use_db no use_auth no in cookiecutter

---------

Co-authored-by: opencode-agent <agent@opencode.local>
2026-08-03 17:06:24 +03:00

31 lines
No EOL
971 B
Python

"""Unit tests for the User model."""
from __future__ import annotations
import pytest
{% if cookiecutter.use_auth == "yes" %}
from {{ cookiecutter.project_name }}.services.auth_service import AuthService
def test_hash_password_is_not_plain() -> None:
"""hash_password must not store the plain text."""
hashed = AuthService.hash_password("mypassword")
assert hashed != "mypassword"
assert hashed.startswith("$2") # bcrypt prefix
def test_verify_password_roundtrip() -> None:
"""verify_password must accept the correct password."""
hashed = AuthService.hash_password("mypassword")
assert AuthService.verify_password("mypassword", hashed) is True
assert AuthService.verify_password("wrong", hashed) is False
{% else %}
def test_user_model_table_name() -> None:
"""User model must use the 'users' table."""
from {{ cookiecutter.project_name }}.db.models.user import User
assert User._meta.db_table == "users"
{% endif %}