Skip to content

Commit

Permalink
unit test for instructions_records_to_db
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Maranan committed Jan 11, 2024
1 parent 01ac3a0 commit 5406faf
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_digitaltwin/data/test_data_to_db.py
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()

0 comments on commit 5406faf

Please sign in to comment.