Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
091b94f
Refactor auth module
Sep 14, 2025
4dd378a
Refactor Account module
Sep 14, 2025
cd6d704
Refactor serializer
Sep 14, 2025
6824c99
Seperate serializer
Sep 14, 2025
c3dab66
Refactor problem
Sep 14, 2025
689c20d
Refactor collection
Sep 14, 2025
e58325b
Refactor group and topic
Sep 14, 2025
a4509f5
Refactor submission
Sep 14, 2025
72de12e
Remove unused view and controller
Sep 14, 2025
f9b90f9
Remove print
Sep 14, 2025
4171cba
Refactor object oriented services
KanonKC Sep 22, 2025
87e606f
Call service from setup
KanonKC Sep 24, 2025
fab7a4d
Remove Django model on controllers and model object on services
KanonKC Sep 24, 2025
eb332b4
Return error on wrapper
KanonKC Sep 24, 2025
7034bd2
Use mysql database
KanonKC Sep 24, 2025
6dee059
Add django type for Cursor auto-complete detection
KanonKC Sep 15, 2025
941aa0b
Refactor CSR pattern on Account
Sep 14, 2025
9ef8b71
Controller use non-object appeoach
KanonKC Sep 15, 2025
746d17f
Implement account, collection, repo
Sep 22, 2025
0d35b28
Add more repo
KanonKC Sep 22, 2025
356ed21
Correct list type
KanonKC Sep 24, 2025
c1fa73e
Start implement collection service
KanonKC Sep 24, 2025
c4a43b4
Refactor collection service
Sep 25, 2025
24bd8ed
Add repository refactoring process documentation
Sep 25, 2025
93b3d74
Refactor topic problem and submission
Sep 25, 2025
8a39b82
Refactor by rules
Sep 25, 2025
a05ce4e
Add unit test for account auth and problem
Sep 25, 2025
81503d1
Complete auth unit test
KanonKC Sep 25, 2025
87de915
Complete test for account
KanonKC Sep 25, 2025
e26937e
Create unit test docs
KanonKC Sep 25, 2025
be2d2af
Unit tests
KanonKC Sep 26, 2025
46dd142
Complete collection test
Sep 28, 2025
cdaf820
Complete problem test
Sep 28, 2025
68632d8
Fix some submission casee
Sep 28, 2025
937efa4
Complete submission test
KanonKC Sep 28, 2025
9d58647
Complete all service test
KanonKC Sep 28, 2025
425ee6c
Create workflow for unit test
KanonKC Sep 28, 2025
3451dc5
Add psudo env variable
KanonKC Sep 28, 2025
ba732de
Remove CI
KanonKC Sep 28, 2025
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
Binary file added .coverage
Binary file not shown.
30 changes: 30 additions & 0 deletions .cursor/rules/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ModelGrader Backend Project Rules

## Virtual Environment
- ALWAYS activate the virtual environment before running any Python scripts
- Use `source env/bin/activate` to activate the environment
- All Python commands should be run with the activated environment

## Python Scripts
- When running Django management commands, ensure the environment is activated first
- For testing: `source env/bin/activate && python manage.py test [test_path]`
- For running the server: `source env/bin/activate && python manage.py runserver`
- For migrations: `source env/bin/activate && python manage.py migrate`

## Test Execution
- Always activate environment before running tests
- Use the project's test runner: `source env/bin/activate && python run_all_tests.py`
- Individual test files: `source env/bin/activate && python manage.py test [test_path]`

## Project Structure
- This is a Django REST Framework project
- Main application is in the `api/` directory
- Services are in `api/services/`
- Tests are in `api/services/*/test_*.py`
- Configuration files: `manage.py`, `requirements.txt`, `Dockerfile`

## Dependencies
- Django REST Framework
- PostgreSQL (production)
- SQLite (development/testing)
- Various Python packages listed in `requirements.txt`
30 changes: 30 additions & 0 deletions .cursor/rules/active-python-env.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
description: Active Python Environment for ModelGrader Backend
globs:
alwaysApply: true
---

# Virtual Environment Activation Rules

## Always Activate Virtual Environment
- ALWAYS activate the virtual environment before running any Python scripts
- Use `source env/bin/activate` to activate the environment
- All Python commands should be run with the activated environment

## Django Management Commands
- When running Django management commands, ensure the environment is activated first
- For testing: `source env/bin/activate && python manage.py test [test_path]`
- For running the server: `source env/bin/activate && python manage.py runserver`
- For migrations: `source env/bin/activate && python manage.py migrate`

## Test Execution
- Always activate environment before running tests
- Use the project's test runner: `source env/bin/activate && python run_all_tests.py`
- Individual test files: `source env/bin/activate && python manage.py test [test_path]`

## Project Context
- This is a Django REST Framework project
- Main application is in the `api/` directory
- Services are in `api/services/`
- Tests are in `api/services/*/test_*.py`
- Configuration files: `manage.py`, `requirements.txt`, `Dockerfile`
78 changes: 78 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Run Tests on PR

on:
pull_request:
branches: [ "*" ]
push:
branches: [ main, dev ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Set up environment variables
run: |
echo "PORT=8000" >> $GITHUB_ENV
echo "FRONTEND_URL=http://localhost:3000" >> $GITHUB_ENV
echo "TOKEN_LIFETIME_SECOND=3600" >> $GITHUB_ENV
echo "DATABASE_NAME=test_db.sqlite3" >> $GITHUB_ENV
echo "DATABASE_USER=test_user" >> $GITHUB_ENV
echo "DATABASE_PASSWORD=test_password" >> $GITHUB_ENV
echo "DATABASE_HOST=localhost" >> $GITHUB_ENV
echo "DATABASE_PORT=5432" >> $GITHUB_ENV
echo "SECRET_KEY=test-secret-key-for-github-actions" >> $GITHUB_ENV
echo "DEBUG=True" >> $GITHUB_ENV

- name: Run all tests
run: |
python run_all_tests.py --verbose

- name: Run tests with coverage
run: |
pip install coverage
python run_all_tests.py --coverage --verbose

- name: Test individual services
run: |
echo "Testing Account Service..."
python run_all_tests.py --services account --verbose

echo "Testing Problem Service..."
python run_all_tests.py --services problem --verbose

echo "Testing Auth Service..."
python run_all_tests.py --services auth --verbose

echo "Testing Collection Service..."
python run_all_tests.py --services collection --verbose

echo "Testing Group Service..."
python run_all_tests.py --services group --verbose

echo "Testing Submission Service..."
python run_all_tests.py --services submission --verbose

echo "Testing Topic Service..."
python run_all_tests.py --services topic --verbose
42 changes: 42 additions & 0 deletions .github/workflows/simple-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Simple Test Runner

on:
pull_request:
branches: [ "*" ]
push:
branches: [ main, dev ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Set up environment variables
run: |
echo "PORT=8000" >> $GITHUB_ENV
echo "FRONTEND_URL=http://localhost:3000" >> $GITHUB_ENV
echo "TOKEN_LIFETIME_SECOND=3600" >> $GITHUB_ENV
echo "DATABASE_NAME=test_db.sqlite3" >> $GITHUB_ENV
echo "DATABASE_USER=test_user" >> $GITHUB_ENV
echo "DATABASE_PASSWORD=test_password" >> $GITHUB_ENV
echo "DATABASE_HOST=localhost" >> $GITHUB_ENV
echo "DATABASE_PORT=5432" >> $GITHUB_ENV
echo "SECRET_KEY=test-secret-key-for-github-actions" >> $GITHUB_ENV
echo "DEBUG=True" >> $GITHUB_ENV

- name: Run tests
run: |
python run_all_tests.py --verbose
66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Run Tests

on:
pull_request:
branches: [ "*" ]
push:
branches: [ main, dev ]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.11]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Set up environment variables
run: |
echo "PORT=8000" >> $GITHUB_ENV
echo "FRONTEND_URL=http://localhost:3000" >> $GITHUB_ENV
echo "TOKEN_LIFETIME_SECOND=3600" >> $GITHUB_ENV
echo "DATABASE_NAME=test_db.sqlite3" >> $GITHUB_ENV
echo "DATABASE_USER=test_user" >> $GITHUB_ENV
echo "DATABASE_PASSWORD=test_password" >> $GITHUB_ENV
echo "DATABASE_HOST=localhost" >> $GITHUB_ENV
echo "DATABASE_PORT=5432" >> $GITHUB_ENV
echo "SECRET_KEY=test-secret-key-for-github-actions" >> $GITHUB_ENV
echo "DEBUG=True" >> $GITHUB_ENV

- name: Run tests
run: |
python run_all_tests.py --verbose

- name: Run tests with coverage
run: |
pip install coverage
python run_all_tests.py --coverage --verbose

- name: Upload coverage reports
uses: codecov/codecov-action@v3
if: matrix.python-version == '3.11'
with:
file: ./coverage.xml
fail_ci_if_error: false
26 changes: 13 additions & 13 deletions Backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,24 @@
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': config('DATABASE_NAME'),
'USER': config('DATABASE_USER'),
'PASSWORD': config('DATABASE_PASSWORD'),
'HOST': config('DATABASE_HOST'),
'PORT': config('DATABASE_PORT'),
}
}

# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'ModelGrader.sqlite3',
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': config('DATABASE_NAME'),
# 'USER': config('DATABASE_USER'),
# 'PASSWORD': config('DATABASE_PASSWORD'),
# 'HOST': config('DATABASE_HOST'),
# 'PORT': config('DATABASE_PORT'),
# }
# }

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'ModelGrader.sqlite3',
}
}

# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

Expand Down
Loading