Skip to content

Integration test #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
39 changes: 27 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ executors:
python:
docker:
- image: cimg/python:3.12.2
python-machine:
machine:
docker_layer_caching: true
image: ubuntu-2204:edge
defaults:
docker_publish: &docker_publish
image: bsstudio/bss-web-file-api
Expand All @@ -34,30 +38,39 @@ jobs:
- run: poetry run black . --check
- run: poetry run pylint src
- run: poetry run mypy -p src
github_release:
docker:
- image: cimg/base:stable
steps:
- checkout
- github-cli/install:
version: 2.43.1
- github-cli/setup:
version: 2.43.1
- run: gh release create << pipeline.git.tag >> -t << pipeline.git.tag >> --generate-notes
coverage:
executor: python
steps:
- checkout
- python/install-packages:
pkg-manager: poetry
- run: |
poetry run pytest --cov=src \
poetry run pytest tests --cov=src \
--cov-fail-under=100 \
--cov-report=html \
--cov-report json
- codecov/upload
- store_artifacts:
path: htmlcov
integration:
executor: python-machine
steps:
- checkout
- python/install-packages:
pkg-manager: poetry
pre-install-steps:
- run: pip install poetry
- run: poetry run pytest tests-int
github_release:
docker:
- image: cimg/base:stable
steps:
- checkout
- github-cli/install:
version: 2.43.1
- github-cli/setup:
version: 2.43.1
- run: gh release create << pipeline.git.tag >> -t << pipeline.git.tag >> --generate-notes
workflows:
Build:
jobs:
Expand All @@ -68,8 +81,10 @@ workflows:
- python/test:
name: Unit tests
pkg-manager: poetry
test-tool: pytest
test-tool-args: tests
version: 3.12.2
- integration:
name: Integration tests
- docker/hadolint:
name: Lint Dockerfile
- docker/publish:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ RUN pip install --no-cache-dir ./wheels/*

COPY ./src ./src

CMD ["uvicorn", "src.bss_web_file_server.main:app", "--host", "0.0.0.0", "--port", "80"]
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "80"]
EXPOSE 80
LABEL org.opencontainers.image.source="https://github.com/BSStudio/bss-web-file-api"
LABEL org.opencontainers.image.description="BSS Web file API"
Expand Down
10 changes: 3 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ services:
ports:
- "80"
environment:
SERVER_BASE_PATH: /assets
SERVER_BASE_PATH: /home/nonroot/assets
healthcheck:
test: "wget --tries=1 --no-verbose -qO- http://localhost:80/health | grep -q UP"
start_period: 5s
test: python -c "import requests, sys; sys.exit(0 if 'UP' in requests.get('http://localhost/health').text else 1)"
start_period: 2s
interval: 10s
timeout: 5s
retries: 5
volumes:
- assets:/assets
volumes:
assets:
342 changes: 311 additions & 31 deletions poetry.lock

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@ readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.12"
fastapi = {version="0.110.0", extras=["all"]}
uvicorn = {version = "0.29.0", extras = ["standard"]}
pillow = "10.2.0"
pillow-avif-plugin = "1.4.3"
python = "^3.12"
# used for UploadFile
python-multipart = "0.0.9"
requests = "2.31.0"
uvicorn = {version = "0.29.0", extras = ["standard"]}

[tool.poetry.group.dev.dependencies]
black = "24.3.0"
pre-commit = "3.6.2"
pylint = "3.1.0"
isort = "5.13.2"
types-Pillow = "10.2.0.20240311"
mypy = "1.9.0"
pylint = "3.1.0"
pre-commit = "3.6.2"
types-Pillow = "10.2.0.20240311"

[tool.poetry.group.test.dependencies]
httpx = "^0.23.0"
pytest = "^8.0.0"
pytest-mock = "^3.10.0"
pytest-cov = "^4.1.0"
pytest = "8.0.0"
pytest-cov = "4.1.0"
pytest-mock = "3.10.0"
testcontainers = "4.1.1"

[tool.isort]
profile = "black"
Expand Down
Empty file added tests-int/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions tests-int/test_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os

import pytest
import requests
from testcontainers.compose import DockerCompose


@pytest.fixture(scope="session")
def compose():
print("Starting compose")
compose = DockerCompose(
context=os.getcwd(),
compose_file_name="docker-compose.yml",
build=True,
wait=True,
)
compose.start()
yield compose
compose.stop()


def test_health(compose: DockerCompose):
host = compose.get_service_host("app")
port = compose.get_service_port("app", 80)
assert "Application startup complete." in compose.get_logs("app")[0]
response = requests.get(f"http://{host}:{port}/health")
assert response.status_code == 200
assert response.text == "UP"


def test_ping(compose: DockerCompose):
host = compose.get_service_host("app")
port = compose.get_service_port("app", 80)
response = requests.get(f"http://{host}:{port}/ping")
assert response.status_code == 200
assert response.text == "PONG"