|
1 | 1 | """test config classes.""" |
2 | 2 |
|
| 3 | +import logging |
| 4 | + |
3 | 5 | import pytest |
4 | 6 | from pydantic import ValidationError |
5 | 7 |
|
@@ -27,3 +29,43 @@ def test_incompatible_options(): |
27 | 29 | enable_response_models=True, |
28 | 30 | enable_direct_response=True, |
29 | 31 | ) |
| 32 | + |
| 33 | + |
| 34 | +def test_default_values_warning(caplog): |
| 35 | + """test that a warning is logged when using default values.""" |
| 36 | + with caplog.at_level(logging.WARNING): |
| 37 | + ApiSettings() |
| 38 | + |
| 39 | + assert "Using default values for" in caplog.text |
| 40 | + assert "stac_fastapi_title" in caplog.text |
| 41 | + assert "stac_fastapi_description" in caplog.text |
| 42 | + assert "stac_fastapi_landing_id" in caplog.text |
| 43 | + assert "stac_fastapi_version" in caplog.text |
| 44 | + |
| 45 | + |
| 46 | +def test_custom_values_no_warning(caplog): |
| 47 | + """test that no warning is logged when using custom values.""" |
| 48 | + with caplog.at_level(logging.WARNING): |
| 49 | + ApiSettings( |
| 50 | + stac_fastapi_title="My API", |
| 51 | + stac_fastapi_description="My API Description", |
| 52 | + stac_fastapi_landing_id="my-api", |
| 53 | + stac_fastapi_version="1.0.0", |
| 54 | + ) |
| 55 | + |
| 56 | + assert "Using default values for" not in caplog.text |
| 57 | + |
| 58 | + |
| 59 | +def test_partial_custom_values_warning(caplog): |
| 60 | + """test that a warning is logged only for remaining default values.""" |
| 61 | + with caplog.at_level(logging.WARNING): |
| 62 | + ApiSettings( |
| 63 | + stac_fastapi_title="My API", |
| 64 | + stac_fastapi_description="My API Description", |
| 65 | + ) |
| 66 | + |
| 67 | + assert "Using default values for" in caplog.text |
| 68 | + assert "stac_fastapi_landing_id" in caplog.text |
| 69 | + assert "stac_fastapi_version" in caplog.text |
| 70 | + assert "stac_fastapi_title" not in caplog.text |
| 71 | + assert "stac_fastapi_description" not in caplog.text |
0 commit comments