1+ from contextlib import nullcontext as does_not_raise
2+
13import pytest
24
3- from chatmaild .config import read_config
5+ from chatmaild .config import read_config , is_valid_ipv4 , format_arpa_address , format_deliverable_domain
46
57
68def test_read_config_basic (example_config ):
@@ -16,6 +18,11 @@ def test_read_config_basic(example_config):
1618 assert example_config .mail_domain_deliverable == "chat.example.org"
1719
1820
21+ def test_read_config_deliverable (ipv4_config ):
22+ assert ipv4_config .mail_domain == "1.3.3.7"
23+ assert ipv4_config .mail_domain_deliverable == "[1.3.3.7]"
24+
25+
1926def test_read_config_basic_using_defaults (tmp_path , maildomain ):
2027 inipath = tmp_path .joinpath ("chatmail.ini" )
2128 inipath .write_text (f"[params]\n mail_domain = { maildomain } " )
@@ -122,3 +129,45 @@ def test_config_tls_external_bad_format(make_config):
122129 "tls_external_cert_and_key" : "/only/one/path.pem" ,
123130 },
124131 )
132+
133+
134+ @pytest .mark .parametrize (
135+ ["input" , "result" ],
136+ [
137+ ("example.org" , False ),
138+ ("1.3.3.7" , True ),
139+ ("fe::1" , False ),
140+ ("ad.1e.dag.adf" , False ),
141+ ("12394142" , False ),
142+ ]
143+ )
144+ def test_is_valid_ipv4 (input , result ):
145+ assert result == is_valid_ipv4 (input )
146+
147+
148+ @pytest .mark .parametrize (
149+ ["input" , "result" , "exception" ],
150+ [
151+ ("example.org" , "example.org" , does_not_raise ()),
152+ ("1.3.3.7" , "7.3.3.1.in-addr.arpa" , does_not_raise ()),
153+ ("fe::1" , None , pytest .raises (ValueError )),
154+ ("12394142" , None , pytest .raises (ValueError )),
155+ ]
156+ )
157+ def test_format_arpa_address (input , result , exception ):
158+ with exception :
159+ assert result == format_arpa_address (input )
160+
161+
162+ @pytest .mark .parametrize (
163+ ["input" , "result" , "exception" ],
164+ [
165+ ("example.org" , "example.org" , does_not_raise ()),
166+ ("1.3.3.7" , "[1.3.3.7]" , does_not_raise ()),
167+ ("fe::1" , None , pytest .raises (ValueError )),
168+ ("12394142" , None , pytest .raises (ValueError )),
169+ ]
170+ )
171+ def test_format_deliverable_domain (input , result , exception ):
172+ with exception :
173+ assert result == format_deliverable_domain (input )
0 commit comments