Skip to content

Commit

Permalink
remove testcontainers, add makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub3628800 committed Feb 10, 2024
1 parent 26e2af2 commit 3f9ba0a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
all: lint test

lint:
pre-commit run --all-files

test:
docker compose up postgres -d
sleep 5 # wait for postgres to start
pytest
docker compose down

install:
pip-sync

upgrade:
pip-compile
pip-sync

run:
docker compose up postgres -d
python run_app.py
docker compose down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ things such as GitHub actions or python async libraries.

It works: https://async-url-shortener.herokuapp.com/shipit

## Running
1. Activate a virtual environment
2. Install pip-tools: `pip install pip-tools` (pip-tols is used to manage dependencies, you only need to install it once when bootstraping the virtualenv)
3. Install dependencies: `make install`

### Running the tests
`make test`

### Running the app
`make run`

### Upgrading dependencies
`make upgrade`

## Environments
The app is currently deployed in heroku.

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.4"
version: "3.8"
services:
postgres:
image: 'postgres:13'
Expand Down
3 changes: 0 additions & 3 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
- change to fastapi
- remove heroku deployment
- find new deployment
- move pre-commit workflow action into normal workflow action
- use alembic + sqlalchemy (or something else?) for migrations
- add sqlite support
- change pre-commit PR action to be custom and not use pre-commi ci
- experiment with testcontainers
- experiment with docker scout
32 changes: 14 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import pytest
from starlette.testclient import TestClient

from testcontainers.compose import DockerCompose
from shortener.factory import app
from shortener.settings import PostgresSettings


@pytest.mark.asyncio
@pytest.fixture(scope="function")
async def test_client():
async_pool = asyncpg.create_pool(min_size=5, max_size=25, **dict(PostgresSettings(_env_file=None)))
Expand All @@ -22,26 +20,24 @@ async def test_client():
return


@pytest.fixture(scope="session")
def docker_compose_test_containers():
compose = DockerCompose("", compose_file_name="docker-compose.yaml", pull=True)

with compose:
stdout, stderr = compose.get_logs()
print(stdout)
# @pytest.fixture(scope="session")
# def docker_compose_test_containers():
# compose = DockerCompose("", compose_file_name="docker-compose.yaml", pull=True)
# print("Starting docker compose")
# with compose:
# stdout, stderr = compose.get_logs()
# print(stdout)


@pytest.fixture(scope="session")
def psycopg2_cursor():
compose = DockerCompose(".", compose_file_name="docker-compose.yaml", pull=True)

with compose:
stdout, stderr = compose.get_logs()
print(stdout)

import time

time.sleep(20)
# compose = DockerCompose(".", compose_file_name="docker-compose.yaml", pull=True)
#
# with compose:
# stdout, stderr = compose.get_logs()
# print(stdout)
#
# import time

db_port = os.getenv("DB_PORT", 5432)
db_host = os.getenv("DB_HOST", "localhost")
Expand Down

0 comments on commit 3f9ba0a

Please sign in to comment.