diff --git a/.github/workflows/pyTest_runs.yml b/.github/workflows/ci_regression_script.yml similarity index 83% rename from .github/workflows/pyTest_runs.yml rename to .github/workflows/ci_regression_script.yml index 180129c..c81c3ec 100644 --- a/.github/workflows/pyTest_runs.yml +++ b/.github/workflows/ci_regression_script.yml @@ -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' diff --git a/routers/submit.py b/routers/submit.py index 91b8f7b..f6745ea 100644 --- a/routers/submit.py +++ b/routers/submit.py @@ -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: @@ -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( diff --git a/tests/test_submit.py b/tests/test_submit.py index b953e55..254a13a 100644 --- a/tests/test_submit.py +++ b/tests/test_submit.py @@ -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"] \ No newline at end of file + 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"]