mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-02-13 23:59:00 -06:00
- Normalize line endings from CRLF to LF across all files to match .editorconfig - Standardize quote style from single quotes to double quotes - Normalize whitespace and formatting throughout codebase - Apply consistent code style across 372 files including: * Application code (models, routes, services, utils) * Test files * Configuration files * CI/CD workflows This ensures consistency with the project's .editorconfig settings and improves code maintainability.
85 lines
2.5 KiB
Python
85 lines
2.5 KiB
Python
"""
|
|
Tests for ApiTokenService.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
# Skip entire test file - ApiTokenService no longer exists
|
|
pytestmark = pytest.mark.skip(reason="ApiTokenService no longer exists in app.services")
|
|
|
|
# Imports commented out since the service doesn't exist
|
|
# from app.services import ApiTokenService
|
|
# from app.models import ApiToken, User
|
|
# from app import db
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_create_token_success(app, test_user):
|
|
"""Test successful token creation"""
|
|
service = ApiTokenService()
|
|
|
|
result = service.create_token(
|
|
user_id=test_user.id,
|
|
name="Test Token",
|
|
description="Test description",
|
|
scopes="read:projects,write:time_entries",
|
|
expires_days=30,
|
|
)
|
|
|
|
assert result["success"] is True
|
|
assert result["token"] is not None
|
|
assert result["api_token"] is not None
|
|
assert result["api_token"].name == "Test Token"
|
|
assert result["api_token"].user_id == test_user.id
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_create_token_invalid_user(app):
|
|
"""Test token creation with invalid user"""
|
|
service = ApiTokenService()
|
|
|
|
result = service.create_token(user_id=99999, name="Test Token", scopes="read:projects") # Non-existent user
|
|
|
|
assert result["success"] is False
|
|
assert result["error"] == "invalid_user"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_validate_scopes_valid(app):
|
|
"""Test scope validation with valid scopes"""
|
|
service = ApiTokenService()
|
|
|
|
result = service.validate_scopes("read:projects,write:time_entries")
|
|
assert result["valid"] is True
|
|
assert len(result["invalid"]) == 0
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_validate_scopes_invalid(app):
|
|
"""Test scope validation with invalid scopes"""
|
|
service = ApiTokenService()
|
|
|
|
result = service.validate_scopes("read:projects,invalid:scope")
|
|
assert result["valid"] is False
|
|
assert "invalid:scope" in result["invalid"]
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_rotate_token(app, test_user):
|
|
"""Test token rotation"""
|
|
service = ApiTokenService()
|
|
|
|
# Create initial token
|
|
create_result = service.create_token(user_id=test_user.id, name="Original Token", scopes="read:projects")
|
|
|
|
assert create_result["success"] is True
|
|
original_token_id = create_result["api_token"].id
|
|
|
|
# Rotate token
|
|
rotate_result = service.rotate_token(token_id=original_token_id, user_id=test_user.id)
|
|
|
|
assert rotate_result["success"] is True
|
|
assert rotate_result["new_token"] is not None
|
|
assert rotate_result["old_token"].is_active is False
|
|
assert rotate_result["api_token"].id != original_token_id
|