| 1 |
"""Test AsusRouter cleaners tools.""" |
| 2 |
|
| 3 |
from asusrouter.tools import cleaners |
| 4 |
|
| 5 |
|
| 6 |
def test_clean_content() -> None: |
| 7 |
"""Test clean_content method.""" |
| 8 |
|
| 9 |
# Test with BOM |
| 10 |
content = "\ufefftest" |
| 11 |
assert cleaners.clean_content(content) == "test" |
| 12 |
|
| 13 |
# Test without BOM |
| 14 |
content = "test" |
| 15 |
assert cleaners.clean_content(content) == "test" |
| 16 |
|
| 17 |
|
| 18 |
def test_clean_dict() -> None: |
| 19 |
"""Test clean_dict method.""" |
| 20 |
|
| 21 |
# Test with empty dict |
| 22 |
data = {} |
| 23 |
assert cleaners.clean_dict(data) == {} # pylint: disable=C1803 |
| 24 |
|
| 25 |
# Test with empty string |
| 26 |
data = {"test": ""} |
| 27 |
assert cleaners.clean_dict(data) == {"test": None} |
| 28 |
|
| 29 |
# Test with nested dicts |
| 30 |
data = {"test": {"test": ""}} |
| 31 |
assert cleaners.clean_dict(data) == {"test": {"test": None}} |
| 32 |
|
| 33 |
|
| 34 |
def test_clean_dict_key_prefix() -> None: |
| 35 |
"""Test clean_dict_key_prefix method.""" |
| 36 |
|
| 37 |
# Test with empty dict |
| 38 |
data = {} |
| 39 |
assert cleaners.clean_dict_key_prefix(data, "prefix") == {} # pylint: disable=C1803 |
| 40 |
|
| 41 |
# Test with empty string |
| 42 |
data = {"prefix_test": "", "test2": ""} |
| 43 |
assert cleaners.clean_dict_key_prefix(data, "prefix") == { |
| 44 |
"test": "", |
| 45 |
"test2": "", |
| 46 |
} |
| 47 |
|
| 48 |
# Test with nested dicts |
| 49 |
data = {"prefix_test": {"prefix_test": ""}} |
| 50 |
assert cleaners.clean_dict_key_prefix(data, "prefix") == { |
| 51 |
"test": {"prefix_test": ""} |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
def test_clean_dict_key() -> None: |
| 56 |
"""Test clean_dict_key method.""" |
| 57 |
|
| 58 |
# Test with empty dict |
| 59 |
data = {} |
| 60 |
assert cleaners.clean_dict_key(data, "test") == {} # pylint: disable=C1803 |
| 61 |
|
| 62 |
# Test with empty string |
| 63 |
data = {"test": "", "test2": ""} |
| 64 |
assert cleaners.clean_dict_key(data, "test") == {"test2": ""} |
| 65 |
|
| 66 |
# Test with nested dicts |
| 67 |
data = {"test": {"test": ""}, "test2": {"test": ""}} |
| 68 |
assert cleaners.clean_dict_key(data, "test") == {"test2": {}} |