""" Comprehensive unit tests for Test Suite entity. """ import unittest from unittest.mock import MagicMock from uuid import UUID from metadata.generated.schema.api.tests.createTestSuite import CreateTestSuiteRequest from metadata.generated.schema.entity.tests.testSuite import TestSuite as TestSuiteEntity from metadata.sdk.entities.testsuite import TestSuite class TestTestSuiteEntity(unittest.TestCase): """Comprehensive tests for TestSuite entity operations""" def setUp(self): """Set up test fixtures""" self.mock_ometa = MagicMock() TestSuite._default_client = self.mock_ometa self.entity_id = "550e8400-e29b-41d4-a716-446655440000" self.entity_fqn = "service.test_suite.test_test_suite" def test_create_test_suite(self): """Test creating a test suite""" create_request = MagicMock(spec=CreateTestSuiteRequest) create_request.name = "test_test_suite" create_request.displayName = "Test Test Suite" create_request.description = "Test test suite for unit tests" expected_entity = MagicMock(spec=TestSuiteEntity) expected_entity.id = UUID(self.entity_id) expected_entity.name = "test_test_suite" self.mock_ometa.create_or_update.return_value = expected_entity result = TestSuite.create(create_request) self.assertEqual(str(result.id), self.entity_id) self.assertEqual(result.name, "test_test_suite") self.mock_ometa.create_or_update.assert_called_once_with(create_request) def test_retrieve_test_suite_by_id(self): """Test retrieving a test suite by ID""" expected_entity = MagicMock(spec=TestSuiteEntity) expected_entity.id = UUID(self.entity_id) expected_entity.name = "test_test_suite" self.mock_ometa.get_by_id.return_value = expected_entity result = TestSuite.retrieve(self.entity_id) self.assertEqual(str(result.id), self.entity_id) self.mock_ometa.get_by_id.assert_called_once_with( entity=TestSuiteEntity, entity_id=self.entity_id, fields=None ) def test_retrieve_test_suite_by_name(self): """Test retrieving a test suite by name""" expected_entity = MagicMock(spec=TestSuiteEntity) expected_entity.fullyQualifiedName = self.entity_fqn self.mock_ometa.get_by_name.return_value = expected_entity result = TestSuite.retrieve_by_name(self.entity_fqn) self.assertEqual(result.fullyQualifiedName, self.entity_fqn) self.mock_ometa.get_by_name.assert_called_once_with( entity=TestSuiteEntity, fqn=self.entity_fqn, fields=None ) def test_update_test_suite(self): """Test updating a test suite""" entity_to_update = MagicMock(spec=TestSuiteEntity) entity_to_update.id = UUID(self.entity_id) entity_to_update.description = "Updated description" self.mock_ometa.create_or_update.return_value = entity_to_update result = TestSuite.update(self.entity_id, entity_to_update) self.assertEqual(result.description, "Updated description") self.mock_ometa.create_or_update.assert_called_once_with(entity_to_update) def test_patch_test_suite(self): """Test patching a test suite""" json_patch = [ {"op": "add", "path": "/description", "value": "Patched description"}, {"op": "add", "path": "/tags/0", "value": {"tagFQN": "Important.High"}}, ] patched_entity = MagicMock(spec=TestSuiteEntity) patched_entity.id = UUID(self.entity_id) patched_entity.description = "Patched description" self.mock_ometa.patch.return_value = patched_entity result = TestSuite.patch(self.entity_id, json_patch) self.assertEqual(result.description, "Patched description") self.mock_ometa.patch.assert_called_once_with( entity=TestSuiteEntity, entity_id=self.entity_id, json_patch=json_patch ) def test_delete_test_suite(self): """Test deleting a test suite""" TestSuite.delete(self.entity_id, recursive=True, hard_delete=False) self.mock_ometa.delete.assert_called_once_with( entity=TestSuiteEntity, entity_id=self.entity_id, recursive=True, hard_delete=False, ) def test_list_test_suites(self): """Test listing test suites""" mock_entity1 = MagicMock(spec=TestSuiteEntity) mock_entity1.name = "entity1" mock_entity2 = MagicMock(spec=TestSuiteEntity) mock_entity2.name = "entity2" mock_response = MagicMock() mock_response.entities = [mock_entity1, mock_entity2] self.mock_ometa.list_entities.return_value = mock_response result = TestSuite.list(limit=10) self.assertEqual(len(result), 2) self.assertEqual(result[0].name, "entity1") self.mock_ometa.list_entities.assert_called_once() if __name__ == "__main__": unittest.main()