Skip to content

Commit c385cf4

Browse files
authored
feature: add docker compose to run test (#21)
* feature: add docker compose - to run tests: docker compose up * feature: add dynamic env POSTGRES_HOST - add dynamic env POSTGRES_HOST so we can test outside and inside docker - docker will use postgres, and default to localhost if testing on host machine * feature: add readme for docker compose * feature: move docker compose to tests directory * feature: lint code
1 parent 5c4f855 commit c385cf4

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ class SomeSqlAlchemyFilterModel(SqlAlchemyFilterBaseModel):
204204
super().__init__(field__in=field__in, **kwargs)
205205
```
206206

207+
____
208+
### Docker Compose
209+
To run tests on your local machine
210+
```bash
211+
cd tests
212+
docker compose up
213+
```
207214
____
208215
### Links
209216
[Github](https://github.com/ViAchKoN/dataclass-sqlalchemy-mixins)

tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
from tests.models import BaseModel
1010

1111

12-
TEST_DB_URL = (
13-
"postgresql://{POSTGRES_CREDENTIALS}localhost/pydantic_sqlalchemy_filters_test"
14-
)
15-
12+
TEST_DB_URL = "postgresql://{POSTGRES_CREDENTIALS}{POSTGRES_HOST}/pydantic_sqlalchemy_filters_test"
1613

1714
POSTGRES_CREDENTIALS = ""
1815
POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD", None)
16+
POSTGRES_HOST = os.getenv("POSTGRES_HOST", "localhost")
1917
if POSTGRES_PASSWORD:
2018
POSTGRES_USER = os.getenv("POSTGRES_USER", "postgres")
2119
POSTGRES_CREDENTIALS = f"{POSTGRES_USER}:{POSTGRES_PASSWORD}@"
2220

2321

24-
TEST_DB_URL = TEST_DB_URL.format(POSTGRES_CREDENTIALS=POSTGRES_CREDENTIALS)
22+
TEST_DB_URL = TEST_DB_URL.format(
23+
POSTGRES_CREDENTIALS=POSTGRES_CREDENTIALS, POSTGRES_HOST=POSTGRES_HOST
24+
)
2525

2626

2727
@pytest.fixture(scope="package")

tests/docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '3'
2+
services:
3+
python:
4+
environment:
5+
POSTGRES_PASSWORD: postgres
6+
POSTGRES_HOST: postgres
7+
image: python:3.8.1
8+
stdin_open: true
9+
tty: true
10+
volumes:
11+
- ../:/app
12+
depends_on:
13+
- postgres
14+
command: >
15+
bash -c "
16+
cd /app &&
17+
pip install poetry &&
18+
poetry install &&
19+
poetry run pytest"
20+
21+
postgres:
22+
image: postgres:latest
23+
environment:
24+
POSTGRES_PASSWORD: postgres
25+
ports:
26+
- "5432:5432"

0 commit comments

Comments
 (0)