Skip to content

Commit

Permalink
fix: Address compatibilities with sqlalchemy 2.
Browse files Browse the repository at this point in the history
* (unnecessary) string conversion of URL object produces obfuscated password
  • Loading branch information
DanCardin committed Dec 24, 2022
1 parent 76c7ed3 commit 3f01fb2
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 186 deletions.
57 changes: 0 additions & 57 deletions .github/workflows/build.yml

This file was deleted.

112 changes: 0 additions & 112 deletions .github/workflows/lint_and_test.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Github Release/Publish PyPi

on:
push:
tags:
- "v*.*.*"

jobs:
gh-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true

publish-pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Run image
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: 1.2.0

- name: Publish
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
92 changes: 92 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Test

on:
pull_request:
branches:
- main
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Test our minimum version bound, the highest version available,
# and something in the middle (i.e. what gets run locally).
python-version: ["3.7", "3.9", "3.11"]
pytest-asyncio-version: ["0.16.0", "0.19.0"]
sqlalchemy-version: ["1.3.0", "1.4.0", "2.0.0b4"]

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install poetry
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: 1.2.0

- name: Set up cache
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Install base dependencies
run: poetry run make install-base

- name: Install specific sqlalchemy version
run: |
poetry run pip install 'sqlalchemy~=${{ matrix.sqlalchemy-version }}'
- name: Install specific pytest-asyncio version
run: pip install 'pytest-asyncio~=${{ matrix.pytest-asyncio-version }}'

- if: ${{ matrix.python-version == '3.9' && matrix.sqlalchemy-version == '1.4.0' }}
run: poetry run make lint

- run: poetry run make test-base

- name: Install dependencies
run: poetry run make install

- run: poetry run make test

- name: Store test result artifacts
uses: actions/upload-artifact@v3
with:
path: coverage.xml

- name: Coveralls
env:
COVERALLS_FLAG_NAME: run-${{ inputs.working-directory }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
run: |
pip install tomli coveralls
coveralls --service=github
finish:
needs:
- test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pip install tomli coveralls
coveralls --service=github --finish
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pytest-mock-resources"
version = "2.6.4"
version = "2.6.5"
description = "A pytest plugin for easily instantiating reproducible mock resources."
authors = [
"Omar Khan <oakhan3@gmail.com>",
Expand Down
18 changes: 8 additions & 10 deletions src/pytest_mock_resources/container/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ def check_fn(self):


def get_sqlalchemy_engine(config, database_name, isolation_level=None):
DB_URI = str(
compat.sqlalchemy.URL(
"mysql+pymysql",
username=config.username,
password=config.password,
host=config.host,
port=config.port,
database=database_name,
)
url = compat.sqlalchemy.URL(
"mysql+pymysql",
username=config.username,
password=config.password,
host=config.host,
port=config.port,
database=database_name,
)

options = {}
Expand All @@ -90,7 +88,7 @@ def get_sqlalchemy_engine(config, database_name, isolation_level=None):

pymysql.connect

engine = sqlalchemy.create_engine(DB_URI, **options)
engine = sqlalchemy.create_engine(url, **options)

# Verify engine is connected
engine.connect()
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_mock_resources/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _create_schemas(self, conn, metadata):
if self.default_schema == schema:
continue

statement = CreateSchema(schema, quote=True)
statement = CreateSchema(schema)
conn.execute(statement)

def _create_tables(self, conn, metadata):
Expand Down
6 changes: 2 additions & 4 deletions tests/fixture/test_ordered_actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

import pytest
from sqlalchemy import Column, ForeignKey, Integer, String, text
from sqlalchemy.exc import ProgrammingError
Expand All @@ -19,7 +17,7 @@ class User(Base):
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String, nullable=False)

objects: List["Object"] = relationship("Object", back_populates="owner")
objects = relationship("Object", back_populates="owner", uselist=True) # type: ignore


class Object(Base):
Expand All @@ -30,7 +28,7 @@ class Object(Base):
name = Column(String, nullable=False)
belongs_to = Column(Integer, ForeignKey("stuffs.user.id"))

owner: List[User] = relationship("User", back_populates="objects")
owner = relationship("User", back_populates="objects", uselist=False) # type: ignore


rows = Rows(User(name="Harold"), User(name="Gump"))
Expand Down
2 changes: 2 additions & 0 deletions tests/fixture/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pytest_mock_resources import create_postgres_fixture, create_sqlite_fixture, Rows
from pytest_mock_resources.compat.sqlalchemy import declarative_base, select
from pytest_mock_resources.fixture.sqlite import utc
from tests import skip_if_sqlalchemy2

Base = declarative_base()

Expand Down Expand Up @@ -110,6 +111,7 @@ class NumericTable(NumericBase):
sqlite_without_warnings = create_sqlite_fixture(NumericBase)


@skip_if_sqlalchemy2
def test_decimal_warnings_enabled(sqlite_with_warnings):
with sqlite_with_warnings.begin() as conn:
conn.execute(text("INSERT INTO numeric (id, value) VALUES (1, 1)"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def test_multiprocess_redis_database(pytester):
pytester.copy_example()

# The `-n 4` are here is tightly coupled with the implementation of `test_split.py`.
args = ["-vv", "-n", "4", "test_split.py"]
args = ["-vv", "-n", "4", "--pmr-multiprocess-safe", "test_split.py"]
result = pytester.inline_run(*args)
result.assertoutcome(passed=4, skipped=0, failed=0)

Expand Down

0 comments on commit 3f01fb2

Please sign in to comment.