Skip to content

Commit 8fd2e3c

Browse files
Akash VermaAkash Verma
authored andcommitted
Fixed tests for new changes
1 parent 863e65e commit 8fd2e3c

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

ingestion/tests/unit/topology/database/test_burstiq_client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def setUp(self):
3131
username="test_user",
3232
password="test_password",
3333
realmName="test_realm",
34+
biqSdzName="test_sdz",
35+
biqCustomerName="test_customer",
3436
)
3537

3638
# Mock authentication response
@@ -49,6 +51,8 @@ def test_authentication_success(self, mock_post):
4951
mock_post.return_value = mock_response
5052

5153
client = BurstIQClient(self.config)
54+
# Trigger authentication explicitly
55+
client.test_authenticate()
5256

5357
# Verify authentication was called correctly
5458
self.assertEqual(mock_post.call_count, 1)
@@ -70,8 +74,6 @@ def test_authentication_success(self, mock_post):
7074
# Verify token is set
7175
self.assertIsNotNone(client.access_token)
7276
self.assertIsNotNone(client.token_expires_at)
73-
self.assertEqual(client.customer_name, "test_realm")
74-
self.assertEqual(client.sdz_name, "test_sdz")
7577

7678
@patch("metadata.ingestion.source.database.burstiq.client.requests.post")
7779
def test_authentication_failure(self, mock_post):
@@ -80,8 +82,9 @@ def test_authentication_failure(self, mock_post):
8082
mock_response.raise_for_status.side_effect = Exception("401 Unauthorized")
8183
mock_post.return_value = mock_response
8284

85+
client = BurstIQClient(self.config)
8386
with self.assertRaises(Exception) as context:
84-
BurstIQClient(self.config)
87+
client.test_authenticate()
8588

8689
self.assertIn("Failed to authenticate with BurstIQ", str(context.exception))
8790

@@ -247,6 +250,9 @@ def test_token_refresh(self, mock_request, mock_datetime, mock_post):
247250

248251
client = BurstIQClient(self.config)
249252

253+
# Trigger initial authentication
254+
client.test_authenticate()
255+
250256
# Manually set token to expired
251257
client.token_expires_at = mock_now - timedelta(seconds=1)
252258

@@ -345,6 +351,8 @@ def test_custom_auth_server_url(self, mock_post):
345351
username="test_user",
346352
password="test_password",
347353
realmName="custom_realm",
354+
biqSdzName="custom_sdz",
355+
biqCustomerName="custom_customer",
348356
)
349357

350358
mock_response = Mock()
@@ -353,6 +361,8 @@ def test_custom_auth_server_url(self, mock_post):
353361
mock_post.return_value = mock_response
354362

355363
client = BurstIQClient(custom_config)
364+
# Trigger authentication
365+
client.test_authenticate()
356366

357367
# Verify custom auth server URL was used
358368
call_args = mock_post.call_args

ingestion/tests/unit/topology/database/test_burstiq_connection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def setUp(self):
3030
username="test_user",
3131
password="test_password",
3232
realmName="test_realm",
33+
biqSdzName="test_sdz",
34+
biqCustomerName="test_customer",
3335
)
3436

3537
self.mock_token_response = {
@@ -49,8 +51,8 @@ def test_get_connection(self, mock_post):
4951

5052
# Verify client was created
5153
self.assertIsNotNone(client)
52-
self.assertEqual(client.username, "test_user")
53-
self.assertEqual(client.realm_name, "test_realm")
54+
self.assertEqual(client.config.username, "test_user")
55+
self.assertEqual(client.config.realmName, "test_realm")
5456

5557
@patch("metadata.ingestion.source.database.burstiq.client.requests.post")
5658
@patch("metadata.ingestion.source.database.burstiq.client.requests.request")
@@ -197,8 +199,9 @@ def test_connection_invalid_credentials(self, mock_post):
197199
mock_response.raise_for_status.side_effect = Exception("401 Unauthorized")
198200
mock_post.return_value = mock_response
199201

200-
# Should raise exception
202+
# Should raise exception when authentication is attempted
203+
client = get_connection(self.config)
201204
with self.assertRaises(Exception) as context:
202-
get_connection(self.config)
205+
client.test_authenticate()
203206

204207
self.assertIn("Failed to authenticate", str(context.exception))

ingestion/tests/unit/topology/database/test_burstiq_lineage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def test_lineage_source_initialization(self, mock_post):
6767
"username": "test_user",
6868
"password": "test_password",
6969
"realmName": "test_realm",
70+
"biqSdzName": "test_sdz",
71+
"biqCustomerName": "test_customer",
7072
}
7173
},
7274
"sourceConfig": {"config": {"type": "DatabaseLineage"}},
@@ -118,6 +120,8 @@ def test_get_table_entity_not_found(self, mock_post):
118120
"username": "test_user",
119121
"password": "test_password",
120122
"realmName": "test_realm",
123+
"biqSdzName": "test_sdz",
124+
"biqCustomerName": "test_customer",
121125
}
122126
},
123127
"sourceConfig": {"config": {"type": "DatabaseLineage"}},
@@ -158,6 +162,8 @@ def test_process_edge_missing_tables(self, mock_post):
158162
"username": "test_user",
159163
"password": "test_password",
160164
"realmName": "test_realm",
165+
"biqSdzName": "test_sdz",
166+
"biqCustomerName": "test_customer",
161167
}
162168
},
163169
"sourceConfig": {"config": {"type": "DatabaseLineage"}},
@@ -208,6 +214,8 @@ def test_lineage_iteration_success(self, mock_request, mock_post):
208214
"username": "test_user",
209215
"password": "test_password",
210216
"realmName": "test_realm",
217+
"biqSdzName": "test_sdz",
218+
"biqCustomerName": "test_customer",
211219
}
212220
},
213221
"sourceConfig": {"config": {"type": "DatabaseLineage"}},
@@ -252,6 +260,8 @@ def test_lineage_iteration_error_handling(self, mock_request, mock_post):
252260
"username": "test_user",
253261
"password": "test_password",
254262
"realmName": "test_realm",
263+
"biqSdzName": "test_sdz",
264+
"biqCustomerName": "test_customer",
255265
}
256266
},
257267
"sourceConfig": {"config": {"type": "DatabaseLineage"}},

ingestion/tests/unit/topology/database/test_burstiq_metadata.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def setUp(self):
3535
username="test_user",
3636
password="test_password",
3737
realmName="test_realm",
38+
biqSdzName="test_sdz",
39+
biqCustomerName="test_customer",
3840
)
3941

4042
# Sample dictionary data
@@ -272,13 +274,23 @@ def test_table_constraints_unique(self):
272274

273275
def test_table_constraints_foreign_key(self):
274276
"""Test extraction of foreign key constraints from referenced dictionaries"""
277+
from unittest.mock import patch
275278
from metadata.ingestion.source.database.burstiq.metadata import Burstiqsource
276279

277280
source = Mock(spec=Burstiqsource)
278281
source.get_table_constraints = Burstiqsource.get_table_constraints.__get__(
279282
source
280283
)
281284

285+
# Mock metadata and context for FQN building
286+
source.metadata = Mock()
287+
source.context = Mock()
288+
context_data = Mock()
289+
context_data.database_service = "test_service"
290+
context_data.database = "test_db"
291+
context_data.database_schema = "test_schema"
292+
source.context.get.return_value = context_data
293+
282294
# Create dictionary with foreign key reference
283295
dictionary = BurstIQDictionary(
284296
name="visit",
@@ -292,14 +304,21 @@ def test_table_constraints_foreign_key(self):
292304
indexes=[],
293305
)
294306

295-
# Get constraints
296-
constraints = source.get_table_constraints(dictionary)
297-
298-
# Verify foreign key constraint
299-
self.assertIsNotNone(constraints)
300-
self.assertEqual(len(constraints), 1)
301-
self.assertEqual(constraints[0].constraintType, ConstraintType.FOREIGN_KEY)
302-
self.assertEqual(constraints[0].columns, ["patient_id"])
307+
# Mock fqn.build to return a test FQN
308+
with patch('metadata.ingestion.source.database.burstiq.metadata.fqn.build') as mock_fqn_build:
309+
mock_fqn_build.return_value = "test_service.test_db.test_schema.patient.patient_id"
310+
311+
# Get constraints
312+
constraints = source.get_table_constraints(dictionary)
313+
314+
# Verify foreign key constraint
315+
self.assertIsNotNone(constraints)
316+
self.assertEqual(len(constraints), 1)
317+
self.assertEqual(constraints[0].constraintType, ConstraintType.FOREIGN_KEY)
318+
self.assertEqual(constraints[0].columns, ["patient_id"])
319+
# Verify the FQN was built and used (it's wrapped in FullyQualifiedEntityName)
320+
self.assertEqual(len(constraints[0].referredColumns), 1)
321+
self.assertEqual(constraints[0].referredColumns[0].root, "test_service.test_db.test_schema.patient.patient_id")
303322

304323
def test_table_name_extraction(self):
305324
"""Test table name and type extraction from dictionaries"""

0 commit comments

Comments
 (0)