forked from GeospatialResearch/Digital-Twins
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit test for instructions_records_to_db
- Loading branch information
Julian Maranan
committed
Jan 11, 2024
1 parent
01ac3a0
commit 5406faf
Showing
1 changed file
with
36 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import unittest | ||
from unittest.mock import MagicMock, patch | ||
import pandas as pd | ||
|
||
from src.digitaltwin.setup_environment import get_database | ||
from src.digitaltwin.data_to_db import get_nz_geospatial_layers | ||
|
||
class TestDataToDB(unittest.TestCase): | ||
@classmethod | ||
@patch("src.digitaltwin.setup_environment.get_connection_from_profile", autospec=True) | ||
def setUpClass(cls, mock_get_connection): | ||
# Set up a mock database engine | ||
mock_engine = MagicMock() | ||
|
||
# Mock the SQL query result | ||
mock_query_result = pd.DataFrame({ | ||
'column1': [1, 2, 3], | ||
'column2': ['A', 'B', 'C'] | ||
# Add more columns as needed | ||
}) | ||
|
||
# Configure the mock engine to return the query result | ||
mock_engine.execute.return_value.fetchall.return_value = mock_query_result.values | ||
|
||
# Mock the database connection setup function | ||
mock_get_connection.return_value = mock_engine | ||
|
||
# Call the function with the mock engine | ||
cls.dataframe_output = get_nz_geospatial_layers(mock_engine) | ||
|
||
def test_get_nz_geospatial_layers_correct_frame_type(self): | ||
"""Test to ensure tabular data is returned in DataFrame format.""" | ||
self.assertIsInstance(self.dataframe_output, pd.DataFrame) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |