using connect_with_credentials to run test
import pymssql
import pytest
-from sqlalchemy import create_engine
+from pymedphys._imports import sqlalchemy
import pandas as pd
@@ -16,12 +16,6 @@ def test_mock_patient_table():
sa_user = "sa"
sa_password = "sqlServerPassw0rd"
- # save the generated user / password
- storage_name = msq_connect.get_storage_name(msq_server, database=test_db_name)
- print(storage_name)
- msq_connect.save_username(storage_name, sa_user)
- msq_connect.save_password(storage_name, sa_password)
-
conn = pymssql.connect(msq_server, user=sa_user, password=sa_password)
conn.autocommit(True)
cursor = conn.cursor()
@@ -31,12 +25,17 @@ def test_mock_patient_table():
patient_df.index = patient_df.index + 10001 # use the index+10001 as the Pat_ID1
conn_str = f"mssql+pymssql://{sa_user}:{sa_password}@{msq_server}/{test_db_name}"
- engine = create_engine(conn_str, echo=False)
+ engine = sqlalchemy.create_engine(conn_str, echo=False)
patient_df.to_sql(
"Patient", engine, if_exists="replace", index=True, index_label="Pat_Id1"
)
- with mosaiq.connect(msq_server, database=test_db_name) as cursor:
+ connection = msq_connect.connect_with_credential(
+ sa_user, sa_password, msq_server, port=1433, database=test_db_name
+ )
+
+ cursor = connection.cursor()
+
result_all = mosaiq.execute(
cursor,
"""
@@ -68,3 +67,5 @@ def test_mock_patient_table():
assert len(result_moe) == 1
assert result_moe[0][0] == 10002
assert result_moe[0][1] == "Moe"
+
+ cursor.close()
