Skip to content
Open
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
18 changes: 13 additions & 5 deletions backend/routers/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi import APIRouter, Depends, HTTPException, status
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTPException and status are imported but not used anywhere in this module (and the new func/case import makes this import block part of the changed hunk). Please remove unused FastAPI imports to avoid lint warnings and keep imports minimal.

Suggested change
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi import APIRouter, Depends

Copilot uses AI. Check for mistakes.
from sqlalchemy.orm import Session
from sqlalchemy import func, case
from typing import List

from backend.database import get_db
Expand All @@ -20,11 +21,18 @@ def get_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):

@router.get("/stats")
def get_system_stats(db: Session = Depends(get_db)):
total_users = db.query(User).count()
admin_users = db.query(User).filter(User.role == UserRole.ADMIN).count()
"""
Get system statistics.
Optimized: Uses a single query with aggregates instead of 3 separate count queries.
"""
stats = db.query(
func.count(User.id).label('total_users'),
func.sum(case((User.role == UserRole.ADMIN, 1), else_=0)).label('admin_count'),
func.sum(case((User.is_active == True, 1), else_=0)).label('active_users')
).first()
Comment on lines +28 to +32
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The /admin/stats endpoint logic was refactored to an aggregate query, but there are currently no tests covering this endpoint. Please add a test that seeds a few users (admin/non-admin, active/inactive) and asserts the returned totals match expected counts so the refactor is protected against regressions.

Copilot uses AI. Check for mistakes.

return {
"total_users": total_users,
"admin_count": admin_users,
"active_users": db.query(User).filter(User.is_active == True).count(),
"total_users": stats.total_users or 0,
"admin_count": stats.admin_count or 0,
"active_users": stats.active_users or 0,
}
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
asyncio_mode = auto
asyncio_default_fixture_loop_scope = function
Comment on lines +1 to +3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Search for pytest-asyncio version requirements in the repository
find . -type f \( -name "*.txt" -o -name "*.toml" -o -name "*.cfg" -o -name "*.py" -o -name "*.lock" -o -name "*.yaml" -o -name "*.yml" \) | head -20

Repository: RohanExploit/VishwaGuru

Length of output: 917


🏁 Script executed:

# Look for dependency files
git ls-files | grep -E "(requirements|setup|pyproject|poetry|pipfile)" | head -20

Repository: RohanExploit/VishwaGuru

Length of output: 177


🏁 Script executed:

# Check for pytest-asyncio in common dependency files
for file in requirements.txt requirements-dev.txt setup.py setup.cfg pyproject.toml poetry.lock Pipfile Pipfile.lock .python-version; do
  if [ -f "$file" ]; then
    echo "=== $file ==="
    cat "$file" | head -50
  fi
done

Repository: RohanExploit/VishwaGuru

Length of output: 49


🏁 Script executed:

echo "=== backend/requirements.txt ===" && cat backend/requirements.txt
echo ""
echo "=== backend/requirements-render.txt ===" && cat backend/requirements-render.txt

Repository: RohanExploit/VishwaGuru

Length of output: 984


🏁 Script executed:

# Search for pytest-asyncio anywhere in the repository
rg "pytest-asyncio" -i

Repository: RohanExploit/VishwaGuru

Length of output: 49


🏁 Script executed:

# Also check functions/requirements.txt and any other requirements files
find . -name "*requirements*.txt" -o -name "Pipfile*" -o -name "pyproject.toml" | grep -v node_modules

Repository: RohanExploit/VishwaGuru

Length of output: 156


🏁 Script executed:

cat functions/requirements.txt

Repository: RohanExploit/VishwaGuru

Length of output: 298


Add pytest-asyncio to project dependencies.

The pytest.ini file uses pytest-asyncio specific configuration options (asyncio_mode and asyncio_default_fixture_loop_scope), but pytest-asyncio is not listed as a dependency in any requirements file. Add it to backend/requirements.txt (and backend/requirements-render.txt if async tests run there) to enable these configuration options. Recommend a version constraint of pytest-asyncio>=0.23.0 to support asyncio_default_fixture_loop_scope.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pytest.ini` around lines 1 - 3, The project uses pytest-asyncio options
(asyncio_mode and asyncio_default_fixture_loop_scope) in pytest.ini but the
dependency is missing; add pytest-asyncio>=0.23.0 to backend/requirements.txt
(and backend/requirements-render.txt if async tests run there) so pytest-asyncio
is installed and the pytest.ini keys are supported; ensure the version
constraint is >=0.23.0 to guarantee support for
asyncio_default_fixture_loop_scope.

Comment on lines +1 to +3
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds asyncio_mode / asyncio_default_fixture_loop_scope, which are pytest-asyncio configuration options. The repo’s dependency lists (e.g., backend/requirements.txt) don’t appear to include pytest-asyncio, so pytest will likely emit “Unknown config option” warnings or fail to run async-marked tests depending on warning settings. Please add pytest-asyncio as a declared test/dev dependency (and consider pinning a minimum version that supports asyncio_default_fixture_loop_scope).

Copilot uses AI. Check for mistakes.