From e57bd21b47a305e19ea2617a1c32573c70035efa Mon Sep 17 00:00:00 2001 From: Nikolas Stevenson-Molnar Date: Sat, 28 Oct 2023 14:14:18 -0700 Subject: [PATCH 1/2] Add test action --- .github/workflows/python-tests.yml | 60 ++++++++++++++++++++++++++++++ pg_database/tests/test_config.json | 1 + pg_database/tests/tests.py | 6 +-- tox.ini | 9 ----- 4 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/python-tests.yml diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml new file mode 100644 index 0000000..95ce311 --- /dev/null +++ b/.github/workflows/python-tests.yml @@ -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 diff --git a/pg_database/tests/test_config.json b/pg_database/tests/test_config.json index df06162..ae0e0f4 100644 --- a/pg_database/tests/test_config.json +++ b/pg_database/tests/test_config.json @@ -1,5 +1,6 @@ { "database-name": "test_pg_database", + "database-user": "postgres", "django-db-key": "other", "connect-args": {"sslmode": "prefer"}, "pooling-args": { diff --git a/pg_database/tests/tests.py b/pg_database/tests/tests.py index 0df225c..a3d7041 100644 --- a/pg_database/tests/tests.py +++ b/pg_database/tests/tests.py @@ -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)) @@ -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() @@ -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) diff --git a/tox.ini b/tox.ini index 3b8aaf3..f664460 100644 --- a/tox.ini +++ b/tox.ini @@ -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} From 0001dfe75aee7abb3d2ed883b6c753675b02cc14 Mon Sep 17 00:00:00 2001 From: Nikolas Stevenson-Molnar Date: Sat, 28 Oct 2023 19:50:50 -0700 Subject: [PATCH 2/2] Remove tox and travis configs --- .travis.yml | 41 ----------------------------------------- README.md | 3 --- tox.ini | 24 ------------------------ 3 files changed, 68 deletions(-) delete mode 100644 .travis.yml delete mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6be1182..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -dist: xenial -group: edge - -language: python -python: - - "3.8" - - "3.7" - - "3.6" -env: - - TOXENV=django - - TOXENV=nodjango - - TOXENV=coverage - -sudo: true # Allow the sudo command - -before_install: - - sudo apt-get update - - sudo apt-get --yes remove postgresql\* - - sudo apt-get install -y postgresql-12 postgresql-client-12 postgresql-12-postgis-2.5 postgresql-12-postgis-2.5-scripts - - sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/12/main/postgresql.conf - - sudo cp /etc/postgresql/{9.6,12}/main/pg_hba.conf - - sudo cp /etc/postgresql/{10,12}/main/pg_hba.conf - - sudo service postgresql restart 12 -install: - - pip install frozendict - - pip install sqlalchemy - - pip install GeoAlchemy2 - - pip install psycopg2-binary - - pip install coveralls - - pip install tox - -before_script: - - 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 -script: - - tox -after_success: - coveralls diff --git a/README.md b/README.md index 00393dc..fc3c6f2 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # pg-database-utils -[![Build Status](https://api.travis-ci.com/consbio/pg-database-utils.png?branch=main)](https://app.travis-ci.com/github/consbio/pg-database-utils) -[![Coverage Status](https://coveralls.io/repos/github/consbio/pg-database-utils/badge.svg?branch=main)](https://coveralls.io/github/consbio/pg-database-utils?branch=main) - A suite of utilities for PostgreSQL database queries and operations built on sqlalchemy. This library includes support for: diff --git a/tox.ini b/tox.ini deleted file mode 100644 index f664460..0000000 --- a/tox.ini +++ /dev/null @@ -1,24 +0,0 @@ -[tox] -envlist = django, nodjango - -[testenv] -commands = py.test -setenv = - DATABASE_CONFIG_JSON={toxinidir}/pg_database/tests/test_config.json - DJANGO_SETTINGS_MODULE=pg_database.tests.settings - PYTHONPATH={toxinidir} - -[base] -deps = - mock - pytest - pytest-cov - -[testenv:django] -deps = - Django - {[base]deps} - -[testenv:nodjango] -deps = - {[base]deps}