mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-02-14 08:29:29 -06:00
@@ -13,13 +13,17 @@ from app.models import User, Project, Client, Invoice, InvoiceItem, Settings
|
||||
@pytest.fixture
|
||||
def app():
|
||||
"""Create and configure a test app instance"""
|
||||
# Set test database URL before creating app
|
||||
os.environ['DATABASE_URL'] = 'sqlite:///:memory:'
|
||||
# Create app with test configuration
|
||||
test_config = {
|
||||
'TESTING': True,
|
||||
'SQLALCHEMY_DATABASE_URI': 'sqlite:///:memory:',
|
||||
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
|
||||
'WTF_CSRF_ENABLED': False,
|
||||
'SECRET_KEY': 'test-secret-key-do-not-use-in-production',
|
||||
'SERVER_NAME': 'localhost:5000',
|
||||
}
|
||||
|
||||
app = create_app()
|
||||
app.config['TESTING'] = True
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
|
||||
app.config['WTF_CSRF_ENABLED'] = False
|
||||
app = create_app(test_config)
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
@@ -45,10 +49,10 @@ def client_fixture(app):
|
||||
def test_user(app):
|
||||
"""Create a test user"""
|
||||
with app.app_context():
|
||||
user = User(username='testuser', email='test@example.com', is_admin=True)
|
||||
user.set_password('password123')
|
||||
user = User(username='testuser', role='admin', email='test@example.com')
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
db.session.refresh(user) # Refresh to keep object in session
|
||||
return user
|
||||
|
||||
|
||||
@@ -56,13 +60,15 @@ def test_user(app):
|
||||
def test_client_model(app, test_user):
|
||||
"""Create a test client"""
|
||||
with app.app_context():
|
||||
# Re-query user to get it in this session
|
||||
user = db.session.get(User, test_user.id)
|
||||
client = Client(
|
||||
name='Test Client',
|
||||
email='client@example.com',
|
||||
created_by=test_user.id
|
||||
email='client@example.com'
|
||||
)
|
||||
db.session.add(client)
|
||||
db.session.commit()
|
||||
db.session.refresh(client) # Refresh to keep object in session
|
||||
return client
|
||||
|
||||
|
||||
@@ -70,16 +76,20 @@ def test_client_model(app, test_user):
|
||||
def test_project(app, test_user, test_client_model):
|
||||
"""Create a test project"""
|
||||
with app.app_context():
|
||||
# Re-query user and client to get them in this session
|
||||
user = db.session.get(User, test_user.id)
|
||||
client = db.session.get(Client, test_client_model.id)
|
||||
project = Project(
|
||||
name='Test Project',
|
||||
client_id=test_client_model.id,
|
||||
created_by=test_user.id,
|
||||
client_id=client.id,
|
||||
billable=True,
|
||||
hourly_rate=Decimal('100.00'),
|
||||
status='active'
|
||||
hourly_rate=Decimal('100.00')
|
||||
)
|
||||
project.created_by = user.id
|
||||
project.status = 'active'
|
||||
db.session.add(project)
|
||||
db.session.commit()
|
||||
db.session.refresh(project) # Refresh to keep object in session
|
||||
return project
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ Smoke tests for invoice currency functionality
|
||||
Simple high-level tests to ensure the system works end-to-end
|
||||
"""
|
||||
import pytest
|
||||
import os
|
||||
from datetime import date, timedelta
|
||||
from decimal import Decimal
|
||||
from app import create_app, db
|
||||
@@ -13,13 +12,17 @@ from app.models import User, Project, Client, Invoice, Settings
|
||||
@pytest.fixture
|
||||
def app():
|
||||
"""Create and configure a test app instance"""
|
||||
# Set test database URL before creating app
|
||||
os.environ['DATABASE_URL'] = 'sqlite:///:memory:'
|
||||
# Create app with test configuration
|
||||
test_config = {
|
||||
'TESTING': True,
|
||||
'SQLALCHEMY_DATABASE_URI': 'sqlite:///:memory:',
|
||||
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
|
||||
'WTF_CSRF_ENABLED': False,
|
||||
'SECRET_KEY': 'test-secret-key-do-not-use-in-production',
|
||||
'SERVER_NAME': 'localhost:5000',
|
||||
}
|
||||
|
||||
app = create_app()
|
||||
app.config['TESTING'] = True
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
|
||||
app.config['WTF_CSRF_ENABLED'] = False
|
||||
app = create_app(test_config)
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
@@ -32,22 +35,24 @@ def test_invoice_currency_smoke(app):
|
||||
"""Smoke test: Create invoice and verify it uses settings currency"""
|
||||
with app.app_context():
|
||||
# Setup: Create user, client, project
|
||||
user = User(username='smokeuser', email='smoke@example.com', is_admin=True)
|
||||
user.set_password('password')
|
||||
user = User(username='smokeuser', role='admin', email='smoke@example.com')
|
||||
db.session.add(user)
|
||||
db.session.flush() # Flush to get user.id
|
||||
|
||||
client = Client(name='Smoke Client', email='client@example.com', created_by=1)
|
||||
client = Client(name='Smoke Client', email='client@example.com')
|
||||
db.session.add(client)
|
||||
db.session.flush() # Flush to get client.id
|
||||
|
||||
project = Project(
|
||||
name='Smoke Project',
|
||||
client_id=1,
|
||||
created_by=1,
|
||||
client_id=client.id,
|
||||
billable=True,
|
||||
hourly_rate=Decimal('100.00'),
|
||||
status='active'
|
||||
hourly_rate=Decimal('100.00')
|
||||
)
|
||||
project.created_by = user.id
|
||||
project.status = 'active'
|
||||
db.session.add(project)
|
||||
db.session.flush() # Flush to get project.id
|
||||
|
||||
# Set currency in settings
|
||||
settings = Settings.get_settings()
|
||||
@@ -78,22 +83,24 @@ def test_pdf_generator_uses_settings_currency(app):
|
||||
"""Smoke test: Verify PDF generator uses settings currency"""
|
||||
with app.app_context():
|
||||
# Setup
|
||||
user = User(username='pdfuser', email='pdf@example.com', is_admin=True)
|
||||
user.set_password('password')
|
||||
user = User(username='pdfuser', role='admin', email='pdf@example.com')
|
||||
db.session.add(user)
|
||||
db.session.flush() # Flush to get user.id
|
||||
|
||||
client = Client(name='PDF Client', email='pdf@example.com', created_by=1)
|
||||
client = Client(name='PDF Client', email='pdf@example.com')
|
||||
db.session.add(client)
|
||||
db.session.flush() # Flush to get client.id
|
||||
|
||||
project = Project(
|
||||
name='PDF Project',
|
||||
client_id=1,
|
||||
created_by=1,
|
||||
client_id=client.id,
|
||||
billable=True,
|
||||
hourly_rate=Decimal('150.00'),
|
||||
status='active'
|
||||
hourly_rate=Decimal('150.00')
|
||||
)
|
||||
project.created_by = user.id
|
||||
project.status = 'active'
|
||||
db.session.add(project)
|
||||
db.session.flush() # Flush to get project.id
|
||||
|
||||
settings = Settings.get_settings()
|
||||
settings.currency = 'SEK'
|
||||
|
||||
Reference in New Issue
Block a user