Skip to content

Commit

Permalink
v1.0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
ddc committed Dec 19, 2024
1 parent b4bd7d7 commit 9c84173
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 140 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Unit Tests
name: Run Pytest

on:
push:
Expand All @@ -8,7 +8,7 @@ on:
- "!main"

jobs:
run_tests:
pytest:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Run tests
run: |
python -m poetry run coverage run --omit=./tests/* --source=./ddcDatabases -m pytest -v
python -m poetry run coverage run --omit=./tests/* -m pytest -v
- name: Generate Coverage Report
run: |
Expand All @@ -44,3 +44,4 @@ jobs:
# uses: codecov/codecov-action@v5
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# slug: ddc/ddcDatabases
3 changes: 2 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Run tests
run: |
python -m poetry run coverage run --omit=./tests/* --source=./ddcDatabases -m pytest -v
python -m poetry run coverage run --omit=./tests/* -m pytest -v
- name: Generate Coverage Report
run: |
Expand All @@ -43,6 +43,7 @@ jobs:
# uses: codecov/codecov-action@v5
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# slug: ddc/ddcDatabases

- name: Build package with poetry
run: |
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Databases Connection and Queries

[![Donate](https://img.shields.io/badge/Donate-PayPal-brightgreen.svg?style=plastic)](https://www.paypal.com/ncp/payment/6G9Z78QHUD4RJ)
[![License](https://img.shields.io/pypi/l/ddcDatabases)](https://github.com/ddc/ddcDatabases/blob/master/LICENSE)
[![Python](https://img.shields.io/pypi/pyversions/ddcDatabases.svg)](https://www.python.org)
[![PyPi](https://img.shields.io/pypi/v/ddcDatabases.svg)](https://pypi.python.org/pypi/ddcDatabases)
[![PyPI Downloads](https://static.pepy.tech/badge/ddcDatabases)](https://pepy.tech/projects/ddcDatabases)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A//actions-badge.atrox.dev/ddc/ddcDatabases/badge?ref=main&label=build&logo=none)](https://actions-badge.atrox.dev/ddc/ddcDatabases/goto?ref=main)
[![Python](https://img.shields.io/pypi/pyversions/ddcDatabases.svg)](https://www.python.org)

[//]: # ([![codecov](https://codecov.io/github/ddc/ddcDatabases/graph/badge.svg?token=E942EZII4Q)](https://codecov.io/github/ddc/ddcDatabases))

Expand Down Expand Up @@ -35,7 +36,7 @@ pip install ddcDatabases[pgsql]
# Databases
+ Parameters for all classes are declared as OPTIONAL falling back to [.env](./ddcDatabases/.env.example) file variables
+ All examples are using [db_utils.py](ddcDatabases/db_utils.py)
+ By default, the MSSQL class will open a session to the database, but the engine can be available
+ By default, the MSSQL class will open a session to the database, but the engine can be available at `session.bind`
+ SYNC sessions defaults:
+ `autoflush is True`
+ `expire_on_commit is True`
Expand Down Expand Up @@ -73,7 +74,8 @@ with Sqlite() as session:
#### Sync Engine
```python
from ddcDatabases import Sqlite
with Sqlite().engine() as engine:
with Sqlite() as session:
engine = session.bind
...
```

Expand Down Expand Up @@ -126,14 +128,16 @@ async with MSSQL() as session:
#### Sync Engine
```python
from ddcDatabases import MSSQL
with MSSQL().engine() as engine:
with MSSQL() as session:
engine = session.bind
...
```

#### Async Engine
```python
from ddcDatabases import MSSQL
async with MSSQL().async_engine() as engine:
async with MSSQL() as session:
engine = await session.bind
...
```

Expand Down Expand Up @@ -184,14 +188,16 @@ async with PostgreSQL() as session:
#### Sync Engine
```python
from ddcDatabases import PostgreSQL
with PostgreSQL().engine() as engine:
with PostgreSQL() as session:
engine = session.bind
...
```

#### Async Engine
```python
from ddcDatabases import PostgreSQL
async with PostgreSQL().async_engine() as engine:
async with PostgreSQL() as session:
engine = await session.bind
...
```

Expand Down
210 changes: 105 additions & 105 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
requires = ["poetry-core>=1.9.1"]
build-backend = "poetry.core.masonry.api"


[tool.poetry]
name = "ddcDatabases"
version = "1.0.17"
version = "1.0.18"
description = "Databases Connection and Queries"
license = "MIT"
readme = "README.md"
Expand Down Expand Up @@ -33,9 +34,11 @@ classifiers = [
"Natural Language :: English",
]


[tool.poetry.group.test]
optional = true


[tool.poetry.dependencies]
python = "^3.10"
aioodbc = "^0.5.0"
Expand All @@ -46,20 +49,29 @@ pyodbc = "^5.2.0"
SQLAlchemy = "^2.0.36"
pytest = "^8.3.4"


[tool.poetry.extras]
mssql = [ "pyodbc", "aioodbc" ]
pgsql = [ "psycopg2-binary", "asyncpg" ]
all = [ "pyodbc", "aioodbc", "psycopg2-binary", "asyncpg" ]


[tool.poetry.group.test.dependencies]
coverage = "^7.6.9"
faker = "^33.1.0"
poethepoet = "^0.31.1"
pytest = "^8.3.4"


[tool.coverage.run]
omit = [
"tests/*",
]


[tool.poe.tasks]
_test = "poetry run coverage run --omit=./tests/* --source=./ddcDatabases -m pytest -v"
_coverage_report = "poetry run coverage report"
_coverage_xml = "poetry run coverage xml"
_test = "coverage run -m pytest -v"
_coverage_report = "coverage report"
_coverage_xml = "coverage xml"
tests = ["_test", "_coverage_report", "_coverage_xml"]
test = ["tests"]
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import pytest
from sqlalchemy.pool import StaticPool
from ddcDatabases import Sqlite
from tests.data.base_data import get_fake_test_data, sqlite_filename
from tests.data.base_data import get_fake_test_data


@pytest.fixture(name="sqlite_session", scope="session")
def sqlite_session():
extra_engine_args = {"poolclass": StaticPool}
with Sqlite(
filepath=sqlite_filename,
filepath=":memory:",
extra_engine_args=extra_engine_args,
) as session:
yield session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sqlalchemy as sa
from ddcDatabases import DBUtils
from ddcDatabases.exceptions import DBFetchAllException
from tests.models.test_model import ModelTest
from tests.models.model_test import ModelTest


class ModelDalTest:
Expand Down
3 changes: 0 additions & 3 deletions tests/data/base_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
from faker import Faker


sqlite_filename = "test.db"


def _set_randoms():
_faker = Faker(locale="en_US")
return {
Expand Down
File renamed without changes.
25 changes: 11 additions & 14 deletions tests/unit/test_sqlite.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
# -*- coding: utf-8 -*-
import os
import pytest
from ddcDatabases import Sqlite
from tests.dal.test_model_dal import ModelDalTest
from tests.data.base_data import sqlite_filename
from tests.models.test_model import ModelTest
from tests.dal.model_dal_test import ModelDalTest
from tests.models.model_test import ModelTest


class TestSQLite:
@classmethod
def setup_class(cls):
with Sqlite(sqlite_filename).engine() as engine:
ModelTest.__table__.create(engine)
""" setup_class """
pass

@classmethod
def teardown_class(cls):
os.remove(sqlite_filename)
""" teardown_class """
pass

@pytest.fixture(autouse=True, scope="class")
def test_insert(self, sqlite_session, fake_test_data):
def test_sqlite(self, sqlite_session, fake_test_data):
ModelTest.__table__.create(sqlite_session.bind)
sqlite_session.add(ModelTest(**fake_test_data))
config_dal = ModelDalTest(sqlite_session)
config_id = fake_test_data["id"]
results = config_dal.get(config_id)
assert len(results) == 1

def test_get(self, sqlite_session, fake_test_data):
# test_get
test_dal = ModelDalTest(sqlite_session)
config_id = fake_test_data["id"]
results = test_dal.get(config_id)
assert len(results) == 1

def test_update_str(self, sqlite_session, fake_test_data):
# test_update_str
test_dal = ModelDalTest(sqlite_session)
_id = fake_test_data["id"]
name = "Test_1"
test_dal.update_name(name, _id)
results = test_dal.get(_id)
assert results[0]["name"] == name

def test_update_bool(self, sqlite_session, fake_test_data):
# test_update_bool
test_dal = ModelDalTest(sqlite_session)
_id = fake_test_data["id"]
status = (True, False,)
Expand Down

0 comments on commit 9c84173

Please sign in to comment.