uaf.git

uaf

~
git clone https://github.com/debuman/uaf.git

tests/test_config.py (2641B)

      1 """Tests for ap_scanner.config."""
      2 
      3 import argparse
      4 
      5 from ap_scanner.config import apply_config_to_args, load_config
      6 
      7 
      8 def test_load_config_missing_file(tmp_path):
      9     result = load_config(str(tmp_path / "nonexistent.ini"))
     10     assert result["band"] == "all"
     11     assert result["sort"] == "rssi"
     12     assert result["interface"] == ""
     13 
     14 
     15 def test_load_config_valid_file(tmp_path):
     16     cfg = tmp_path / "config.ini"
     17     cfg.write_text("[scanner]\ninterface = wlan0\nband = 5\nsort = channel\n")
     18     result = load_config(str(cfg))
     19     assert result["interface"] == "wlan0"
     20     assert result["band"] == "5"
     21     assert result["sort"] == "channel"
     22 
     23 
     24 def test_load_config_partial_file(tmp_path):
     25     cfg = tmp_path / "config.ini"
     26     cfg.write_text("[scanner]\nband = 2.4\n")
     27     result = load_config(str(cfg))
     28     assert result["band"] == "2.4"
     29     assert result["sort"] == "rssi"  # default
     30 
     31 
     32 def test_apply_config_cli_overrides():
     33     args = argparse.Namespace(
     34         interface="wlan1", channels=None, band="all",
     35         sort="rssi", no_color=False, verbose=False,
     36         log_file=None, write=None,
     37     )
     38     config = {"interface": "wlan0", "channels": "1,6,11", "band": "5",
     39               "sort": "channel", "no_color": "false", "verbose": "false",
     40               "log_file": "", "write": ""}
     41     apply_config_to_args(args, config)
     42     # CLI set interface to wlan1, should NOT be overridden
     43     assert args.interface == "wlan1"
     44     # CLI didn't set channels, should pick up from config
     45     assert args.channels == "1,6,11"
     46     # CLI band is default "all", config says "5"
     47     assert args.band == "5"
     48 
     49 
     50 def test_apply_config_all_defaults():
     51     args = argparse.Namespace(
     52         interface=None, channels=None, band="all",
     53         sort="rssi", no_color=False, verbose=False,
     54         log_file=None, write=None,
     55     )
     56     config = {"interface": "", "channels": "", "band": "all",
     57               "sort": "rssi", "no_color": "false", "verbose": "false",
     58               "log_file": "", "write": ""}
     59     apply_config_to_args(args, config)
     60     assert args.interface is None
     61     assert args.band == "all"
     62 
     63 
     64 def test_apply_config_bool_options():
     65     args = argparse.Namespace(
     66         interface=None, channels=None, band="all",
     67         sort="rssi", no_color=False, verbose=False,
     68         log_file=None, write=None,
     69     )
     70     config = {"interface": "", "channels": "", "band": "all",
     71               "sort": "rssi", "no_color": "true", "verbose": "true",
     72               "log_file": "/tmp/test.log", "write": ""}
     73     apply_config_to_args(args, config)
     74     assert args.no_color is True
     75     assert args.verbose is True
     76     assert args.log_file == "/tmp/test.log"