Refactor database module and add testing utilities
Simplify database module by re-organizing engine creation, session handling, and removing redundant methods. Introduce SQLite compatibility for testing and add a utility module for test database setup and teardown. Integrate initial unit tests for user models and update dependencies for security and testing.
This commit is contained in:
29
backend/tests/models/test_user.py
Normal file
29
backend/tests/models/test_user.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# tests/models/test_user.py
|
||||
import uuid
|
||||
from app.models.user import User
|
||||
|
||||
def test_create_user(db_session):
|
||||
# Arrange
|
||||
user_id = uuid.uuid4()
|
||||
new_user = User(
|
||||
id=user_id,
|
||||
email="test@example.com",
|
||||
password_hash="hashedpassword",
|
||||
first_name="Test",
|
||||
last_name="User",
|
||||
phone_number="1234567890",
|
||||
is_active=True,
|
||||
is_superuser=False,
|
||||
preferences={"theme": "dark"},
|
||||
)
|
||||
db_session.add(new_user)
|
||||
|
||||
# Act
|
||||
db_session.commit()
|
||||
created_user = db_session.query(User).filter_by(email="test@example.com").first()
|
||||
|
||||
# Assert
|
||||
assert created_user is not None
|
||||
assert created_user.email == "test@example.com"
|
||||
assert created_user.first_name == "Test"
|
||||
assert created_user.preferences == {"theme": "dark"}
|
||||
Reference in New Issue
Block a user