A Python port of the Invisible Internet Project (I2P)
at main 88 lines 3.2 kB view raw
1"""Tests for I2CP session configuration.""" 2 3import pytest 4 5 6class TestSessionConfig: 7 def test_defaults(self): 8 from i2p_client.session_config import SessionConfig 9 cfg = SessionConfig() 10 assert cfg.get("inbound.quantity") == "3" 11 assert cfg.get("outbound.quantity") == "3" 12 assert cfg.get("inbound.length") == "3" 13 assert cfg.get("outbound.length") == "3" 14 15 def test_override(self): 16 from i2p_client.session_config import SessionConfig 17 cfg = SessionConfig({"inbound.quantity": "5", "custom.key": "val"}) 18 assert cfg.get("inbound.quantity") == "5" 19 assert cfg.get("custom.key") == "val" 20 # Defaults still present for non-overridden keys 21 assert cfg.get("outbound.quantity") == "3" 22 23 def test_set_get(self): 24 from i2p_client.session_config import SessionConfig 25 cfg = SessionConfig() 26 cfg.set("my.option", "42") 27 assert cfg.get("my.option") == "42" 28 29 def test_get_missing_returns_none(self): 30 from i2p_client.session_config import SessionConfig 31 cfg = SessionConfig() 32 assert cfg.get("nonexistent") is None 33 34 def test_get_missing_with_default(self): 35 from i2p_client.session_config import SessionConfig 36 cfg = SessionConfig() 37 assert cfg.get("nonexistent", "fallback") == "fallback" 38 39 def test_merge(self): 40 from i2p_client.session_config import SessionConfig 41 cfg = SessionConfig({"a": "1"}) 42 cfg.merge({"b": "2", "a": "override"}) 43 assert cfg.get("a") == "override" 44 assert cfg.get("b") == "2" 45 46 def test_to_properties(self): 47 from i2p_client.session_config import SessionConfig 48 cfg = SessionConfig({"key": "val"}) 49 props = cfg.to_properties() 50 assert isinstance(props, dict) 51 assert "key" in props 52 53 def test_from_properties(self): 54 from i2p_client.session_config import SessionConfig 55 props = {"inbound.quantity": "5", "outbound.length": "2"} 56 cfg = SessionConfig.from_properties(props) 57 assert cfg.get("inbound.quantity") == "5" 58 assert cfg.get("outbound.length") == "2" 59 60 def test_tunnel_options(self): 61 from i2p_client.session_config import SessionConfig 62 cfg = SessionConfig({ 63 "inbound.quantity": "2", 64 "inbound.length": "1", 65 "inbound.backupQuantity": "0", 66 "outbound.quantity": "2", 67 "outbound.length": "1", 68 "outbound.backupQuantity": "0", 69 }) 70 assert cfg.get("inbound.quantity") == "2" 71 assert cfg.get("inbound.backupQuantity") == "0" 72 73 def test_crypto_options(self): 74 from i2p_client.session_config import SessionConfig 75 cfg = SessionConfig({ 76 "crypto.tagsToSend": "40", 77 "crypto.lowTagThreshold": "30", 78 }) 79 assert cfg.get("crypto.tagsToSend") == "40" 80 assert cfg.get("crypto.lowTagThreshold") == "30" 81 82 def test_equality(self): 83 from i2p_client.session_config import SessionConfig 84 c1 = SessionConfig({"a": "1"}) 85 c2 = SessionConfig({"a": "1"}) 86 c3 = SessionConfig({"a": "2"}) 87 assert c1 == c2 88 assert c1 != c3