diff --git a/.github/workflows/deployaws.yml b/.github/workflows/deployaws.yml index 0d360fd..c1b722c 100644 --- a/.github/workflows/deployaws.yml +++ b/.github/workflows/deployaws.yml @@ -16,13 +16,13 @@ jobs: submodules: 'true' - uses: actions/setup-python@v3 with: - python-version: '3.9' + python-version: '3.12' - uses: aws-actions/setup-sam@v2 - uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ap-southeast-1 - - run: find ./ -name requirements.txt -type f -exec pip install -t dependencies/python -r "{}" \; + - run: pip install -t dependencies/python -e . - run: sam build - run: sam deploy --parameter-overrides 'Password=${{ secrets.WEB_PASSWORD }}' diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml new file mode 100644 index 0000000..2fa85b1 --- /dev/null +++ b/.github/workflows/run_tests.yml @@ -0,0 +1,49 @@ +name: Run Unit Tests + +on: + pull_request: + branches: [ dev, master ] + push: + branches: [ dev, master ] + paths-ignore: + - 'docs/**' + - '**.md' + +jobs: + test: + name: Run Python Tests + runs-on: ubuntu-latest + container: + image: ghcr.io/astral-sh/uv:python3.12-bookworm + options: --user root + env: + UV_INDEX_URL: https://pypi.org/simple + + steps: + - uses: actions/checkout@v4 + with: + submodules: 'true' + + - name: Install dependencies with uv sync + run: | + uv sync --python-preference only + uv pip install pytest moto + + - name: Initialize submodules + run: git submodule update --init --recursive + + - name: Run tests + run: pytest tests/ -v + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-1 + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results + path: | + test-results/ + .pytest_cache/ diff --git a/pyproject.toml b/pyproject.toml index af342a9..a17ad55 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "taskbox" version = "0.1.0" description = "A personal scheduled task framework running on Serverless platform" authors = [ - {name = "jneeee", email = "your-email@example.com"}, + {name = "jneeee", email = "jneeee@outlook.com"}, ] readme = "README.md" requires-python = ">=3.9" @@ -18,10 +18,11 @@ dependencies = [ "Jinja2>=3.1.2", "boto3>=1.26.8", "botocore>=1.29.8", + "pyaes>=1.6.1", ] [tool.uv] -dev-dependencies = [ +dependency-groups.dev = [ "pytest>=7.0.0", "black>=23.0.0", "isort>=5.0.0", @@ -64,4 +65,4 @@ skip_gitignore = true [tool.pytest.ini_options] pythonpath = ["src"] -testpaths = ["src/taskbox/tests"] +testpaths = ["tests"] diff --git a/src/taskbox/tests/test_manage.py b/tests/test_manage.py similarity index 79% rename from src/taskbox/tests/test_manage.py rename to tests/test_manage.py index 2f3f2ba..3703c06 100644 --- a/src/taskbox/tests/test_manage.py +++ b/tests/test_manage.py @@ -1,14 +1,17 @@ import os +import sys import unittest from unittest import mock -from taskbox.tests import fixture +sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) + +from taskbox.tests.fixture import create_table from taskbox.taskbase.manage import TaskManager class Test_manage(unittest.TestCase): def setUp(self) -> None: - self.table = fixture.create_table() + self.table = create_table() d = { 'DDB_TABLE': 'table_name', 'AWS_ACCESS_KEY_ID': "keyid", diff --git a/src/taskbox/tests/test_object.py b/tests/test_object.py similarity index 96% rename from src/taskbox/tests/test_object.py rename to tests/test_object.py index 349032e..c643afd 100644 --- a/src/taskbox/tests/test_object.py +++ b/tests/test_object.py @@ -1,6 +1,10 @@ +import os +import sys import unittest from unittest import mock +sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) + from taskbox.webx.object import Request diff --git a/src/taskbox/tests/test_web.py b/tests/test_web.py similarity index 93% rename from src/taskbox/tests/test_web.py rename to tests/test_web.py index e35ec66..85aae66 100644 --- a/src/taskbox/tests/test_web.py +++ b/tests/test_web.py @@ -4,9 +4,13 @@ from moto import mock_dynamodb +import sys +import os +sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) + from taskbox.index import lambda_handler from taskbox.utils.tools import LOG -from taskbox.tests import fixture +from taskbox.tests.fixture import create_table Fake_event = { @@ -30,7 +34,7 @@ class Test_web_tasks(unittest.TestCase): @classmethod def setUpClass(cls): - cls.table = fixture.create_table() + cls.table = create_table() @classmethod def tearDownClass(cls):