feat: Implement MFA authentication, add ride statistics model, and update various services, APIs, and tests across the application.

This commit is contained in:
pacnpal
2025-12-28 17:32:53 -05:00
parent aa56c46c27
commit c95f99ca10
452 changed files with 7948 additions and 6073 deletions

View File

@@ -3,12 +3,13 @@ Test utilities and helpers following Django styleguide patterns.
Provides reusable testing patterns and assertion helpers.
"""
from typing import Dict, Any, Optional, List
from datetime import date, datetime
from django.test import TestCase
from typing import Any
from django.contrib.auth import get_user_model
from rest_framework.test import APITestCase
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APITestCase
User = get_user_model()
@@ -22,8 +23,8 @@ class ApiTestMixin:
*,
status_code: int = status.HTTP_200_OK,
response_status: str = "success",
data_type: Optional[type] = None,
contains_fields: Optional[List[str]] = None,
data_type: type | None = None,
contains_fields: list[str] | None = None,
):
"""
Assert API response has correct structure and content.
@@ -68,8 +69,8 @@ class ApiTestMixin:
response,
*,
status_code: int,
error_code: Optional[str] = None,
message_contains: Optional[str] = None,
error_code: str | None = None,
message_contains: str | None = None,
):
"""
Assert API response is an error with specific characteristics.
@@ -94,9 +95,9 @@ class ApiTestMixin:
self,
response,
*,
expected_count: Optional[int] = None,
has_next: Optional[bool] = None,
has_previous: Optional[bool] = None,
expected_count: int | None = None,
has_next: bool | None = None,
has_previous: bool | None = None,
):
"""
Assert API response has correct pagination structure.
@@ -136,7 +137,7 @@ class ApiTestMixin:
class ModelTestMixin:
"""Mixin providing common model testing utilities."""
def assertModelFields(self, instance, expected_fields: Dict[str, Any]):
def assertModelFields(self, instance, expected_fields: dict[str, Any]):
"""
Assert model instance has expected field values.
@@ -155,8 +156,8 @@ class ModelTestMixin:
def assertModelValidation(
self,
model_class,
invalid_data: Dict[str, Any],
expected_errors: List[str],
invalid_data: dict[str, Any],
expected_errors: list[str],
):
"""
Assert model validation catches expected errors.
@@ -175,7 +176,7 @@ class ModelTestMixin:
for expected_error in expected_errors:
self.assertIn(expected_error, exception_str)
def assertDatabaseConstraint(self, model_factory, invalid_data: Dict[str, Any]):
def assertDatabaseConstraint(self, model_factory, invalid_data: dict[str, Any]):
"""
Assert database constraint is enforced.
@@ -299,7 +300,7 @@ class GeographyTestMixin:
point2: (latitude, longitude) tuple
max_distance_km: Maximum allowed distance in kilometers
"""
from math import radians, cos, sin, asin, sqrt
from math import asin, cos, radians, sin, sqrt
lat1, lon1 = point1
lat2, lon2 = point2