diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..141c75a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,69 @@ +name: Continuous Integration + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: [3.13] + + steps: + # Checkout the code + - name: Checkout code + uses: actions/checkout@v3 + + # Set up Python + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + # Install dependencies + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r server/src/requirements.txt + + # Set AWS region and mock credentials + - name: Configure AWS Credentials for Tests + run: | + echo "Setting AWS region and mock credentials..." + export AWS_REGION=us-east-1 + export AWS_ACCESS_KEY_ID=fake_access_key + export AWS_SECRET_ACCESS_KEY=fake_secret_key + export AWS_DEFAULT_REGION=us-east-1 + + # Run tests and generate coverage report + - name: Run tests with coverage + run: | + export PYTHONPATH=$(pwd)/server/src + pytest --cov=src/functions --cov=server/src --cov-report=term-missing --cov-report=xml --cov-report=html + + # Upload coverage report as an artifact + - name: Upload coverage report (HTML) + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-report-html + path: htmlcov/ + + # Upload XML coverage report for CI tools + - name: Upload coverage report (XML) + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-report-xml + path: coverage.xml + + # Show coverage summary in logs + - name: Show coverage summary + run: cat coverage.xml diff --git a/server/src/functions/permanent_data/permanent_data.py b/server/src/functions/permanent_data/permanent_data.py index b204f77..b0f2190 100644 --- a/server/src/functions/permanent_data/permanent_data.py +++ b/server/src/functions/permanent_data/permanent_data.py @@ -12,6 +12,7 @@ from concurrent.futures import ThreadPoolExecutor session = requests.Session() # Setup DynamoDB client for Lambda +os.environ.setdefault('AWS_DEFAULT_REGION', 'us-east-1') dynamodb = boto3.resource("dynamodb") table_name = os.environ.get("DYNAMODB_TABLE", "permanent_data") table = dynamodb.Table(table_name) @@ -208,4 +209,4 @@ if __name__ == "__main__": for future in futures: data.extend(future.result()) - print(json.dumps(data)) \ No newline at end of file + print(json.dumps(data)) diff --git a/server/src/functions/return_all_data/lambda_function.py b/server/src/functions/return_all_data/lambda_function.py index 614babb..198198b 100644 --- a/server/src/functions/return_all_data/lambda_function.py +++ b/server/src/functions/return_all_data/lambda_function.py @@ -3,6 +3,7 @@ import os import boto3 from boto3.dynamodb.conditions import Key, Attr +os.environ.setdefault('AWS_DEFAULT_REGION', 'us-east-1') dynamodb = boto3.resource('dynamodb') def lambda_handler(event, context): diff --git a/server/src/functions/return_newest_data/lambda_function.py b/server/src/functions/return_newest_data/lambda_function.py index 2cc0e88..82d1c7f 100644 --- a/server/src/functions/return_newest_data/lambda_function.py +++ b/server/src/functions/return_newest_data/lambda_function.py @@ -3,6 +3,7 @@ import json import os from boto3.dynamodb.conditions import Key, Attr +os.environ.setdefault('AWS_DEFAULT_REGION', 'us-east-1') dynamodb = boto3.resource('dynamodb') gsi_name = "objectType-index" diff --git a/server/src/functions/transient_data/transient_data.py b/server/src/functions/transient_data/transient_data.py index 932a853..ef7c4ec 100644 --- a/server/src/functions/transient_data/transient_data.py +++ b/server/src/functions/transient_data/transient_data.py @@ -11,6 +11,7 @@ from concurrent.futures import ThreadPoolExecutor session = requests.Session() # Setup DynamoDB client +os.environ.setdefault('AWS_DEFAULT_REGION', 'us-east-1') dynamodb = boto3.resource("dynamodb") table_name = os.environ.get("DYNAMODB_TABLE", "transient_data") table = dynamodb.Table(table_name) @@ -224,4 +225,4 @@ if __name__ == "__main__": for future in futures: data.extend(future.result()) - print(json.dumps(data)) \ No newline at end of file + print(json.dumps(data)) diff --git a/server/src/requirements.txt b/server/src/requirements.txt index db435d0..d69abb0 100644 --- a/server/src/requirements.txt +++ b/server/src/requirements.txt @@ -1,3 +1,5 @@ -boto3==1.36.23 -Requests==2.32.3 -xmltodict==0.14.2 +boto3 +Requests +xmltodict +pytest +pytest-cov diff --git a/server/src/test/conftest.py b/server/src/test/conftest.py new file mode 100644 index 0000000..de520f6 --- /dev/null +++ b/server/src/test/conftest.py @@ -0,0 +1,5 @@ +import sys +import os + +# Ensure the /server path is in PYTHONPATH +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))