-
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.
Move Data Warehouse files to a separate folder. Refactor.
- Loading branch information
Dawid Makar
committed
Mar 13, 2024
1 parent
84e9a8e
commit a39df4c
Showing
9 changed files
with
79 additions
and
86 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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pyprediktorutilities import singleton | ||
from pyprediktorutilities.dwh import dwh | ||
|
||
|
||
class DwhSingleton(dwh.Dwh, metaclass=singleton.SingletonMeta): | ||
pass |
File renamed without changes.
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,25 @@ | ||
import random | ||
import string | ||
|
||
import pyodbc | ||
|
||
|
||
class mock_pyodbc_connection: | ||
def __init__(self, connection_string): | ||
pass | ||
|
||
def cursor(self): | ||
return | ||
|
||
|
||
def mock_pyodbc_connection_throws_error_not_tolerant_to_attempts(connection_string): | ||
raise pyodbc.DataError("Error code", "Error message") | ||
|
||
|
||
def mock_pyodbc_connection_throws_error_tolerant_to_attempts(connection_string): | ||
raise pyodbc.DatabaseError("Error code", "Error message") | ||
|
||
|
||
def grs(): | ||
"""Generate a random string.""" | ||
return "".join(random.choices(string.ascii_uppercase + string.digits, k=10)) |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from helpers import grs, mock_pyodbc_connection | ||
from pyprediktorutilities.dwh import dwh_singleton | ||
|
||
|
||
def test_dwh_singleton_can_be_created_only_once(monkeypatch): | ||
driver_index = 0 | ||
|
||
# Mock the database connection | ||
monkeypatch.setattr( | ||
"pyprediktorutilities.dwh.dwh.pyodbc.connect", mock_pyodbc_connection | ||
) | ||
|
||
db = dwh_singleton.DwhSingleton(grs(), grs(), grs(), grs(), driver_index) | ||
db_instance_address = id(db) | ||
|
||
db_2 = dwh_singleton.DwhSingleton(grs(), grs(), grs(), grs(), driver_index) | ||
db_2_instance_address = id(db_2) | ||
|
||
assert db_instance_address == db_2_instance_address |
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