Skip to content
Closed
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
38 changes: 38 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Python application

on:
push:
branches: [ "main", "mac-port" ]
pull_request:
branches: [ "main", "mac-port" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-flask
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Test with pytest
env:
SECRET_KEY: "test-secret-key"
run: |
pytest
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
pythonpath = API
testpaths = tests
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys
import os
from pathlib import Path

# Add the API folder to sys.path so that 'import app'
# and 'from Classes.Base import Config' work exactly as they do in production
api_path = Path(__file__).parent.parent / "API"
sys.path.insert(0, str(api_path.resolve()))
27 changes: 27 additions & 0 deletions tests/test_api_basics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest
from API.app import app
from API.Classes.Base import Config

@pytest.fixture
def client():
# Make sure we don't try to sync to AWS during tests
Config.AWS_SYNC = 0
app.config['TESTING'] = True
app.config['SECRET_KEY'] = 'test-secret-key'

with app.test_client() as client:
yield client

def test_home_page(client):
"""Test that the application starts and serves the frontend."""
# We check /getSession as a basic API liveness probe
rv = client.get('/getSession')
# Because we haven't set a session, it returns a 200 with session: null
assert rv.status_code == 200
assert b'session' in rv.data

def test_cors_headers(client):
"""Test that CORS headers are appended to requests."""
rv = client.get('/getSession')
assert 'Access-Control-Allow-Origin' in rv.headers
assert 'Access-Control-Allow-Credentials' in rv.headers