Skip to content

Commit e9801c0

Browse files
committed
linting
1 parent 942c9aa commit e9801c0

File tree

5 files changed

+73
-71
lines changed

5 files changed

+73
-71
lines changed

backend/migrations/versions/ded0314bce37_create_tasks_table.py

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@
55
Create Date: 2025-09-29 19:52:52.161683
66
77
"""
8+
89
from typing import Sequence, Union
910

1011
import sqlalchemy as sa
1112
from alembic import op
1213
from sqlalchemy.dialects import postgresql
1314

1415
# revision identifiers, used by Alembic.
15-
revision: str = 'ded0314bce37'
16-
down_revision: Union[str, None] = 'seed_intake_forms'
16+
revision: str = "ded0314bce37"
17+
down_revision: Union[str, None] = "seed_intake_forms"
1718
branch_labels: Union[str, Sequence[str], None] = None
1819
depends_on: Union[str, Sequence[str], None] = None
1920

2021

2122
def upgrade() -> None:
2223
# Create task_type enum
23-
op.execute("CREATE TYPE task_type AS ENUM ('intake_form_review', 'volunteer_app_review', 'profile_update', 'matching')")
24+
op.execute(
25+
"CREATE TYPE task_type AS ENUM ('intake_form_review', 'volunteer_app_review', 'profile_update', 'matching')"
26+
)
2427

2528
# Create task_priority enum
2629
op.execute("CREATE TYPE task_priority AS ENUM ('low', 'medium', 'high', 'no_status')")
@@ -30,41 +33,57 @@ def upgrade() -> None:
3033

3134
# Create tasks table
3235
op.create_table(
33-
'tasks',
34-
sa.Column('id', sa.UUID(), nullable=False),
35-
sa.Column('participant_id', sa.UUID(), nullable=False),
36-
sa.Column('type', postgresql.ENUM('intake_form_review', 'volunteer_app_review', 'profile_update', 'matching', name='task_type'), nullable=False),
37-
sa.Column('priority', postgresql.ENUM('low', 'medium', 'high', 'no_status', name='task_priority'), nullable=False, server_default='no_status'),
38-
sa.Column('assignee_id', sa.UUID(), nullable=True),
39-
sa.Column('start_date', sa.DateTime(timezone=True), nullable=False, server_default=sa.text('now()')),
40-
sa.Column('end_date', sa.DateTime(timezone=True), nullable=True),
41-
sa.Column('status', postgresql.ENUM('pending', 'in_progress', 'completed', name='task_status'), nullable=False, server_default='pending'),
42-
sa.Column('task_metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
43-
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.text('now()')),
44-
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.text('now()')),
45-
sa.ForeignKeyConstraint(['assignee_id'], ['users.id'], ondelete='SET NULL'),
46-
sa.ForeignKeyConstraint(['participant_id'], ['users.id'], ondelete='CASCADE'),
47-
sa.PrimaryKeyConstraint('id')
36+
"tasks",
37+
sa.Column("id", sa.UUID(), nullable=False),
38+
sa.Column("participant_id", sa.UUID(), nullable=False),
39+
sa.Column(
40+
"type",
41+
postgresql.ENUM(
42+
"intake_form_review", "volunteer_app_review", "profile_update", "matching", name="task_type"
43+
),
44+
nullable=False,
45+
),
46+
sa.Column(
47+
"priority",
48+
postgresql.ENUM("low", "medium", "high", "no_status", name="task_priority"),
49+
nullable=False,
50+
server_default="no_status",
51+
),
52+
sa.Column("assignee_id", sa.UUID(), nullable=True),
53+
sa.Column("start_date", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
54+
sa.Column("end_date", sa.DateTime(timezone=True), nullable=True),
55+
sa.Column(
56+
"status",
57+
postgresql.ENUM("pending", "in_progress", "completed", name="task_status"),
58+
nullable=False,
59+
server_default="pending",
60+
),
61+
sa.Column("task_metadata", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
62+
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
63+
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
64+
sa.ForeignKeyConstraint(["assignee_id"], ["users.id"], ondelete="SET NULL"),
65+
sa.ForeignKeyConstraint(["participant_id"], ["users.id"], ondelete="CASCADE"),
66+
sa.PrimaryKeyConstraint("id"),
4867
)
4968

5069
# Create indexes for common queries
51-
op.create_index('ix_tasks_participant_id', 'tasks', ['participant_id'])
52-
op.create_index('ix_tasks_assignee_id', 'tasks', ['assignee_id'])
53-
op.create_index('ix_tasks_type', 'tasks', ['type'])
54-
op.create_index('ix_tasks_status', 'tasks', ['status'])
55-
op.create_index('ix_tasks_priority', 'tasks', ['priority'])
70+
op.create_index("ix_tasks_participant_id", "tasks", ["participant_id"])
71+
op.create_index("ix_tasks_assignee_id", "tasks", ["assignee_id"])
72+
op.create_index("ix_tasks_type", "tasks", ["type"])
73+
op.create_index("ix_tasks_status", "tasks", ["status"])
74+
op.create_index("ix_tasks_priority", "tasks", ["priority"])
5675

5776

5877
def downgrade() -> None:
5978
# Drop indexes
60-
op.drop_index('ix_tasks_priority', table_name='tasks')
61-
op.drop_index('ix_tasks_status', table_name='tasks')
62-
op.drop_index('ix_tasks_type', table_name='tasks')
63-
op.drop_index('ix_tasks_assignee_id', table_name='tasks')
64-
op.drop_index('ix_tasks_participant_id', table_name='tasks')
79+
op.drop_index("ix_tasks_priority", table_name="tasks")
80+
op.drop_index("ix_tasks_status", table_name="tasks")
81+
op.drop_index("ix_tasks_type", table_name="tasks")
82+
op.drop_index("ix_tasks_assignee_id", table_name="tasks")
83+
op.drop_index("ix_tasks_participant_id", table_name="tasks")
6584

6685
# Drop tasks table
67-
op.drop_table('tasks')
86+
op.drop_table("tasks")
6887

6988
# Drop enums
7089
op.execute("DROP TYPE task_status")

backend/migrations/versions/seed_intake_forms.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@
55
Create Date: 2025-06-29 15:30:00.000000
66
77
"""
8+
89
import uuid
910
from typing import Sequence, Union
1011

1112
import sqlalchemy as sa
1213
from alembic import op
1314

1415
# revision identifiers, used by Alembic.
15-
revision: str = 'seed_intake_forms'
16-
down_revision: Union[str, None] = 'f11846c50673'
16+
revision: str = "seed_intake_forms"
17+
down_revision: Union[str, None] = "f11846c50673"
1718
branch_labels: Union[str, Sequence[str], None] = None
1819
depends_on: Union[str, Sequence[str], None] = None
1920

2021
# Generate static UUIDs for forms to ensure consistency
2122
PARTICIPANT_FORM_ID = uuid.uuid4()
2223
VOLUNTEER_FORM_ID = uuid.uuid4()
2324

25+
2426
def upgrade() -> None:
2527
op.bulk_insert(
2628
sa.table(
@@ -31,20 +33,11 @@ def upgrade() -> None:
3133
sa.Column("type", sa.String(), nullable=False),
3234
),
3335
[
34-
{
35-
"id": PARTICIPANT_FORM_ID,
36-
"name": "Participant Intake Form",
37-
"version": 1,
38-
"type": "intake"
39-
},
40-
{
41-
"id": VOLUNTEER_FORM_ID,
42-
"name": "Volunteer Intake Form",
43-
"version": 1,
44-
"type": "intake"
45-
}
36+
{"id": PARTICIPANT_FORM_ID, "name": "Participant Intake Form", "version": 1, "type": "intake"},
37+
{"id": VOLUNTEER_FORM_ID, "name": "Volunteer Intake Form", "version": 1, "type": "intake"},
4638
],
4739
)
4840

41+
4942
def downgrade() -> None:
5043
op.execute(f"DELETE FROM forms WHERE id IN ('{PARTICIPANT_FORM_ID}', '{VOLUNTEER_FORM_ID}')")

backend/tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# Use in-memory SQLite for tests
1313
SQLALCHEMY_DATABASE_URL = "sqlite://"
1414

15+
1516
@pytest.fixture(scope="session")
1617
def test_engine():
1718
"""Create a test database engine"""
@@ -23,6 +24,7 @@ def test_engine():
2324
Base.metadata.create_all(bind=engine)
2425
return engine
2526

27+
2628
@pytest.fixture(scope="function")
2729
def db_session(test_engine):
2830
"""Create a fresh database session for each test"""
@@ -34,9 +36,11 @@ def db_session(test_engine):
3436
db.rollback()
3537
db.close()
3638

39+
3740
@pytest.fixture(scope="function")
3841
def client(db_session):
3942
"""Create a test client with a test database"""
43+
4044
def override_get_db():
4145
try:
4246
yield db_session
@@ -48,12 +52,14 @@ def override_get_db():
4852
yield test_client
4953
app.dependency_overrides.clear()
5054

55+
5156
@pytest.fixture(scope="function")
5257
def auth_headers():
5358
"""Mock authentication headers for testing"""
5459
# This is a mock token - in real tests you might want to use a real Firebase token
5560
return {"Authorization": "Bearer test-token"}
5661

62+
5763
@pytest.fixture(scope="function")
5864
def mock_auth_middleware(monkeypatch):
5965
"""Mock the auth middleware to bypass Firebase authentication"""

backend/tests/fixtures/models.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,21 @@ def create_test_user(db, role_name="participant"):
2121
2222
role_id=role.id,
2323
auth_id="test-user-id",
24-
approved=True
24+
approved=True,
2525
)
2626
db.add(user)
2727
db.flush()
2828
return user
2929

30+
3031
def create_test_form(db):
3132
"""Create a test intake form"""
32-
form = Form(
33-
id=uuid.uuid4(),
34-
name="Test Intake Form",
35-
version=1,
36-
type="intake"
37-
)
33+
form = Form(id=uuid.uuid4(), name="Test Intake Form", version=1, type="intake")
3834
db.add(form)
3935
db.flush()
4036
return form
4137

38+
4239
def create_test_submission(db, user=None, form=None):
4340
"""Create a test form submission"""
4441
if not user:
@@ -51,10 +48,7 @@ def create_test_submission(db, user=None, form=None):
5148
form_id=form.id,
5249
user_id=user.id,
5350
submitted_at=datetime.utcnow(),
54-
answers={
55-
"test_field": "test value",
56-
"another_field": 123
57-
}
51+
answers={"test_field": "test value", "another_field": 123},
5852
)
5953
db.add(submission)
6054
db.flush()

backend/tests/unit/routes/test_intake.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,15 @@ def test_list_forms(client, db_session, mock_auth_middleware):
2020
assert forms[0]["name"] == form.name
2121
assert forms[0]["type"] == "intake"
2222

23+
2324
def test_create_submission(client, db_session, mock_auth_middleware):
2425
"""Test POST /intake/submissions endpoint"""
2526
# Create test user and form
2627
form = create_test_form(db_session)
2728
db_session.commit()
2829

2930
# Prepare submission data
30-
submission_data = {
31-
"form_id": str(form.id),
32-
"answers": {
33-
"test_question": "test answer",
34-
"numeric_question": 42
35-
}
36-
}
31+
submission_data = {"form_id": str(form.id), "answers": {"test_question": "test answer", "numeric_question": 42}}
3732

3833
# Make request
3934
response = client.post("/intake/submissions", json=submission_data)
@@ -44,6 +39,7 @@ def test_create_submission(client, db_session, mock_auth_middleware):
4439
assert data["form_id"] == str(form.id)
4540
assert data["answers"] == submission_data["answers"]
4641

42+
4743
def test_get_own_submissions(client, db_session, mock_auth_middleware):
4844
"""Test GET /intake/submissions endpoint - user can see their own submissions"""
4945
# Create test data
@@ -61,6 +57,7 @@ def test_get_own_submissions(client, db_session, mock_auth_middleware):
6157
assert len(data["submissions"]) == 1
6258
assert data["submissions"][0]["id"] == str(submission.id)
6359

60+
6461
def test_update_submission(client, db_session, mock_auth_middleware):
6562
"""Test PUT /intake/submissions/{submission_id} endpoint"""
6663
# Create test data
@@ -69,24 +66,17 @@ def test_update_submission(client, db_session, mock_auth_middleware):
6966
db_session.commit()
7067

7168
# Prepare update data
72-
update_data = {
73-
"answers": {
74-
"updated_field": "updated value",
75-
"another_field": 456
76-
}
77-
}
69+
update_data = {"answers": {"updated_field": "updated value", "another_field": 456}}
7870

7971
# Make request
80-
response = client.put(
81-
f"/intake/submissions/{submission.id}",
82-
json=update_data
83-
)
72+
response = client.put(f"/intake/submissions/{submission.id}", json=update_data)
8473

8574
# Check response
8675
assert response.status_code == status.HTTP_200_OK
8776
data = response.json()
8877
assert data["answers"] == update_data["answers"]
8978

79+
9080
def test_delete_submission(client, db_session, mock_auth_middleware):
9181
"""Test DELETE /intake/submissions/{submission_id} endpoint"""
9282
# Create test data

0 commit comments

Comments
 (0)