mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-05-13 12:58:45 +02:00
Chore/rework workflow (#52)
* Reworked the lint action * Removed the file change requirement * Repaired mypy * Repaired pip-audit
This commit is contained in:
parent
daa315804e
commit
e4a57c9136
2
.github/workflows/documentation.yaml
vendored
2
.github/workflows/documentation.yaml
vendored
@ -5,8 +5,6 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
doc-build:
|
doc-build:
|
||||||
|
24
.github/workflows/lint-actions.yaml
vendored
24
.github/workflows/lint-actions.yaml
vendored
@ -2,10 +2,6 @@ name: Python-Lint
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
|
||||||
- '*.py'
|
|
||||||
- poetry.lock
|
|
||||||
- pyproject.toml
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@ -49,7 +45,7 @@ jobs:
|
|||||||
- run: poetry install --without develop,doc
|
- run: poetry install --without develop,doc
|
||||||
- name: Run linters
|
- name: Run linters
|
||||||
run: |
|
run: |
|
||||||
mypy src tests --install-types --non-interactive
|
mypy src tests
|
||||||
|
|
||||||
ruff:
|
ruff:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -72,21 +68,19 @@ jobs:
|
|||||||
uses: snok/install-poetry@v1
|
uses: snok/install-poetry@v1
|
||||||
with:
|
with:
|
||||||
version: 1.4.2
|
version: 1.4.2
|
||||||
|
virtualenvs-create: true
|
||||||
virtualenvs-path: ~/local/share/virtualenvs
|
virtualenvs-path: ~/local/share/virtualenvs
|
||||||
- name: Cache pipenv
|
|
||||||
id: cache-pipenv
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: ~/.local/share/virtualenvs
|
|
||||||
key: venv
|
|
||||||
- name: Check out Git repository
|
- name: Check out Git repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
- name: Install root, pip-licenses & pip-audit
|
||||||
|
run: |
|
||||||
|
poetry install --only-root
|
||||||
|
poetry run pip install pip-licenses pip-audit
|
||||||
- name: Poetry export
|
- name: Poetry export
|
||||||
run: poetry export -f requirements.txt --output requirements.txt
|
run: poetry export -f requirements.txt --output requirements.txt
|
||||||
- name: Check license
|
- name: Check license
|
||||||
run: |
|
run: |
|
||||||
pip install pip-licenses
|
poetry run pip-licenses --format=markdown --output-file=license-summary.md
|
||||||
pip-licenses --format=markdown --output-file=license-summary.md
|
|
||||||
- name: Archive license summary
|
- name: Archive license summary
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
@ -96,6 +90,4 @@ jobs:
|
|||||||
requirements.txt
|
requirements.txt
|
||||||
- name: Check requirements security with pip-audit
|
- name: Check requirements security with pip-audit
|
||||||
run: |
|
run: |
|
||||||
pip install pip-audit
|
poetry run pip-audit --format markdown -o lbr-audit.md
|
||||||
pip-audit -r requirements.txt --no-deps --disable-pip || true
|
|
||||||
pip-audit -r requirements.txt --format=markdown --output=lbr-audit.md --no-deps --disable-pip
|
|
||||||
|
4
.github/workflows/test-and-build-action.yaml
vendored
4
.github/workflows/test-and-build-action.yaml
vendored
@ -3,10 +3,6 @@ name: Test & Build
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
paths:
|
|
||||||
- '*.py'
|
|
||||||
- poetry.lock
|
|
||||||
- pyproject.toml
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -215,3 +215,4 @@ replay_pid*
|
|||||||
/documentations/aki_prj23_transparenzregister.*
|
/documentations/aki_prj23_transparenzregister.*
|
||||||
/documentations/modules.rst
|
/documentations/modules.rst
|
||||||
/unit-test-results.xml
|
/unit-test-results.xml
|
||||||
|
/lbr-audit.md
|
||||||
|
75
poetry.lock
generated
75
poetry.lock
generated
@ -672,6 +672,52 @@ files = [
|
|||||||
[package.extras]
|
[package.extras]
|
||||||
toml = ["tomli"]
|
toml = ["tomli"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cryptography"
|
||||||
|
version = "41.0.3"
|
||||||
|
description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers."
|
||||||
|
category = "dev"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.7"
|
||||||
|
files = [
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-macosx_10_12_universal2.whl", hash = "sha256:652627a055cb52a84f8c448185922241dd5217443ca194d5739b44612c5e6507"},
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:8f09daa483aedea50d249ef98ed500569841d6498aa9c9f4b0531b9964658922"},
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4fd871184321100fb400d759ad0cddddf284c4b696568204d281c902fc7b0d81"},
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:84537453d57f55a50a5b6835622ee405816999a7113267739a1b4581f83535bd"},
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:3fb248989b6363906827284cd20cca63bb1a757e0a2864d4c1682a985e3dca47"},
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:42cb413e01a5d36da9929baa9d70ca90d90b969269e5a12d39c1e0d475010116"},
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:aeb57c421b34af8f9fe830e1955bf493a86a7996cc1338fe41b30047d16e962c"},
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:6af1c6387c531cd364b72c28daa29232162010d952ceb7e5ca8e2827526aceae"},
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-win32.whl", hash = "sha256:0d09fb5356f975974dbcb595ad2d178305e5050656affb7890a1583f5e02a306"},
|
||||||
|
{file = "cryptography-41.0.3-cp37-abi3-win_amd64.whl", hash = "sha256:a983e441a00a9d57a4d7c91b3116a37ae602907a7618b882c8013b5762e80574"},
|
||||||
|
{file = "cryptography-41.0.3-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:5259cb659aa43005eb55a0e4ff2c825ca111a0da1814202c64d28a985d33b087"},
|
||||||
|
{file = "cryptography-41.0.3-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:67e120e9a577c64fe1f611e53b30b3e69744e5910ff3b6e97e935aeb96005858"},
|
||||||
|
{file = "cryptography-41.0.3-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:7efe8041897fe7a50863e51b77789b657a133c75c3b094e51b5e4b5cec7bf906"},
|
||||||
|
{file = "cryptography-41.0.3-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:ce785cf81a7bdade534297ef9e490ddff800d956625020ab2ec2780a556c313e"},
|
||||||
|
{file = "cryptography-41.0.3-pp38-pypy38_pp73-macosx_10_12_x86_64.whl", hash = "sha256:57a51b89f954f216a81c9d057bf1a24e2f36e764a1ca9a501a6964eb4a6800dd"},
|
||||||
|
{file = "cryptography-41.0.3-pp38-pypy38_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:4c2f0d35703d61002a2bbdcf15548ebb701cfdd83cdc12471d2bae80878a4207"},
|
||||||
|
{file = "cryptography-41.0.3-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:23c2d778cf829f7d0ae180600b17e9fceea3c2ef8b31a99e3c694cbbf3a24b84"},
|
||||||
|
{file = "cryptography-41.0.3-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:95dd7f261bb76948b52a5330ba5202b91a26fbac13ad0e9fc8a3ac04752058c7"},
|
||||||
|
{file = "cryptography-41.0.3-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:41d7aa7cdfded09b3d73a47f429c298e80796c8e825ddfadc84c8a7f12df212d"},
|
||||||
|
{file = "cryptography-41.0.3-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:d0d651aa754ef58d75cec6edfbd21259d93810b73f6ec246436a21b7841908de"},
|
||||||
|
{file = "cryptography-41.0.3-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:ab8de0d091acbf778f74286f4989cf3d1528336af1b59f3e5d2ebca8b5fe49e1"},
|
||||||
|
{file = "cryptography-41.0.3-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:a74fbcdb2a0d46fe00504f571a2a540532f4c188e6ccf26f1f178480117b33c4"},
|
||||||
|
{file = "cryptography-41.0.3.tar.gz", hash = "sha256:6d192741113ef5e30d89dcb5b956ef4e1578f304708701b8b73d38e3e1461f34"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
cffi = ">=1.12"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
docs = ["sphinx (>=5.3.0)", "sphinx-rtd-theme (>=1.1.1)"]
|
||||||
|
docstest = ["pyenchant (>=1.6.11)", "sphinxcontrib-spelling (>=4.0.1)", "twine (>=1.12.0)"]
|
||||||
|
nox = ["nox"]
|
||||||
|
pep8test = ["black", "check-sdist", "mypy", "ruff"]
|
||||||
|
sdist = ["build"]
|
||||||
|
ssh = ["bcrypt (>=3.1.5)"]
|
||||||
|
test = ["pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-xdist"]
|
||||||
|
test-randomorder = ["pytest-randomly"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cycler"
|
name = "cycler"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@ -4442,6 +4488,21 @@ exceptiongroup = "*"
|
|||||||
trio = ">=0.11"
|
trio = ">=0.11"
|
||||||
wsproto = ">=0.14"
|
wsproto = ">=0.14"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "types-pyopenssl"
|
||||||
|
version = "23.2.0.2"
|
||||||
|
description = "Typing stubs for pyOpenSSL"
|
||||||
|
category = "dev"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
files = [
|
||||||
|
{file = "types-pyOpenSSL-23.2.0.2.tar.gz", hash = "sha256:6a010dac9ecd42b582d7dd2cc3e9e40486b79b3b64bb2fffba1474ff96af906d"},
|
||||||
|
{file = "types_pyOpenSSL-23.2.0.2-py3-none-any.whl", hash = "sha256:19536aa3debfbe25a918cf0d898e9f5fbbe6f3594a429da7914bf331deb1b342"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
cryptography = ">=35.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "types-pytz"
|
name = "types-pytz"
|
||||||
version = "2023.3.0.1"
|
version = "2023.3.0.1"
|
||||||
@ -4469,6 +4530,18 @@ files = [
|
|||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
types-urllib3 = "*"
|
types-urllib3 = "*"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "types-setuptools"
|
||||||
|
version = "68.1.0.0"
|
||||||
|
description = "Typing stubs for setuptools"
|
||||||
|
category = "dev"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
files = [
|
||||||
|
{file = "types-setuptools-68.1.0.0.tar.gz", hash = "sha256:2bc9b0c0818f77bdcec619970e452b320a423bb3ac074f5f8bc9300ac281c4ae"},
|
||||||
|
{file = "types_setuptools-68.1.0.0-py3-none-any.whl", hash = "sha256:0c1618fb14850cb482adbec602bbb519c43f24942d66d66196bc7528320f33b1"},
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "types-tqdm"
|
name = "types-tqdm"
|
||||||
version = "4.66.0.1"
|
version = "4.66.0.1"
|
||||||
@ -4694,4 +4767,4 @@ h11 = ">=0.9.0,<1"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.11"
|
python-versions = "^3.11"
|
||||||
content-hash = "dbf83df77d434d397b384a0c7fdcf68c4594e7e77cd195e247f3fe2030d79697"
|
content-hash = "946f6b81f3072e2a3d93482405f7bbe6f02218a3c2097c1f3f8246363c7e15c2"
|
||||||
|
@ -2,25 +2,30 @@
|
|||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
|
|
||||||
[tookl.mypy]
|
|
||||||
disallow_untyped_defs = true
|
|
||||||
exclude = ".ipynb_checkpoints, .mypy_cache, .mytest_cache, build"
|
|
||||||
follow_imports = "silent"
|
|
||||||
ignore_missing_imports = true
|
|
||||||
plugins = ["sqlalchemy.ext.mypy.plugin"]
|
|
||||||
python_version = "3.11"
|
|
||||||
warn_redundant_casts = true
|
|
||||||
warn_unused_ignores = true
|
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
target-version = ["py311"]
|
target-version = ["py311"]
|
||||||
|
|
||||||
|
[tool.coverage.report]
|
||||||
|
exclude_also = ["if __name__ == .__main__.:"]
|
||||||
|
|
||||||
[tool.coverage.run]
|
[tool.coverage.run]
|
||||||
branch = true
|
branch = true
|
||||||
dynamic_context = "test_function"
|
dynamic_context = "test_function"
|
||||||
relative_files = true
|
relative_files = true
|
||||||
source = ["src"]
|
source = ["src"]
|
||||||
|
|
||||||
|
[tool.mypy]
|
||||||
|
disallow_untyped_defs = true
|
||||||
|
exclude = ".ipynb_checkpoints, .mypy_cache, .mytest_cache, build"
|
||||||
|
follow_imports = "silent"
|
||||||
|
ignore_missing_imports = true
|
||||||
|
install_types = true
|
||||||
|
non_interactive = true
|
||||||
|
plugins = ["sqlalchemy.ext.mypy.plugin"]
|
||||||
|
python_version = "3.11"
|
||||||
|
warn_redundant_casts = true
|
||||||
|
warn_unused_ignores = true
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
authors = ["AKI Projektgruppe 23"]
|
authors = ["AKI Projektgruppe 23"]
|
||||||
description = "A project analysing the german transparenzregister and other data sources to find shared business interests and shared personal and other links for lots of companies."
|
description = "A project analysing the german transparenzregister and other data sources to find shared business interests and shared personal and other links for lots of companies."
|
||||||
@ -67,7 +72,9 @@ pandas-stubs = "^2.0.1.230501"
|
|||||||
pip-audit = "^2.6.1"
|
pip-audit = "^2.6.1"
|
||||||
pip-licenses = "^4.3.2"
|
pip-licenses = "^4.3.2"
|
||||||
ruff = "^0.0.270"
|
ruff = "^0.0.270"
|
||||||
|
types-pyOpenSSL = "*"
|
||||||
types-requests = "^2.31.0.1"
|
types-requests = "^2.31.0.1"
|
||||||
|
types-setuptools = "*"
|
||||||
types-tqdm = "^4.65.0"
|
types-tqdm = "^4.65.0"
|
||||||
|
|
||||||
[tool.poetry.group.test.dependencies]
|
[tool.poetry.group.test.dependencies]
|
||||||
@ -108,7 +115,6 @@ line-length = 88
|
|||||||
select = ["E", "F", "B", "I", "S", "RSE", "RET", "SLF", "SIM", "TID", "PD", "PL", "PLE", "PLR", "PLW", "NPY", "UP", "D", "N", "A", "C4", "T20", "PT"]
|
select = ["E", "F", "B", "I", "S", "RSE", "RET", "SLF", "SIM", "TID", "PD", "PL", "PLE", "PLR", "PLW", "NPY", "UP", "D", "N", "A", "C4", "T20", "PT"]
|
||||||
src = ["src"]
|
src = ["src"]
|
||||||
target-version = "py311"
|
target-version = "py311"
|
||||||
# Avoid trying to fix flake8-bugbear (`B`) violations.
|
|
||||||
unfixable = ["B"]
|
unfixable = ["B"]
|
||||||
|
|
||||||
[tool.ruff.flake8-builtins]
|
[tool.ruff.flake8-builtins]
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "win32" or python_version >= "3.11" and python_version < "4.0" and platform_system == "Windows"
|
|
||||||
contourpy==1.1.0 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
cycler==0.11.0 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
fonttools==4.40.0 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
kiwisolver==1.4.4 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
loguru==0.7.0 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
matplotlib==3.7.1 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
numpy==1.25.0 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
packaging==23.1 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
pandas==2.0.2 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
pillow==9.5.0 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
plotly==5.15.0 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
pyparsing==3.0.9 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
python-dateutil==2.8.2 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
pytz==2023.3 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
seaborn==0.12.2 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
six==1.16.0 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
tenacity==8.2.2 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
tqdm==4.65.0 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
tzdata==2023.3 ; python_version >= "3.11" and python_version < "4.0"
|
|
||||||
win32-setctime==1.1.0 ; python_version >= "3.11" and python_version < "4.0" and sys_platform == "win32"
|
|
@ -13,7 +13,7 @@ if __name__ == "__main__":
|
|||||||
session = get_session()
|
session = get_session()
|
||||||
query = session.query(entities.Company)
|
query = session.query(entities.Company)
|
||||||
|
|
||||||
companies_df = pd.read_sql(str(query), session.bind)
|
companies_df: pd.DataFrame = pd.read_sql(str(query), session.bind) # type: ignore
|
||||||
app = Dash(__name__)
|
app = Dash(__name__)
|
||||||
|
|
||||||
app.layout = dash_table.DataTable(
|
app.layout = dash_table.DataTable(
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""CompanyMongoService."""
|
"""CompanyMongoService."""
|
||||||
|
from pymongo.results import InsertOneResult
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.models.company import Company, CompanyID
|
from aki_prj23_transparenzregister.models.company import Company, CompanyID
|
||||||
from aki_prj23_transparenzregister.utils.mongo.connector import MongoConnector
|
from aki_prj23_transparenzregister.utils.mongo.connector import MongoConnector
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ class CompanyMongoService:
|
|||||||
return result[0]
|
return result[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def insert(self, company: Company):
|
def insert(self, company: Company) -> InsertOneResult:
|
||||||
"""_summary_.
|
"""_summary_.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""MongoNewsService."""
|
"""MongoNewsService."""
|
||||||
|
from pymongo.results import InsertOneResult
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.models.news import News
|
from aki_prj23_transparenzregister.models.news import News
|
||||||
from aki_prj23_transparenzregister.utils.mongo.connector import MongoConnector
|
from aki_prj23_transparenzregister.utils.mongo.connector import MongoConnector
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ class MongoNewsService:
|
|||||||
return MongoEntryTransformer.transform_outgoing(result[0])
|
return MongoEntryTransformer.transform_outgoing(result[0])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def insert(self, news: News):
|
def insert(self, news: News) -> InsertOneResult:
|
||||||
"""_summary_.
|
"""_summary_.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
"""Module containing connection utils for PostgreSQL DB."""
|
"""Module containing connection utils for PostgreSQL DB."""
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.engine import URL
|
from sqlalchemy.engine import URL, Engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import Session, sessionmaker
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
|
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
|
||||||
from aki_prj23_transparenzregister.config.config_template import PostgreConnectionString
|
from aki_prj23_transparenzregister.config.config_template import PostgreConnectionString
|
||||||
from aki_prj23_transparenzregister.utils.postgres.entities import Base
|
from aki_prj23_transparenzregister.utils.postgres.entities import Base
|
||||||
|
|
||||||
|
|
||||||
def get_engine(conn_args: PostgreConnectionString):
|
def get_engine(conn_args: PostgreConnectionString) -> Engine:
|
||||||
"""Creates an engine connected to a Postgres instance.
|
"""Creates an engine connected to a Postgres instance.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -26,7 +26,7 @@ def get_engine(conn_args: PostgreConnectionString):
|
|||||||
return create_engine(url)
|
return create_engine(url)
|
||||||
|
|
||||||
|
|
||||||
def get_session():
|
def get_session() -> Session: # pragma: no cover
|
||||||
"""Return PG Session."""
|
"""Return PG Session."""
|
||||||
config_provider = JsonFileConfigProvider("./secrets.json")
|
config_provider = JsonFileConfigProvider("./secrets.json")
|
||||||
engine = get_engine(config_provider.get_postgre_connection_string())
|
engine = get_engine(config_provider.get_postgre_connection_string())
|
||||||
@ -34,7 +34,7 @@ def get_session():
|
|||||||
return session()
|
return session()
|
||||||
|
|
||||||
|
|
||||||
def init_db():
|
def init_db() -> None:
|
||||||
"""Initialize DB with all defined entities."""
|
"""Initialize DB with all defined entities."""
|
||||||
config_provider = JsonFileConfigProvider("./secrets.json")
|
config_provider = JsonFileConfigProvider("./secrets.json")
|
||||||
engine = get_engine(config_provider.get_postgre_connection_string())
|
engine = get_engine(config_provider.get_postgre_connection_string())
|
||||||
|
@ -17,7 +17,7 @@ from aki_prj23_transparenzregister.utils.enumy_types import (
|
|||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
class DistrictCourt(Base): # type: ignore
|
class DistrictCourt(Base):
|
||||||
"""DistrictCourt."""
|
"""DistrictCourt."""
|
||||||
|
|
||||||
__tablename__ = "district_court"
|
__tablename__ = "district_court"
|
||||||
@ -27,7 +27,7 @@ class DistrictCourt(Base): # type: ignore
|
|||||||
name = sa.Column(sa.String(100), nullable=False)
|
name = sa.Column(sa.String(100), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
class Company(Base): # type: ignore
|
class Company(Base):
|
||||||
"""Company."""
|
"""Company."""
|
||||||
|
|
||||||
__tablename__ = "company"
|
__tablename__ = "company"
|
||||||
@ -51,7 +51,7 @@ class Company(Base): # type: ignore
|
|||||||
sector = sa.Column(sa.String(100), nullable=False)
|
sector = sa.Column(sa.String(100), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
class Finance(Base): # type: ignore
|
class Finance(Base):
|
||||||
"""Finance."""
|
"""Finance."""
|
||||||
|
|
||||||
__tablename__ = "finance"
|
__tablename__ = "finance"
|
||||||
@ -72,7 +72,7 @@ class Finance(Base): # type: ignore
|
|||||||
# company: Mapped[Company] = relationship(Company)
|
# company: Mapped[Company] = relationship(Company)
|
||||||
|
|
||||||
|
|
||||||
class Sentiment(Base): # type: ignore
|
class Sentiment(Base):
|
||||||
"""Sentiment."""
|
"""Sentiment."""
|
||||||
|
|
||||||
# noinspection SpellCheckingInspection
|
# noinspection SpellCheckingInspection
|
||||||
@ -92,7 +92,7 @@ class Sentiment(Base): # type: ignore
|
|||||||
|
|
||||||
|
|
||||||
# create person object
|
# create person object
|
||||||
class Person(Base): # type: ignore
|
class Person(Base):
|
||||||
"""Person."""
|
"""Person."""
|
||||||
|
|
||||||
__tablename__ = "person"
|
__tablename__ = "person"
|
||||||
@ -104,7 +104,7 @@ class Person(Base): # type: ignore
|
|||||||
|
|
||||||
|
|
||||||
# create own relation type and person_relation object
|
# create own relation type and person_relation object
|
||||||
class PersonRelation(Base): # type: ignore
|
class PersonRelation(Base):
|
||||||
"""PersonRelation."""
|
"""PersonRelation."""
|
||||||
|
|
||||||
__tablename__ = "person_relation"
|
__tablename__ = "person_relation"
|
||||||
@ -122,7 +122,7 @@ class PersonRelation(Base): # type: ignore
|
|||||||
|
|
||||||
|
|
||||||
# create own relation type and company_relation object
|
# create own relation type and company_relation object
|
||||||
class CompanyRelation(Base): # type: ignore
|
class CompanyRelation(Base):
|
||||||
"""CompanyRelation."""
|
"""CompanyRelation."""
|
||||||
|
|
||||||
__tablename__ = "company_relation"
|
__tablename__ = "company_relation"
|
||||||
|
@ -6,12 +6,12 @@ import pytest
|
|||||||
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
|
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
|
||||||
|
|
||||||
|
|
||||||
def test_json_provider_init_fail():
|
def test_json_provider_init_fail() -> None:
|
||||||
with pytest.raises(FileNotFoundError):
|
with pytest.raises(FileNotFoundError):
|
||||||
JsonFileConfigProvider("file-that-does-not-exist")
|
JsonFileConfigProvider("file-that-does-not-exist")
|
||||||
|
|
||||||
|
|
||||||
def test_json_provider_init_no_json():
|
def test_json_provider_init_no_json() -> None:
|
||||||
with patch("os.path.isfile") as mock_isfile, patch(
|
with patch("os.path.isfile") as mock_isfile, patch(
|
||||||
"builtins.open", mock_open(read_data="fhdaofhdoas")
|
"builtins.open", mock_open(read_data="fhdaofhdoas")
|
||||||
):
|
):
|
||||||
@ -20,7 +20,7 @@ def test_json_provider_init_no_json():
|
|||||||
JsonFileConfigProvider("non-json-file")
|
JsonFileConfigProvider("non-json-file")
|
||||||
|
|
||||||
|
|
||||||
def test_json_provider_init():
|
def test_json_provider_init() -> None:
|
||||||
data = {"hello": "world"}
|
data = {"hello": "world"}
|
||||||
input_data = json.dumps(data)
|
input_data = json.dumps(data)
|
||||||
with patch("os.path.isfile") as mock_isfile:
|
with patch("os.path.isfile") as mock_isfile:
|
||||||
@ -30,7 +30,7 @@ def test_json_provider_init():
|
|||||||
assert provider.__data__ == data
|
assert provider.__data__ == data
|
||||||
|
|
||||||
|
|
||||||
def test_json_provider_get_postgre():
|
def test_json_provider_get_postgres() -> None:
|
||||||
data = {
|
data = {
|
||||||
"postgres": {
|
"postgres": {
|
||||||
"username": "user",
|
"username": "user",
|
||||||
@ -52,7 +52,7 @@ def test_json_provider_get_postgre():
|
|||||||
assert config.port == data["postgres"]["port"]
|
assert config.port == data["postgres"]["port"]
|
||||||
|
|
||||||
|
|
||||||
def test_json_provider_get_mongo():
|
def test_json_provider_get_mongo() -> None:
|
||||||
data = {
|
data = {
|
||||||
"mongo": {
|
"mongo": {
|
||||||
"username": "user",
|
"username": "user",
|
||||||
|
7
tests/ui/company_stats_dash_test.py
Normal file
7
tests/ui/company_stats_dash_test.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"""Test the compy stats dash file."""
|
||||||
|
from aki_prj23_transparenzregister.ui import company_stats_dash
|
||||||
|
|
||||||
|
|
||||||
|
def test_company_stats_dash_import() -> None:
|
||||||
|
"""Since there is no single method to test the import is tested instead."""
|
||||||
|
assert company_stats_dash
|
@ -10,7 +10,7 @@ from aki_prj23_transparenzregister.utils.mongo.company_mongo_service import (
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def mock_mongo_connector(mocker) -> Mock:
|
def mock_mongo_connector(mocker: Mock) -> Mock:
|
||||||
"""Mock MongoConnector class.
|
"""Mock MongoConnector class.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -37,7 +37,7 @@ def mock_collection() -> Mock:
|
|||||||
return Mock()
|
return Mock()
|
||||||
|
|
||||||
|
|
||||||
def test_init(mock_mongo_connector, mock_collection):
|
def test_init(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||||
"""Test CompanyMongoService constructor.
|
"""Test CompanyMongoService constructor.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -49,7 +49,7 @@ def test_init(mock_mongo_connector, mock_collection):
|
|||||||
assert service.collection == mock_collection
|
assert service.collection == mock_collection
|
||||||
|
|
||||||
|
|
||||||
def test_get_all(mock_mongo_connector, mock_collection):
|
def test_get_all(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||||
"""Test CompanyMongoService get_all method.
|
"""Test CompanyMongoService get_all method.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -63,7 +63,7 @@ def test_get_all(mock_mongo_connector, mock_collection):
|
|||||||
assert service.get_all() == mock_result
|
assert service.get_all() == mock_result
|
||||||
|
|
||||||
|
|
||||||
def test_by_id_no_result(mock_mongo_connector, mock_collection):
|
def test_by_id_no_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||||
"""Test CompanyMongoService get_by_id with no result.
|
"""Test CompanyMongoService get_by_id with no result.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -73,10 +73,10 @@ def test_by_id_no_result(mock_mongo_connector, mock_collection):
|
|||||||
mock_mongo_connector.database = {"companies": mock_collection}
|
mock_mongo_connector.database = {"companies": mock_collection}
|
||||||
service = CompanyMongoService(mock_mongo_connector)
|
service = CompanyMongoService(mock_mongo_connector)
|
||||||
mock_collection.find.return_value = []
|
mock_collection.find.return_value = []
|
||||||
assert service.get_by_id("Does not exist") is None
|
assert service.get_by_id("Does not exist") is None # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_by_id_result(mock_mongo_connector, mock_collection):
|
def test_by_id_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||||
"""Test CompanyMongoService get_by_id with result.
|
"""Test CompanyMongoService get_by_id with result.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -87,10 +87,10 @@ def test_by_id_result(mock_mongo_connector, mock_collection):
|
|||||||
service = CompanyMongoService(mock_mongo_connector)
|
service = CompanyMongoService(mock_mongo_connector)
|
||||||
mock_entry = {"id": "Does exist", "vaue": 42}
|
mock_entry = {"id": "Does exist", "vaue": 42}
|
||||||
mock_collection.find.return_value = [mock_entry]
|
mock_collection.find.return_value = [mock_entry]
|
||||||
assert service.get_by_id("Does exist") == mock_entry
|
assert service.get_by_id("Does exist") == mock_entry # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_insert(mock_mongo_connector, mock_collection):
|
def test_insert(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||||
"""Test CompanyMongoService insert method.
|
"""Test CompanyMongoService insert method.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -101,4 +101,4 @@ def test_insert(mock_mongo_connector, mock_collection):
|
|||||||
service = CompanyMongoService(mock_mongo_connector)
|
service = CompanyMongoService(mock_mongo_connector)
|
||||||
mock_result = 42
|
mock_result = 42
|
||||||
mock_collection.insert_one.return_value = mock_result
|
mock_collection.insert_one.return_value = mock_result
|
||||||
assert service.insert(Company(None, None, "", "", [])) == mock_result
|
assert service.insert(Company(None, None, "", "", [])) == mock_result # type: ignore
|
||||||
|
@ -6,22 +6,22 @@ from aki_prj23_transparenzregister.utils.mongo.connector import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_get_conn_string_no_credentials():
|
def test_get_conn_string_no_credentials() -> None:
|
||||||
conn = MongoConnection("localhost", "", 27017, None, None)
|
conn = MongoConnection("localhost", "", 27017, None, None)
|
||||||
assert conn.get_conn_string() == "mongodb://localhost:27017"
|
assert conn.get_conn_string() == "mongodb://localhost:27017"
|
||||||
|
|
||||||
|
|
||||||
def test_get_conn_string_no_port_but_credentials():
|
def test_get_conn_string_no_port_but_credentials() -> None:
|
||||||
conn = MongoConnection("localhost", "", None, "admin", "password")
|
conn = MongoConnection("localhost", "", None, "admin", "password")
|
||||||
assert conn.get_conn_string() == "mongodb+srv://admin:password@localhost"
|
assert conn.get_conn_string() == "mongodb+srv://admin:password@localhost"
|
||||||
|
|
||||||
|
|
||||||
def test_get_conn_simple():
|
def test_get_conn_simple() -> None:
|
||||||
conn = MongoConnection("localhost", "", None, None, None)
|
conn = MongoConnection("localhost", "", None, None, None)
|
||||||
assert conn.get_conn_string() == "mongodb+srv://localhost"
|
assert conn.get_conn_string() == "mongodb+srv://localhost"
|
||||||
|
|
||||||
|
|
||||||
def test_mongo_connector():
|
def test_mongo_connector() -> None:
|
||||||
with patch("pymongo.MongoClient") as mock_mongo_client:
|
with patch("pymongo.MongoClient") as mock_mongo_client:
|
||||||
expected_result = 42
|
expected_result = 42
|
||||||
mock_mongo_client.return_value = {"db": expected_result}
|
mock_mongo_client.return_value = {"db": expected_result}
|
||||||
|
@ -10,7 +10,7 @@ from aki_prj23_transparenzregister.utils.mongo.news_mongo_service import (
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def mock_mongo_connector(mocker) -> Mock:
|
def mock_mongo_connector(mocker: Mock) -> Mock:
|
||||||
"""Mock MongoConnector class.
|
"""Mock MongoConnector class.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -37,7 +37,7 @@ def mock_collection() -> Mock:
|
|||||||
return Mock()
|
return Mock()
|
||||||
|
|
||||||
|
|
||||||
def test_init(mock_mongo_connector, mock_collection):
|
def test_init(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||||
"""Test CompanyMongoService constructor.
|
"""Test CompanyMongoService constructor.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -49,7 +49,7 @@ def test_init(mock_mongo_connector, mock_collection):
|
|||||||
assert service.collection == mock_collection
|
assert service.collection == mock_collection
|
||||||
|
|
||||||
|
|
||||||
def test_get_all(mock_mongo_connector, mock_collection):
|
def test_get_all(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||||
mock_mongo_connector.database = {"news": mock_collection}
|
mock_mongo_connector.database = {"news": mock_collection}
|
||||||
service = MongoNewsService(mock_mongo_connector)
|
service = MongoNewsService(mock_mongo_connector)
|
||||||
|
|
||||||
@ -57,7 +57,9 @@ def test_get_all(mock_mongo_connector, mock_collection):
|
|||||||
assert service.get_all() == []
|
assert service.get_all() == []
|
||||||
|
|
||||||
|
|
||||||
def test_get_by_id_with_result(mock_mongo_connector, mock_collection):
|
def test_get_by_id_with_result(
|
||||||
|
mock_mongo_connector: Mock, mock_collection: Mock
|
||||||
|
) -> None:
|
||||||
mock_mongo_connector.database = {"news": mock_collection}
|
mock_mongo_connector.database = {"news": mock_collection}
|
||||||
service = MongoNewsService(mock_mongo_connector)
|
service = MongoNewsService(mock_mongo_connector)
|
||||||
|
|
||||||
@ -69,7 +71,7 @@ def test_get_by_id_with_result(mock_mongo_connector, mock_collection):
|
|||||||
assert service.get_by_id("foadh") == {}
|
assert service.get_by_id("foadh") == {}
|
||||||
|
|
||||||
|
|
||||||
def test_get_by_id_no_result(mock_mongo_connector, mock_collection):
|
def test_get_by_id_no_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||||
mock_mongo_connector.database = {"news": mock_collection}
|
mock_mongo_connector.database = {"news": mock_collection}
|
||||||
service = MongoNewsService(mock_mongo_connector)
|
service = MongoNewsService(mock_mongo_connector)
|
||||||
|
|
||||||
@ -77,7 +79,7 @@ def test_get_by_id_no_result(mock_mongo_connector, mock_collection):
|
|||||||
assert service.get_by_id("foadh") is None
|
assert service.get_by_id("foadh") is None
|
||||||
|
|
||||||
|
|
||||||
def test_insert(mock_mongo_connector, mock_collection):
|
def test_insert(mock_mongo_connector: Mock, mock_collection: Mock) -> None:
|
||||||
mock_mongo_connector.database = {"news": mock_collection}
|
mock_mongo_connector.database = {"news": mock_collection}
|
||||||
service = MongoNewsService(mock_mongo_connector)
|
service = MongoNewsService(mock_mongo_connector)
|
||||||
|
|
||||||
@ -86,17 +88,17 @@ def test_insert(mock_mongo_connector, mock_collection):
|
|||||||
) as mock_in:
|
) as mock_in:
|
||||||
mock_collection.insert_one.return_value = {}
|
mock_collection.insert_one.return_value = {}
|
||||||
mock_in.return_value = {}
|
mock_in.return_value = {}
|
||||||
assert service.insert({}) == {}
|
assert service.insert({}) == {} # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_transform_ingoing():
|
def test_transform_ingoing() -> None:
|
||||||
news = News("42", None, None, None, None)
|
news = News("42", None, None, None, None) # type: ignore
|
||||||
result = MongoEntryTransformer.transform_ingoing(news)
|
result = MongoEntryTransformer.transform_ingoing(news)
|
||||||
assert result["_id"] == "42"
|
assert result["_id"] == "42"
|
||||||
assert "id" not in result
|
assert "id" not in result
|
||||||
|
|
||||||
|
|
||||||
def test_transform_outgoing():
|
def test_transform_outgoing() -> None:
|
||||||
data = {
|
data = {
|
||||||
"_id": "4711",
|
"_id": "4711",
|
||||||
"title": "Hello",
|
"title": "Hello",
|
||||||
|
@ -4,7 +4,7 @@ from aki_prj23_transparenzregister.config.config_template import PostgreConnecti
|
|||||||
from aki_prj23_transparenzregister.utils.postgres.connector import get_engine, init_db
|
from aki_prj23_transparenzregister.utils.postgres.connector import get_engine, init_db
|
||||||
|
|
||||||
|
|
||||||
def test_get_engine():
|
def test_get_engine() -> None:
|
||||||
conn_args = PostgreConnectionString("", "", "", "", 42)
|
conn_args = PostgreConnectionString("", "", "", "", 42)
|
||||||
with patch(
|
with patch(
|
||||||
"aki_prj23_transparenzregister.utils.postgres.connector.create_engine"
|
"aki_prj23_transparenzregister.utils.postgres.connector.create_engine"
|
||||||
@ -14,7 +14,7 @@ def test_get_engine():
|
|||||||
assert get_engine(conn_args) == result
|
assert get_engine(conn_args) == result
|
||||||
|
|
||||||
|
|
||||||
def test_init_db():
|
def test_init_db() -> None:
|
||||||
with patch(
|
with patch(
|
||||||
"aki_prj23_transparenzregister.utils.postgres.connector.get_engine"
|
"aki_prj23_transparenzregister.utils.postgres.connector.get_engine"
|
||||||
) as mock_get_engine, patch(
|
) as mock_get_engine, patch(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
def test_import():
|
def test_import() -> None:
|
||||||
from aki_prj23_transparenzregister.utils.postgres import entities
|
from aki_prj23_transparenzregister.utils.postgres import entities
|
||||||
|
|
||||||
assert entities is not None
|
assert entities is not None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user