diff --git a/.circleci/config.yml b/.circleci/config.yml index d88732ce..c3b08bf1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -83,7 +83,7 @@ jobs: . venv/bin/activate pip install -r requirements.txt - save_cache: - key: deps-3.11-{{ checksum "requirements.txt" }} + key: deps-3.11-{{ checksum "requirements.txt" }}-2 paths: - "venv" - run: @@ -110,13 +110,44 @@ jobs: . venv/bin/activate pip install -r requirements.txt - save_cache: - key: deps-3.12-{{ checksum "requirements.txt" }} + key: deps-3.12-{{ checksum "requirements.txt" }}-2 paths: - "venv" - run: command: './venv/bin/pytest -svv' + sanic-api-start: + docker: + - image: cimg/python:3.11 + steps: + - checkout + - restore_cache: + key: deps-3.11-{{ checksum "requirements.txt" }}-2 + - run: + name: Install dependencies + command: | + python -m venv venv + . venv/bin/activate + pip install -r requirements.txt + sudo mkdir -p /media/wrolpi + - run: + name: Start Sanic API + command: | + . venv/bin/activate + sanic main:api_app -H 0.0.0.0 -p 8081 + background: true + - run: + name: Test Sanic API + command: | + sleep 20 + curl http://0.0.0.0:8081/api/echo + - run: + name: Stop Sanic API + command: pkill -f sanic workflows: + wrolpi-sanic-tests: + jobs: + - sanic-api-start wrolpi-api-tests: jobs: - api-tests-3-11 diff --git a/main.py b/main.py index f80a7c4a..8880e8e2 100755 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ from wrolpi.contexts import attach_shared_contexts, reset_shared_contexts, initi from wrolpi.dates import Seconds from wrolpi.downloader import import_downloads_config, download_manager, \ perpetual_download_worker -from wrolpi.vars import PROJECT_DIR, DOCKERIZED +from wrolpi.vars import PROJECT_DIR, DOCKERIZED, CIRCLECI from wrolpi.version import get_version_string logger = logger.getChild('wrolpi-main') diff --git a/wrolpi/test/common.py b/wrolpi/test/common.py index 31452467..46d73b3a 100644 --- a/wrolpi/test/common.py +++ b/wrolpi/test/common.py @@ -1,4 +1,3 @@ -import os import pathlib import tempfile from contextlib import contextmanager @@ -12,12 +11,11 @@ import pytest from wrolpi.common import get_media_directory from wrolpi.conftest import test_db, test_client # noqa from wrolpi.db import postgres_engine +from wrolpi.vars import CIRCLECI TEST_CONFIG_PATH = tempfile.NamedTemporaryFile(mode='rt', delete=False) -skip_circleci = pytest.mark.skipif( - os.environ.get('CIRCLECI', '').strip().lower() == 'true', - reason='This test is not supported in Circle CI') +skip_circleci = pytest.mark.skipif(CIRCLECI, reason='This test is not supported in Circle CI') def wrap_test_db(func): diff --git a/wrolpi/vars.py b/wrolpi/vars.py index d9f20694..ec1ac9fb 100644 --- a/wrolpi/vars.py +++ b/wrolpi/vars.py @@ -16,6 +16,8 @@ load_dotenv(PROJECT_DIR / '.env') DOCKERIZED = True if os.environ.get('DOCKER', '').lower().startswith('t') else False # tests are running PYTEST = 'pytest' in sys.modules +# running on circlci +CIRCLECI = os.environ.get('CIRCLECI', '').strip().lower() == 'true' def truthy_arg(value: str) -> bool: