This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QPT-36798: Create is db available util function (#12)
* function plus unit tests * pre-commit * Version bumped to 0.13.0 Co-authored-by: ns-circle-ci <[email protected]>
- Loading branch information
1 parent
c556398
commit 9f2cb8a
Showing
4 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"""Lightweight ORM that lets you query your database using Pydantic models and asyncio""" | ||
|
||
__version__ = "0.12.0" | ||
__version__ = "0.13.0" | ||
|
||
from pynocular.engines import DatabaseType, DBInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "pynocular" | ||
version = "0.12.0" | ||
version = "0.13.0" | ||
description = "Lightweight ORM that lets you query your database using Pydantic models and asyncio" | ||
authors = [ | ||
"RJ Santana <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Tests for the db_util module""" | ||
import os | ||
|
||
import pytest | ||
|
||
from pynocular.db_util import is_database_available | ||
from pynocular.engines import DatabaseType, DBInfo | ||
|
||
db_user_password = str(os.environ.get("DB_USER_PASSWORD")) | ||
test_db_name = str(os.environ.get("TEST_DB_NAME", "test_db")) | ||
test_connection_string = str( | ||
os.environ.get( | ||
"TEST_DB_CONNECTION_STRING", | ||
f"postgresql://postgres:{db_user_password}@localhost:5432/{test_db_name}?sslmode=disable", | ||
) | ||
) | ||
test_db = DBInfo(DatabaseType.aiopg_engine, test_connection_string) | ||
|
||
|
||
class TestDBUtil: | ||
"""Test cases for DB util functions""" | ||
|
||
@pytest.mark.asyncio | ||
async def test_is_database_available(self) -> None: | ||
"""Test successful database connection""" | ||
available = await is_database_available(test_db) | ||
assert available is True | ||
|
||
@pytest.mark.asyncio | ||
async def test_is_database_not_available(self) -> None: | ||
"""Test db connection unavailable""" | ||
invalid_connection_string = f"postgresql://postgres:{db_user_password}@localhost:5432/INVALID?sslmode=disable" | ||
non_existing_db = DBInfo(DatabaseType.aiopg_engine, invalid_connection_string) | ||
available = await is_database_available(non_existing_db) | ||
assert available is False |