|
23 | 23 |
|
24 | 24 | # Finally import application modules |
25 | 25 | from idp_common.assessment.service import AssessmentService |
| 26 | +from idp_common.config.models import IDPConfig |
26 | 27 | from idp_common.models import Document, Section, Status, Page |
27 | 28 |
|
28 | 29 |
|
@@ -482,3 +483,45 @@ def test_process_document_section_empty_extraction_results( |
482 | 483 | # Should return without error but log warning |
483 | 484 | assert len(result.errors) == 0 |
484 | 485 | mock_get_json_content.assert_called_once() |
| 486 | + |
| 487 | + def test_init_with_none_config(self): |
| 488 | + """Test initialization with None config creates default IDPConfig.""" |
| 489 | + service = AssessmentService(region="us-east-1", config=None) |
| 490 | + |
| 491 | + assert service.region == "us-east-1" |
| 492 | + assert isinstance(service.config, IDPConfig) |
| 493 | + # Verify default config has assessment settings |
| 494 | + assert hasattr(service.config, "assessment") |
| 495 | + |
| 496 | + def test_init_with_dict_config(self, mock_config): |
| 497 | + """Test initialization with dict config converts to IDPConfig.""" |
| 498 | + service = AssessmentService(region="us-east-1", config=mock_config) |
| 499 | + |
| 500 | + assert service.region == "us-east-1" |
| 501 | + assert isinstance(service.config, IDPConfig) |
| 502 | + # Verify config was properly converted |
| 503 | + assert service.config.assessment.model == mock_config["assessment"]["model"] |
| 504 | + |
| 505 | + def test_init_with_idpconfig_instance(self, mock_config): |
| 506 | + """Test initialization with IDPConfig instance (the previously failing case).""" |
| 507 | + # Create an IDPConfig instance first |
| 508 | + config_instance = IDPConfig(**mock_config) |
| 509 | + |
| 510 | + # Initialize service with IDPConfig instance |
| 511 | + service = AssessmentService(region="us-east-1", config=config_instance) |
| 512 | + |
| 513 | + assert service.region == "us-east-1" |
| 514 | + assert isinstance(service.config, IDPConfig) |
| 515 | + # Should use the same instance |
| 516 | + assert service.config is config_instance |
| 517 | + # Verify config properties are accessible |
| 518 | + assert service.config.assessment.model == mock_config["assessment"]["model"] |
| 519 | + |
| 520 | + def test_init_with_invalid_config_type(self): |
| 521 | + """Test initialization with invalid config type raises ValueError.""" |
| 522 | + # Try to initialize with an invalid config type (e.g., a string) |
| 523 | + with pytest.raises(ValueError) as exc_info: |
| 524 | + AssessmentService(region="us-east-1", config="invalid_config") |
| 525 | + |
| 526 | + # Verify error message mentions the invalid type |
| 527 | + assert "Invalid config type" in str(exc_info.value) |
0 commit comments