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
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ run-name: ${{ github.actor }}

on:
push:
# Only Operate on the main branch
branches:
- main
- issue-4/configuring-ci-cd-pytest
# Ignore changes to the README and the workflow file
paths-ignore:
- 'README.md'
# - '.github/workflows/pyTest_runs.yml'
pull_request:
branches:
- main
paths-ignore:
- 'README.md'


# This workflow will run pytest on the codebase and upload the results as an artifact
jobs:
pytest:
# This runs it at the lasest version of Ubuntu
# lasest version of Ubuntu
runs-on: ubuntu-latest
steps:
# This inputs a message to the console
- run: echo "Running Pytest"

# This checks out the code from the repository so that it can be tested 'actions/checkout@v3'
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

Expand Down
21 changes: 21 additions & 0 deletions routers/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ async def receive_exec_form(form_dto: ExecAppFormDTO):
teamType=team_type,
)

required_fields = [
form_dto.fullName,
form_dto.email,
student_id,
year_of_study,
form_dto.faculty,
form_dto.major,
is_coop,
team_type
]

processed_questions: Dict[str, str] = {}

if form_dto.questions:
Expand Down Expand Up @@ -73,6 +84,16 @@ async def receive_exec_form(form_dto: ExecAppFormDTO):
).model_dump(mode="json"),
)

if any(not field for field in required_fields):
for field in required_fields:
if field is None or (isinstance(field, str) and field.strip() == ""):
return JSONResponse(
status_code=400,
content=ResponseDTO(
message="Missing required fields"
).model_dump(mode="json"),
)

team_type_str = exec_form_request.teamType.value if isinstance(exec_form_request.teamType, TeamType) else str(exec_form_request.teamType)

print_formatter(
Expand Down
22 changes: 21 additions & 1 deletion tests/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,24 @@ def test_submit_exec_form_invalid_team():
assert response.status_code == 400
data = response.json()
assert "message" in data
assert "Invalid team type" in data["message"]
assert "Invalid team type" in data["message"]

def test_submit_exec_form_missing_fields():
# Test for when one component is missing
test_data = {
"fullName": "Charlie Brown",
"email": "charlie.brown@example.com",
"studentId": "330102020",
"yearOfStudy": "1",
"faculty": " ",
"major": "Finance",
"coopTerm": "no",
"firstChoiceTeam": "STRATEGY",
"questions": {}
}

response = client.post("/api/submit/exec-form", json=test_data)
assert response.status_code == 400
data = response.json()
assert "message" in data
assert "Missing required fields" in data["message"]
Loading