Hi I have a method on my main.py which basically receives a dataframe and connection string, I am sending this dataframe to sql database on PostgreSQL.
def connect_with_postgres(df_table,sql_conn):
db = create_engine(sql_conn)
conn=db.connect()
#build a table and put the dataframe information into
df_table.to_sql('table_name', con=conn, if_exists='replace', schema='schemaname', index=False)
conn.close()
print("The data has been stored into the database.")
Then on my unit test I am taking a csv with a sample of data and put it into variable on my mocks.py
with open('mocks/table.csv', 'r') as file:
mock_table_csv = file.read()
file.close()
And last one my unit test function:
def test_connect_with_postgres(self):
conn_result = Mock()
mock_conn.connect.return_value = conn_result
mock_table = pd.read_csv(StringIO(mock_table_csv))
output = connect_with_postgres(mock_table,conn)
But is trying to get a real connection string, shows me this
TypeError: cannot unpack non-iterable Mock object
If I send a real conn string it works but the idea is to mock the connection string (fake one) and test that the function works, any idea how to make this happend?
Regards