Skip to content

Commit

Permalink
Add test action
Browse files Browse the repository at this point in the history
  • Loading branch information
nikmolnar committed Oct 29, 2023
1 parent 7569b65 commit e57bd21
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Python tests

on:
push:
branches: [ main ]
pull_request:

jobs:
build:

runs-on: ubuntu-latest
env:
DATABASE_CONFIG_JSON: pg_database/tests/test_config.json
DJANGO_SETTINGS_MODULE: pg_database.tests.settings
services:
postgis:
image: postgis/postgis:15-3.3
env:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ''
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- '5432:5432'
volumes:
- '/var/run/postgresql:/var/run/postgresql'

strategy:
matrix:
python-version: [3.9, '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
- name: Install System Dependencies
run: |
sudo apt-get update && sudo apt-get install -y build-essential git curl
pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Python Dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install
- name: Set up database
run: |
psql -c 'CREATE ROLE django SUPERUSER LOGIN CREATEDB;' -U postgres
psql -c 'CREATE ROLE travis SUPERUSER LOGIN CREATEDB;' -U postgres
psql -c 'CREATE DATABASE test_pg_database;' -U postgres
psql -c 'CREATE EXTENSION postgis;' -U postgres -d test_pg_database
psql -c 'CREATE EXTENSION postgis_topology;' -U postgres -d test_pg_database
- name: Run Tests
run: |
poetry run pytest
1 change: 1 addition & 0 deletions pg_database/tests/test_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"database-name": "test_pg_database",
"database-user": "postgres",
"django-db-key": "other",
"connect-args": {"sslmode": "prefer"},
"pooling-args": {
Expand Down
6 changes: 3 additions & 3 deletions pg_database/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def db_drop(postgres_engine):
def db_engine():
""" Create a database engine for use in implementing tests """

postgres_engine = create_engine("postgresql:///postgres", isolation_level="AUTOCOMMIT")
postgres_engine = create_engine(URL(drivername="postgresql", username="postgres"), isolation_level="AUTOCOMMIT")

db_create(postgres_engine)
engine = create_engine(URL(**DATABASE_INFO))
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def test_get_engine(db_metadata):
# Test with all params provided

test_metadata = MetaData(schema.get_engine(
connect_args={"sslmode": "require"},
connect_args={"sslmode": "prefer"},
pooling_args={"pool_size": 20, "max_overflow": 0},
))
test_metadata.reflect()
Expand Down Expand Up @@ -1088,7 +1088,7 @@ def test_get_metadata(db_metadata):
# Test with all params provided

test_metadata = schema.get_metadata(
connect_args={"sslmode": "require"},
connect_args={"sslmode": "prefer"},
pooling_args={"pool_size": 20, "max_overflow": 0},
)
assert sorted(test_metadata.tables) == sorted(db_metadata.tables)
Expand Down
9 changes: 0 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,3 @@ deps =
[testenv:nodjango]
deps =
{[base]deps}

[testenv:coverage]
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
commands =
py.test pg_database/tests/tests.py --cov=pg_database --cov-branch
coveralls
deps =
coveralls
{[testenv:django]deps}

0 comments on commit e57bd21

Please sign in to comment.