From 377b6193d15a14b45c53df1d3d936a4ce8e2b345 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 10 Mar 2026 13:58:52 +0000 Subject: [PATCH] Add unit tests for utilities and obfuscation modules - Create `tests/test_obfuscation.py` to test `obfuscate` and `deobfuscate`. - Add tests in `tests/test_utilities.py` for `_to_sec`, `_fuzzyMatch`, `sanitizeShows`, `convertDateTimeToUTC`, `convertUtcToDateTime`, and `createError`. - Ensure all tests pass with pytest. Co-authored-by: razzeee <5943908+razzeee@users.noreply.github.com> --- tests/test_obfuscation.py | 20 ++++++++++++ tests/test_utilities.py | 65 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/test_obfuscation.py diff --git a/tests/test_obfuscation.py b/tests/test_obfuscation.py new file mode 100644 index 00000000..a657b7e7 --- /dev/null +++ b/tests/test_obfuscation.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from resources.lib import obfuscation + +def test_obfuscate(): + assert obfuscation.obfuscate("test") == [54, 39, 49, 54] + +def test_deobfuscate(): + assert obfuscation.deobfuscate([54, 39, 49, 54]) == "test" + +def test_obfuscate_empty(): + assert obfuscation.obfuscate("") == [] + +def test_deobfuscate_empty(): + assert obfuscation.deobfuscate("") == "" + assert obfuscation.deobfuscate(None) == "" + assert obfuscation.deobfuscate("not a list") == "" + +def test_roundtrip(): + original = "Hello, World!" + assert obfuscation.deobfuscate(obfuscation.obfuscate(original)) == original diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 8c86e185..5d434551 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -567,3 +567,68 @@ def test_countEpisodes2(): ) assert utilities.countEpisodes(data1) == 5 + + +def test_to_sec(): + assert utilities._to_sec("1:01:01") == 3661 + assert utilities._to_sec("01:01") == 61 + assert utilities._to_sec("01") == 1 + + +def test_fuzzyMatch(): + assert utilities._fuzzyMatch("The Dark Knight", "The Dark Knight") + assert utilities._fuzzyMatch("The Dark Knight", "Dark Knight") + assert not utilities._fuzzyMatch("The Dark Knight", "The Joker") + + +def test_sanitizeShows(): + shows = { + "shows": [ + { + "title": "Batman", + "seasons": [ + { + "number": 1, + "episodes": [ + { + "number": 1, + "collected": True, + "watched": True, + "season": 1, + "plays": 1, + "ids": {"trakt": 1, "episodeid": 1}, + } + ], + } + ], + } + ] + } + utilities.sanitizeShows(shows) + episode = shows["shows"][0]["seasons"][0]["episodes"][0] + assert "collected" not in episode + assert "watched" not in episode + assert "season" not in episode + assert "plays" not in episode + assert "episodeid" not in episode["ids"] + + +def test_convertDateTimeToUTC(): + # 2023-10-27 10:00:00 UTC + utc_str = utilities.convertDateTimeToUTC("2023-10-27 10:00:00") + assert "2023-10-27" in utc_str + + +def test_convertUtcToDateTime(): + # 2023-10-27T10:00:00.000Z + local_str = utilities.convertUtcToDateTime("2023-10-27T10:00:00.000Z") + assert "2023-10-27" in local_str + + +def test_createError(): + try: + raise ValueError("test error") + except ValueError as e: + error_msg = utilities.createError(e) + assert "ValueError" in error_msg + assert "test error" in error_msg