name: Run Pytest

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - deploy/dev

jobs:
  test:
    runs-on: ubuntu-latest

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

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

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

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

    - name: Run pytest
      run: pytest api/tests/unit_tests
