diff --git a/.github/workflows/error_handling_utils_tests.yml b/.github/workflows/error_handling_utils_tests.yml new file mode 100644 index 0000000..fe6297e --- /dev/null +++ b/.github/workflows/error_handling_utils_tests.yml @@ -0,0 +1,33 @@ +name: Error Handling Utils Tests + +on: + workflow_call: + inputs: + environment: + description: "Environment to run tests against" + type: string + required: false + default: "dev" + +jobs: + error_handling_utils_tests: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest pyyaml requests boto3 flask jinja2 lxml werkzeug six python-dotenv + + - name: Run error handling utils tests + env: + UNIT_TEST_ONLY: "true" + ENVIRONMENT: ${{ inputs.environment }} + run: pytest --env="$ENVIRONMENT" tests/test_error_handling_utils.py diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index bd7ef6e..764d51a 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -36,3 +36,31 @@ jobs: id: "Run during opened pull request" github_tag: ${{ github.event.pull_request.head.ref }} secrets: inherit + + error_handling_utils_changes: + if: >- + (github.event_name == 'pull_request' && github.event.pull_request.user.login != 'dependabot[bot]') || + (github.event_name == 'pull_request_target' && github.event.pull_request.user.login == 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository) + runs-on: ubuntu-latest + outputs: + should_run: ${{ steps.filter.outputs.error_handling_utils }} + steps: + - name: Detect relevant changes + id: filter + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 + with: + filters: | + error_handling_utils: + - 'tests/test_error_handling_utils.py' + - 'utils/data_helper.py' + - 'utils/dynamo_helper.py' + - 'utils/eligibility_api_client.py' + - 'tests/performance_tests/validate_inputs.py' + + error_handling_utils_tests: + if: >- + needs.error_handling_utils_changes.outputs.should_run == 'true' && + ((github.event_name == 'pull_request' && github.event.pull_request.user.login != 'dependabot[bot]') || + (github.event_name == 'pull_request_target' && github.event.pull_request.user.login == 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository)) + needs: error_handling_utils_changes + uses: ./.github/workflows/error_handling_utils_tests.yml diff --git a/tests/conftest.py b/tests/conftest.py index e9963f2..d0d9f7a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -83,6 +83,9 @@ def eligibility_client(): @pytest.fixture(scope="session", autouse=True) def upload_consumer_mapping_once(): + if os.getenv("UNIT_TEST_ONLY", "").lower() == "true": + logger.info("Skipping consumer mapping upload for unit-test-only run") + return upload_consumer_mapping_file_to_s3(test_config.CONSUMER_MAPPING_FILE) diff --git a/tests/performance_tests/validate_inputs.py b/tests/performance_tests/validate_inputs.py index 4cc6e29..e0b289b 100644 --- a/tests/performance_tests/validate_inputs.py +++ b/tests/performance_tests/validate_inputs.py @@ -46,8 +46,13 @@ def parse_run_time_to_seconds(run_time: str) -> int: def main() -> None: - users = int(get_env("USERS")) - spawn_rate = int(get_env("SPAWN_RATE")) + try: + users = int(get_env("USERS")) + spawn_rate = int(get_env("SPAWN_RATE")) + except ValueError: + fail("Invalid input", "USERS must be an integer.") + return + run_time = get_env("RUN_TIME") validate_range("users", users, 1, MAX_USERS)