mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-01-04 10:40:23 -06:00
Change tests
This commit is contained in:
@@ -515,6 +515,12 @@ def test_client_obj(test_client):
|
||||
return test_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_user(user):
|
||||
"""Alias for user fixture"""
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth_user(user):
|
||||
"""Alias for user fixture"""
|
||||
|
||||
@@ -159,10 +159,10 @@ class TestActivityModel:
|
||||
class TestActivityAPIEndpoints:
|
||||
"""Tests for Activity Feed API endpoints"""
|
||||
|
||||
def test_get_activities(self, client, auth_headers, test_user, test_project):
|
||||
def test_get_activities(self, authenticated_client, test_user, test_project):
|
||||
"""Test GET /api/activities endpoint"""
|
||||
# Create some test activities
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
for i in range(3):
|
||||
Activity.log(
|
||||
user_id=test_user.id,
|
||||
@@ -173,7 +173,7 @@ class TestActivityAPIEndpoints:
|
||||
description=f'Activity {i}'
|
||||
)
|
||||
|
||||
response = client.get('/api/activities', headers=auth_headers)
|
||||
response = authenticated_client.get('/api/activities')
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.get_json()
|
||||
@@ -182,9 +182,9 @@ class TestActivityAPIEndpoints:
|
||||
assert 'total' in data
|
||||
assert 'pages' in data
|
||||
|
||||
def test_get_activities_with_entity_type_filter(self, client, auth_headers, test_user, test_project, test_task):
|
||||
def test_get_activities_with_entity_type_filter(self, authenticated_client, test_user, test_project, test_task):
|
||||
"""Test filtering activities by entity type"""
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
Activity.log(
|
||||
user_id=test_user.id,
|
||||
action='created',
|
||||
@@ -204,10 +204,7 @@ class TestActivityAPIEndpoints:
|
||||
)
|
||||
|
||||
# Filter by project entity type
|
||||
response = client.get(
|
||||
'/api/activities?entity_type=project',
|
||||
headers=auth_headers
|
||||
)
|
||||
response = authenticated_client.get('/api/activities?entity_type=project')
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.get_json()
|
||||
@@ -216,9 +213,9 @@ class TestActivityAPIEndpoints:
|
||||
for act in data['activities']
|
||||
)
|
||||
|
||||
def test_get_activities_with_pagination(self, client, auth_headers, test_user, test_project):
|
||||
def test_get_activities_with_pagination(self, authenticated_client, test_user, test_project):
|
||||
"""Test pagination of activities"""
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
# Create 15 activities
|
||||
for i in range(15):
|
||||
Activity.log(
|
||||
@@ -231,10 +228,7 @@ class TestActivityAPIEndpoints:
|
||||
)
|
||||
|
||||
# Get first page
|
||||
response = client.get(
|
||||
'/api/activities?limit=5&page=1',
|
||||
headers=auth_headers
|
||||
)
|
||||
response = authenticated_client.get('/api/activities?limit=5&page=1')
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.get_json()
|
||||
@@ -242,18 +236,15 @@ class TestActivityAPIEndpoints:
|
||||
assert data['has_next'] is True
|
||||
|
||||
# Get second page
|
||||
response = client.get(
|
||||
'/api/activities?limit=5&page=2',
|
||||
headers=auth_headers
|
||||
)
|
||||
response = authenticated_client.get('/api/activities?limit=5&page=2')
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.get_json()
|
||||
assert len(data['activities']) == 5
|
||||
|
||||
def test_get_activity_stats(self, client, auth_headers, test_user, test_project, test_task):
|
||||
def test_get_activity_stats(self, authenticated_client, test_user, test_project, test_task):
|
||||
"""Test GET /api/activities/stats endpoint"""
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
# Create varied activities
|
||||
Activity.log(
|
||||
user_id=test_user.id,
|
||||
@@ -282,7 +273,7 @@ class TestActivityAPIEndpoints:
|
||||
description='Task created'
|
||||
)
|
||||
|
||||
response = client.get('/api/activities/stats', headers=auth_headers)
|
||||
response = authenticated_client.get('/api/activities/stats')
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.get_json()
|
||||
@@ -295,13 +286,13 @@ class TestActivityAPIEndpoints:
|
||||
class TestActivityIntegration:
|
||||
"""Tests for activity logging integration in routes"""
|
||||
|
||||
def test_project_create_logs_activity(self, client, auth_headers, test_client):
|
||||
def test_project_create_logs_activity(self, admin_authenticated_client, test_client):
|
||||
"""Test that creating a project logs an activity"""
|
||||
with client.application.app_context():
|
||||
with admin_authenticated_client.application.app_context():
|
||||
# Count activities before
|
||||
before_count = Activity.query.count()
|
||||
|
||||
response = client.post(
|
||||
response = admin_authenticated_client.post(
|
||||
'/projects/create',
|
||||
data={
|
||||
'name': 'Test Activity Project',
|
||||
@@ -309,11 +300,10 @@ class TestActivityIntegration:
|
||||
'billable': 'on',
|
||||
'description': 'Test project for activity'
|
||||
},
|
||||
headers=auth_headers,
|
||||
follow_redirects=False
|
||||
)
|
||||
|
||||
with client.application.app_context():
|
||||
with admin_authenticated_client.application.app_context():
|
||||
# Check activity was logged
|
||||
after_count = Activity.query.count()
|
||||
assert after_count == before_count + 1
|
||||
@@ -323,12 +313,12 @@ class TestActivityIntegration:
|
||||
assert activity.entity_type == 'project'
|
||||
assert 'Test Activity Project' in activity.description
|
||||
|
||||
def test_task_create_logs_activity(self, client, auth_headers, test_project):
|
||||
def test_task_create_logs_activity(self, authenticated_client, test_project):
|
||||
"""Test that creating a task logs an activity"""
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
before_count = Activity.query.count()
|
||||
|
||||
response = client.post(
|
||||
response = authenticated_client.post(
|
||||
'/tasks/create',
|
||||
data={
|
||||
'project_id': test_project.id,
|
||||
@@ -336,11 +326,10 @@ class TestActivityIntegration:
|
||||
'priority': 'high',
|
||||
'description': 'Test task for activity'
|
||||
},
|
||||
headers=auth_headers,
|
||||
follow_redirects=False
|
||||
)
|
||||
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
after_count = Activity.query.count()
|
||||
assert after_count == before_count + 1
|
||||
|
||||
@@ -349,22 +338,21 @@ class TestActivityIntegration:
|
||||
assert activity.entity_type == 'task'
|
||||
assert 'Test Activity Task' in activity.description
|
||||
|
||||
def test_timer_start_logs_activity(self, client, auth_headers, test_project):
|
||||
def test_timer_start_logs_activity(self, authenticated_client, test_project):
|
||||
"""Test that starting a timer logs an activity"""
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
before_count = Activity.query.count()
|
||||
|
||||
response = client.post(
|
||||
response = authenticated_client.post(
|
||||
'/timer/start',
|
||||
data={
|
||||
'project_id': test_project.id,
|
||||
'notes': 'Test timer'
|
||||
},
|
||||
headers=auth_headers,
|
||||
follow_redirects=False
|
||||
)
|
||||
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
after_count = Activity.query.count()
|
||||
assert after_count == before_count + 1
|
||||
|
||||
@@ -373,9 +361,9 @@ class TestActivityIntegration:
|
||||
assert activity.entity_type == 'time_entry'
|
||||
assert test_project.name in activity.description
|
||||
|
||||
def test_timer_stop_logs_activity(self, client, auth_headers, test_user, test_project):
|
||||
def test_timer_stop_logs_activity(self, authenticated_client, test_user, test_project):
|
||||
"""Test that stopping a timer logs an activity"""
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
# Create an active timer
|
||||
from app.models.time_entry import local_now
|
||||
timer = TimeEntry(
|
||||
@@ -389,13 +377,12 @@ class TestActivityIntegration:
|
||||
|
||||
before_count = Activity.query.count()
|
||||
|
||||
response = client.post(
|
||||
response = authenticated_client.post(
|
||||
'/timer/stop',
|
||||
headers=auth_headers,
|
||||
follow_redirects=False
|
||||
)
|
||||
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
after_count = Activity.query.count()
|
||||
assert after_count == before_count + 1
|
||||
|
||||
@@ -408,9 +395,9 @@ class TestActivityIntegration:
|
||||
class TestActivityWidget:
|
||||
"""Tests for the activity feed widget on dashboard"""
|
||||
|
||||
def test_dashboard_includes_activities(self, client, auth_headers, test_user, test_project):
|
||||
def test_dashboard_includes_activities(self, authenticated_client, test_user, test_project):
|
||||
"""Test that the dashboard includes recent activities"""
|
||||
with client.application.app_context():
|
||||
with authenticated_client.application.app_context():
|
||||
# Create some activities
|
||||
Activity.log(
|
||||
user_id=test_user.id,
|
||||
@@ -421,7 +408,7 @@ class TestActivityWidget:
|
||||
description='Test activity'
|
||||
)
|
||||
|
||||
response = client.get('/dashboard', headers=auth_headers)
|
||||
response = authenticated_client.get('/dashboard')
|
||||
assert response.status_code == 200
|
||||
assert b'Recent Activity' in response.data
|
||||
assert b'Test activity' in response.data
|
||||
|
||||
Reference in New Issue
Block a user