|
| 1 | +import tempfile |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +from powerdns_api_proxy.config import load_config |
| 5 | + |
| 6 | + |
| 7 | +def test_index_html_from_yaml_single_line(): |
| 8 | + config_content = """ |
| 9 | +pdns_api_url: "https://test.example.com" |
| 10 | +pdns_api_token: "testtoken123" |
| 11 | +index_html: "<html><body><h1>PowerDNS API Proxy</h1></body></html>" |
| 12 | +environments: |
| 13 | + - name: "Test" |
| 14 | + token_sha512: "127aab81f4caab9c00e72f26e4c5c4b20146201a1548a787494d999febf1b9422c1711932117f38d9be9efe46f78aa72d8f6a391101bedd6e200014f6738450d" |
| 15 | + zones: |
| 16 | + - name: "example.com" |
| 17 | +""" |
| 18 | + with tempfile.NamedTemporaryFile(mode="w", suffix=".yml") as f: |
| 19 | + f.write(config_content) |
| 20 | + f.flush() |
| 21 | + |
| 22 | + config_path = Path(f.name) |
| 23 | + config = load_config(config_path) |
| 24 | + assert ( |
| 25 | + config.index_html == "<html><body><h1>PowerDNS API Proxy</h1></body></html>" |
| 26 | + ) |
| 27 | + assert config.index_enabled is True |
| 28 | + |
| 29 | + |
| 30 | +def test_index_html_from_yaml_multiline(): |
| 31 | + config_content = """ |
| 32 | +pdns_api_url: "https://test.example.com" |
| 33 | +pdns_api_token: "testtoken123" |
| 34 | +index_html: | |
| 35 | + <html> |
| 36 | + <body> |
| 37 | + <h1>Custom Page</h1> |
| 38 | + </body> |
| 39 | + </html> |
| 40 | +environments: |
| 41 | + - name: "Test" |
| 42 | + token_sha512: "127aab81f4caab9c00e72f26e4c5c4b20146201a1548a787494d999febf1b9422c1711932117f38d9be9efe46f78aa72d8f6a391101bedd6e200014f6738450d" |
| 43 | + zones: |
| 44 | + - name: "example.com" |
| 45 | +""" |
| 46 | + with tempfile.NamedTemporaryFile(mode="w", suffix=".yml") as f: |
| 47 | + f.write(config_content) |
| 48 | + f.flush() |
| 49 | + |
| 50 | + config_path = Path(f.name) |
| 51 | + config = load_config(config_path) |
| 52 | + assert "<h1>Custom Page</h1>" in config.index_html |
| 53 | + assert config.index_enabled is True |
| 54 | + |
| 55 | + |
| 56 | +def test_index_disabled_from_yaml(): |
| 57 | + config_content = """ |
| 58 | +pdns_api_url: "https://test.example.com" |
| 59 | +pdns_api_token: "testtoken123" |
| 60 | +index_enabled: false |
| 61 | +environments: |
| 62 | + - name: "Test" |
| 63 | + token_sha512: "127aab81f4caab9c00e72f26e4c5c4b20146201a1548a787494d999febf1b9422c1711932117f38d9be9efe46f78aa72d8f6a391101bedd6e200014f6738450d" |
| 64 | + zones: |
| 65 | + - name: "example.com" |
| 66 | +""" |
| 67 | + with tempfile.NamedTemporaryFile(mode="w", suffix=".yml") as f: |
| 68 | + f.write(config_content) |
| 69 | + f.flush() |
| 70 | + |
| 71 | + config_path = Path(f.name) |
| 72 | + config = load_config(config_path) |
| 73 | + assert config.index_enabled is False |
0 commit comments