|
5 | 5 | from openstack import exceptions |
6 | 6 |
|
7 | 7 | from openstack_mcp_server.tools.identity_tools import IdentityTools |
8 | | -from openstack_mcp_server.tools.response.identity import Region, Domain |
| 8 | +from openstack_mcp_server.tools.response.identity import Domain, Region |
9 | 9 |
|
10 | 10 |
|
11 | 11 | class TestIdentityTools: |
@@ -428,3 +428,121 @@ def test_get_domain_not_found(self, mock_get_openstack_conn_identity): |
428 | 428 |
|
429 | 429 | # Verify mock calls |
430 | 430 | mock_conn.identity.get_domain.assert_called_once_with(domain="domainone") |
| 431 | + |
| 432 | + def test_create_domain_success(self, mock_get_openstack_conn_identity): |
| 433 | + """Test creating a identity domain successfully.""" |
| 434 | + mock_conn = mock_get_openstack_conn_identity |
| 435 | + |
| 436 | + # Create mock domain object |
| 437 | + mock_domain = Mock() |
| 438 | + mock_domain.id = "domainone" |
| 439 | + mock_domain.name = "DomainOne" |
| 440 | + mock_domain.description = "Domain One description" |
| 441 | + mock_domain.is_enabled = False |
| 442 | + |
| 443 | + # Configure mock domain.create_domain() |
| 444 | + mock_conn.identity.create_domain.return_value = mock_domain |
| 445 | + |
| 446 | + # Test create_domain() |
| 447 | + identity_tools = self.get_identity_tools() |
| 448 | + result = identity_tools.create_domain(id="domainone", name="DomainOne", description="Domain One description", is_enabled=False) |
| 449 | + |
| 450 | + # Verify results |
| 451 | + assert result == Domain(id="domainone", name="DomainOne", description="Domain One description", is_enabled=False) |
| 452 | + |
| 453 | + # Verify mock calls |
| 454 | + mock_conn.identity.create_domain.assert_called_once_with(id="domainone", name="DomainOne", description="Domain One description", is_enabled=False) |
| 455 | + |
| 456 | + |
| 457 | + def test_create_domain_with_empty_id(self, mock_get_openstack_conn_identity): |
| 458 | + """Test creating a identity domain with an empty ID.""" |
| 459 | + mock_conn = mock_get_openstack_conn_identity |
| 460 | + |
| 461 | + # Create mock domain object |
| 462 | + mock_domain = Mock() |
| 463 | + mock_domain.id = "" |
| 464 | + mock_domain.name = "DomainOne" |
| 465 | + mock_domain.description = "Domain One description" |
| 466 | + mock_domain.is_enabled = False |
| 467 | + |
| 468 | + # Configure mock domain.create_domain() |
| 469 | + mock_conn.identity.create_domain.return_value = mock_domain |
| 470 | + |
| 471 | + # If id is empty, the id will be generated by the server |
| 472 | + temp_id = "abcdefghijklmnopqrs12345" |
| 473 | + mock_domain.id = temp_id |
| 474 | + |
| 475 | + # Test create_domain() |
| 476 | + identity_tools = self.get_identity_tools() |
| 477 | + result = identity_tools.create_domain(id="", name="DomainOne", description="Domain One description", is_enabled=False) |
| 478 | + |
| 479 | + # Verify results |
| 480 | + assert result == Domain(id=temp_id, name="DomainOne", description="Domain One description", is_enabled=False) |
| 481 | + |
| 482 | + def test_create_domain_with_empty_name(self, mock_get_openstack_conn_identity): |
| 483 | + """Test creating a identity domain with an empty name.""" |
| 484 | + mock_conn = mock_get_openstack_conn_identity |
| 485 | + |
| 486 | + # Create mock domain object |
| 487 | + mock_domain = Mock() |
| 488 | + mock_domain.id = "domainone" |
| 489 | + mock_domain.name = "" |
| 490 | + mock_domain.description = "Domain One description" |
| 491 | + mock_domain.is_enabled = False |
| 492 | + |
| 493 | + # Configure mock domain.create_domain() |
| 494 | + mock_conn.identity.create_domain.return_value = mock_domain |
| 495 | + |
| 496 | + # Test create_domain() |
| 497 | + identity_tools = self.get_identity_tools() |
| 498 | + result = identity_tools.create_domain(id="domainone", name="", description="Domain One description", is_enabled=False) |
| 499 | + |
| 500 | + # Verify results |
| 501 | + assert result == Domain(id="domainone", name="", description="Domain One description", is_enabled=False) |
| 502 | + |
| 503 | + def test_create_domain_with_empty_description(self, mock_get_openstack_conn_identity): |
| 504 | + """Test creating a identity domain with an empty description.""" |
| 505 | + mock_conn = mock_get_openstack_conn_identity |
| 506 | + |
| 507 | + # Create mock domain object |
| 508 | + mock_domain = Mock() |
| 509 | + mock_domain.id = "domainone" |
| 510 | + mock_domain.name = "DomainOne" |
| 511 | + mock_domain.description = "" |
| 512 | + mock_domain.is_enabled = False |
| 513 | + |
| 514 | + # Configure mock domain.create_domain() |
| 515 | + mock_conn.identity.create_domain.return_value = mock_domain |
| 516 | + |
| 517 | + # Test create_domain() |
| 518 | + identity_tools = self.get_identity_tools() |
| 519 | + result = identity_tools.create_domain(id="domainone", name="DomainOne", description="", is_enabled=False) |
| 520 | + |
| 521 | + # Verify results |
| 522 | + assert result == Domain(id="domainone", name="DomainOne", description="", is_enabled=False) |
| 523 | + |
| 524 | + def test_create_domain_with_empty_is_enabled(self, mock_get_openstack_conn_identity): |
| 525 | + """Test creating a identity domain with an empty is_enabled.""" |
| 526 | + mock_conn = mock_get_openstack_conn_identity |
| 527 | + |
| 528 | + # Create mock domain object |
| 529 | + mock_domain = Mock() |
| 530 | + mock_domain.id = "domainone" |
| 531 | + mock_domain.name = "DomainOne" |
| 532 | + mock_domain.description = "Domain One description" |
| 533 | + mock_domain.is_enabled = False |
| 534 | + |
| 535 | + # Configure mock domain.create_domain() |
| 536 | + mock_conn.identity.create_domain.return_value = mock_domain |
| 537 | + |
| 538 | + # Test create_domain() |
| 539 | + identity_tools = self.get_identity_tools() |
| 540 | + result = identity_tools.create_domain(id="domainone", name="DomainOne", description="Domain One description") |
| 541 | + |
| 542 | + # Verify results |
| 543 | + assert result == Domain(id="domainone", name="DomainOne", description="Domain One description", is_enabled=False) |
| 544 | + |
| 545 | + # Verify mock calls |
| 546 | + mock_conn.identity.create_domain.assert_called_once_with(id="domainone", name="DomainOne", description="Domain One description", is_enabled=False) |
| 547 | + |
| 548 | + |
0 commit comments