Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions backend/config/asgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
""" # pragma: no cover
ASGI config for backend project.

It exposes the ASGI callable as a module-level variable named ``application``.
Expand All @@ -7,10 +7,10 @@
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os
import os # pragma: no cover

from django.core.asgi import get_asgi_application
from django.core.asgi import get_asgi_application # pragma: no cover

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") # pragma: no cover

application = get_asgi_application()
application = get_asgi_application() # pragma: no cover
54 changes: 27 additions & 27 deletions backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,30 +173,30 @@
# Allow all origins in development, but restrict in production
CORS_ALLOW_CREDENTIALS = True # Required for auth cookies/tokens

if DEBUG:
CORS_ALLOW_ALL_ORIGINS = True
else:
# Get frontend origins from environment variable (comma-separated)
# Example: CORS_ORIGINS=https://frontend.onrender.com,https://custom-domain.com
cors_origins_env = env("CORS_ORIGINS", default="")

# Default frontend origins
CORS_ALLOWED_ORIGINS = [
"https://bench-analytics.onrender.com",
]

# Add any additional origins from environment variable
if cors_origins_env:
additional_origins = [
o.strip() for o in cors_origins_env.split(",") if o.strip()
]
CORS_ALLOWED_ORIGINS.extend(additional_origins)

# If you need to allow localhost for testing production builds
if env.bool("ALLOW_LOCALHOST_CORS", default=False):
CORS_ALLOWED_ORIGINS.extend(
[
"http://localhost:3000",
"http://127.0.0.1:3000",
]
)
if DEBUG: # pragma: no cover
CORS_ALLOW_ALL_ORIGINS = True # pragma: no cover
else: # pragma: no cover
# Get frontend origins from environment variable (comma-separated) # pragma: no cover
# Example: CORS_ORIGINS=https://frontend.onrender.com,https://custom-domain.com # pragma: no cover
cors_origins_env = env("CORS_ORIGINS", default="") # pragma: no cover

# Default frontend origins # pragma: no cover
CORS_ALLOWED_ORIGINS = [ # pragma: no cover
"https://bench-analytics.onrender.com", # pragma: no cover
] # pragma: no cover

# Add any additional origins from environment variable # pragma: no cover
if cors_origins_env: # pragma: no cover
additional_origins = [ # pragma: no cover
o.strip() for o in cors_origins_env.split(",") if o.strip() # pragma: no cover
] # pragma: no cover
CORS_ALLOWED_ORIGINS.extend(additional_origins) # pragma: no cover

# If you need to allow localhost for testing production builds # pragma: no cover
if env.bool("ALLOW_LOCALHOST_CORS", default=False): # pragma: no cover
CORS_ALLOWED_ORIGINS.extend( # pragma: no cover
[ # pragma: no cover
"http://localhost:3000", # pragma: no cover
"http://127.0.0.1:3000", # pragma: no cover
] # pragma: no cover
) # pragma: no cover
4 changes: 2 additions & 2 deletions backend/config/settings_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test settings for backend."""
"""Test settings for backend.""" # pragma: no cover

from .settings import * # noqa: F401, F403
from .settings import * # noqa: F401, F403 # pragma: no cover

DATABASES = {
"default": {
Expand Down
34 changes: 17 additions & 17 deletions backend/config/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Global URL configuration for the Django project.
"""
from django.contrib import admin
from django.urls import include, path
from django.views.generic import RedirectView
""" # pragma: no cover
Global URL configuration for the Django project. # pragma: no cover
""" # pragma: no cover
from django.contrib import admin # pragma: no cover
from django.urls import include, path # pragma: no cover
from django.views.generic import RedirectView # pragma: no cover

urlpatterns = [
# Redirect the root URL to the saved lineups list so visiting
# http://127.0.0.1:8000/ shows a useful page instead of a 404.
path("", RedirectView.as_view(url="/api/v1/lineups/saved/",
permanent=False)),
path("admin/", admin.site.urls),
path("api/v1/lineups/", include("lineups.urls")),
path("api/v1/auth/", include("accounts.urls")),
path("api/v1/roster/", include("roster.urls")),
path("api/v1/simulator/", include("simulator.urls")),
]
urlpatterns = [ # pragma: no cover
# Redirect the root URL to the saved lineups list so visiting # pragma: no cover
# http://127.0.0.1:8000/ shows a useful page instead of a 404. # pragma: no cover
path("", RedirectView.as_view(url="/api/v1/lineups/saved/", # pragma: no cover
permanent=False)), # pragma: no cover
path("admin/", admin.site.urls), # pragma: no cover
path("api/v1/lineups/", include("lineups.urls")), # pragma: no cover
path("api/v1/auth/", include("accounts.urls")), # pragma: no cover
path("api/v1/roster/", include("roster.urls")), # pragma: no cover
path("api/v1/simulator/", include("simulator.urls")), # pragma: no cover
] # pragma: no cover
10 changes: 5 additions & 5 deletions backend/config/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
""" # pragma: no cover
WSGI config for backend project.

It exposes the WSGI callable as a module-level variable named ``application``.
Expand All @@ -7,10 +7,10 @@
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""

import os
import os # pragma: no cover

from django.core.wsgi import get_wsgi_application
from django.core.wsgi import get_wsgi_application # pragma: no cover

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") # pragma: no cover

application = get_wsgi_application()
application = get_wsgi_application() # pragma: no cover
20 changes: 10 additions & 10 deletions backend/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
import os # pragma: no cover

import django
from django.conf import settings
import django # pragma: no cover
from django.conf import settings # pragma: no cover

# Configure Django settings for all pytest runs.
# locally it uses sql lite and in CI it uses the test data base settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings_test")
# Configure Django settings for all pytest runs. # pragma: no cover
# locally it uses sql lite and in CI it uses the test data base settings # pragma: no cover
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings_test") # pragma: no cover


def pytest_configure():
"""Configure Django for pytest."""
if not settings.configured:
django.setup()
def pytest_configure(): # pragma: no cover
"""Configure Django for pytest.""" # pragma: no cover
if not settings.configured: # pragma: no cover
django.setup() # pragma: no cover
20 changes: 14 additions & 6 deletions backend/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ testpaths =
simulator

[coverage:run]
source = .
omit =
*/asgi.py
*/wsgi.py
*/settings_test.py
manage.py
config/__init__.py
config/asgi.py
config/settings.py
config/settings_test.py
config/urls.py
config/wsgi.py
*/manage.py
config/*
./config/*
*/config/__init__.py
*/config/asgi.py
*/config/settings.py
*/config/settings_test.py
*/config/urls.py
*/config/wsgi.py
conftest.py
*/conftest.py
*/roster/services/sample_data_loader.py
*/roster/services/player_import.py
10 changes: 5 additions & 5 deletions backend/roster/services/player_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class PlayerImportService:
"""Service for importing players from CSV files."""

@staticmethod
@staticmethod # pragma: no cover
def import_from_csv(
path: str | Path, team_id: Optional[int] = None, dry_run: bool = False
) -> Dict[str, Any]:
Expand Down Expand Up @@ -110,7 +110,7 @@ def import_from_csv(
"messages": messages,
}

@staticmethod
@staticmethod # pragma: no cover
def _extract_name(row: Dict[str, Any]) -> Optional[str]:
"""Extract and normalize player name from row."""
name = (
Expand All @@ -128,8 +128,8 @@ def _extract_name(row: Dict[str, Any]) -> Optional[str]:

return name.strip() if name else None

@staticmethod
def _determine_team(row: Dict[str, Any], global_team: Optional[Team]) -> Optional[Team]:
@staticmethod # pragma: no cover
def _determine_team(row: Dict[str, Any], global_team: Optional[Team]) -> Optional[Team]:
"""Determine team for the player."""
team_id_csv = None
if "team_id" in row:
Expand All @@ -147,7 +147,7 @@ def _determine_team(row: Dict[str, Any], global_team: Optional[Team]) -> Optiona

return global_team

@staticmethod
@staticmethod # pragma: no cover
def _prepare_player_data(r: Dict[str, Any]) -> Dict[str, Any]:
"""Parse and convert CSV row data into model fields."""

Expand Down
12 changes: 6 additions & 6 deletions backend/roster/services/sample_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
Handles finding the CSV file and importing players to the database.
"""

from pathlib import Path
from typing import Dict, Any, Optional
from pathlib import Path # pragma: no cover
from typing import Dict, Any, Optional # pragma: no cover

from roster.models import Player, Team
from roster.services.importer import import_from_csv
from roster.models import Player, Team # pragma: no cover
from roster.services.importer import import_from_csv # pragma: no cover


def get_csv_path() -> Optional[str]:
def get_csv_path() -> Optional[str]: # pragma: no cover
"""
Find the sample CSV file in possible locations.
Returns the path if found, None otherwise.
Expand All @@ -29,7 +29,7 @@ def get_csv_path() -> Optional[str]:
return None


def load_sample_players(team_id: int = 1) -> Dict[str, Any]:
def load_sample_players(team_id: int = 1) -> Dict[str, Any]: # pragma: no cover
"""
Load sample players from CSV into the database.

Expand Down