diff options
| author | Max Nanis | 2026-03-09 06:27:14 -0400 |
|---|---|---|
| committer | Max Nanis | 2026-03-09 06:27:14 -0400 |
| commit | 2f92429a68ec7209059d2d18fe67964c8dd57cf2 (patch) | |
| tree | 641358598982860f6452d27a74cae809b0d2d430 /tests/grliq | |
| parent | ce291a165fab6b6dc9f053c7b75a699d0fdf389f (diff) | |
| download | generalresearch-2f92429a68ec7209059d2d18fe67964c8dd57cf2.tar.gz generalresearch-2f92429a68ec7209059d2d18fe67964c8dd57cf2.zip | |
Simple typing changes, Ruff import formatter. p3
Diffstat (limited to 'tests/grliq')
| -rw-r--r-- | tests/grliq/managers/test_forensic_data.py | 50 | ||||
| -rw-r--r-- | tests/grliq/managers/test_forensic_results.py | 15 | ||||
| -rw-r--r-- | tests/grliq/models/test_forensic_data.py | 34 | ||||
| -rw-r--r-- | tests/grliq/test_utils.py | 5 |
4 files changed, 66 insertions, 38 deletions
diff --git a/tests/grliq/managers/test_forensic_data.py b/tests/grliq/managers/test_forensic_data.py index ed4da80..ac2792a 100644 --- a/tests/grliq/managers/test_forensic_data.py +++ b/tests/grliq/managers/test_forensic_data.py @@ -1,14 +1,21 @@ from datetime import timedelta +from typing import TYPE_CHECKING from uuid import uuid4 import pytest -from generalresearch.grliq.models.events import TimingData, MouseEvent -from generalresearch.grliq.models.forensic_data import GrlIqData -from generalresearch.grliq.models.forensic_result import ( - GrlIqCheckerResults, - GrlIqForensicCategoryResult, -) +if TYPE_CHECKING: + from generalresearch.grliq.managers.forensic_data import ( + GrlIqDataManager, + GrlIqEventManager, + ) + from generalresearch.grliq.models.events import MouseEvent, TimingData + from generalresearch.grliq.models.forensic_data import GrlIqData + from generalresearch.grliq.models.forensic_result import ( + GrlIqCheckerResults, + GrlIqForensicCategoryResult, + ) + from generalresearch.models.thl.product import Product try: from psycopg.errors import UniqueViolation @@ -18,18 +25,16 @@ except ImportError: class TestGrlIqDataManager: - def test_create_dummy(self, grliq_dm): - from generalresearch.grliq.managers.forensic_data import GrlIqDataManager + def test_create_dummy(self, grliq_dm: "GrlIqDataManager"): from generalresearch.grliq.models.forensic_data import GrlIqData - grliq_dm: GrlIqDataManager gd1: GrlIqData = grliq_dm.create_dummy(is_attempt_allowed=True) assert isinstance(gd1, GrlIqData) assert isinstance(gd1.results, GrlIqCheckerResults) assert isinstance(gd1.category_result, GrlIqForensicCategoryResult) - def test_create(self, grliq_data, grliq_dm): + def test_create(self, grliq_data: "GrlIqData", grliq_dm: "GrlIqDataManager"): grliq_dm.create(grliq_data) assert grliq_data.id is not None @@ -45,20 +50,16 @@ class TestGrlIqDataManager: pass @pytest.mark.skip(reason="todo") - def test_update_fingerprint(self): - pass - - @pytest.mark.skip(reason="todo") def test_update_data(self): pass - def test_get_id(self, grliq_data, grliq_dm): + def test_get_id(self, grliq_data: "GrlIqData", grliq_dm: "GrlIqDataManager"): grliq_dm.create(grliq_data) res = grliq_dm.get_data(forensic_id=grliq_data.id) assert res == grliq_data - def test_get_uuid(self, grliq_data, grliq_dm): + def test_get_uuid(self, grliq_data: "GrlIqData", grliq_dm: "GrlIqDataManager"): grliq_dm.create(grliq_data) res = grliq_dm.get_data(forensic_uuid=grliq_data.uuid) @@ -72,7 +73,7 @@ class TestGrlIqDataManager: def test_get_unique_user_count_by_fingerprint(self): pass - def test_filter_data(self, grliq_data, grliq_dm): + def test_filter_data(self, grliq_data: "GrlIqData", grliq_dm: "GrlIqDataManager"): grliq_dm.create(grliq_data) res = grliq_dm.filter_data(uuids=[grliq_data.uuid])[0] assert res == grliq_data @@ -99,7 +100,7 @@ class TestGrlIqDataManager: def test_make_filter_str(self): pass - def test_filter_count(self, grliq_dm, product): + def test_filter_count(self, grliq_dm: "GrlIqDataManager", product: "Product"): res = grliq_dm.filter_count(product_id=product.uuid) assert isinstance(res, int) @@ -115,7 +116,7 @@ class TestGrlIqDataManager: class TestForensicDataGetAndFilter: - def test_events(self, grliq_dm, grliq_em): + def test_events(self, grliq_dm: "GrlIqDataManager"): """If load_events=True, the events and mouse_events attributes should be an array no matter what. An empty array means that the events were loaded, but there were no events available. @@ -140,7 +141,7 @@ class TestForensicDataGetAndFilter: assert len(instance.events) == 0 assert len(instance.mouse_events) == 0 - def test_timing(self, grliq_dm, grliq_em): + def test_timing(self, grliq_dm: "GrlIqDataManager", grliq_em: "GrlIqEventManager"): forensic_uuid = uuid4().hex grliq_dm.create_dummy(is_attempt_allowed=True, uuid=forensic_uuid) @@ -152,13 +153,16 @@ class TestForensicDataGetAndFilter: client_rtts=[100, 200, 150], server_rtts=[150, 120, 120] ), ) + instance = grliq_dm.get_data(forensic_uuid=forensic_uuid, load_events=True) assert isinstance(instance, GrlIqData) assert isinstance(instance.events, list) assert isinstance(instance.mouse_events, list) assert isinstance(instance.timing_data, TimingData) - def test_events_events(self, grliq_dm, grliq_em): + def test_events_events( + self, grliq_dm: "GrlIqDataManager", grliq_em: "GrlIqEventManager" + ): forensic_uuid = uuid4().hex grliq_dm.create_dummy(is_attempt_allowed=True, uuid=forensic_uuid) @@ -181,7 +185,9 @@ class TestForensicDataGetAndFilter: assert len(instance.pointer_move_events) == 0 assert len(instance.keyboard_events) == 0 - def test_events_click(self, grliq_dm, grliq_em): + def test_events_click( + self, grliq_dm: "GrlIqDataManager", grliq_em: "GrlIqEventManager" + ): forensic_uuid = uuid4().hex grliq_dm.create_dummy(is_attempt_allowed=True, uuid=forensic_uuid) instance = grliq_dm.get_data(forensic_uuid=forensic_uuid, load_events=True) diff --git a/tests/grliq/managers/test_forensic_results.py b/tests/grliq/managers/test_forensic_results.py index a837a64..68db732 100644 --- a/tests/grliq/managers/test_forensic_results.py +++ b/tests/grliq/managers/test_forensic_results.py @@ -1,9 +1,20 @@ +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from generalresearch.grliq.managers.forensic_data import GrlIqDataManager + from generalresearch.grliq.managers.forensic_results import ( + GrlIqCategoryResultsReader, + ) + + class TestGrlIqCategoryResultsReader: - def test_filter_category_results(self, grliq_dm, grliq_crr): + def test_filter_category_results( + self, grliq_dm: "GrlIqDataManager", grliq_crr: "GrlIqCategoryResultsReader" + ): from generalresearch.grliq.models.forensic_result import ( - Phase, GrlIqForensicCategoryResult, + Phase, ) # this is just testing that it doesn't fail diff --git a/tests/grliq/models/test_forensic_data.py b/tests/grliq/models/test_forensic_data.py index 653f9a9..4fbf962 100644 --- a/tests/grliq/models/test_forensic_data.py +++ b/tests/grliq/models/test_forensic_data.py @@ -1,42 +1,50 @@ +from typing import TYPE_CHECKING + import pytest from pydantic import ValidationError -from generalresearch.grliq.models.forensic_data import GrlIqData, Platform +if TYPE_CHECKING: + from generalresearch.grliq.models.forensic_data import GrlIqData class TestGrlIqData: - def test_supported_fonts(self, grliq_data): + def test_supported_fonts(self, grliq_data: "GrlIqData"): s = grliq_data.supported_fonts_binary assert len(s) == 1043 assert "Ubuntu" in grliq_data.supported_fonts - def test_battery(self, grliq_data): + def test_battery(self, grliq_data: "GrlIqData"): assert not grliq_data.battery_charging assert grliq_data.battery_level == 0.41 - def test_base(self, grliq_data): - g: GrlIqData = grliq_data - assert g.timezone == "America/Los_Angeles" - assert g.platform == Platform.LINUX_X86_64 - assert g.webgl_extensions + def test_base(self, grliq_data: "GrlIqData"): + from generalresearch.grliq.models.forensic_data import Platform + + assert grliq_data.timezone == "America/Los_Angeles" + assert grliq_data.platform == Platform.LINUX_X86_64 + assert grliq_data.webgl_extensions # ... more - assert g.results is None - assert g.category_result is None + assert grliq_data.results is None + assert grliq_data.category_result is None + + s = grliq_data.model_dump_json() + from generalresearch.grliq.models.forensic_data import GrlIqData, Platform - s = g.model_dump_json() g2: GrlIqData = GrlIqData.model_validate_json(s) assert g2.results is None assert g2.category_result is None - assert g == g2 + assert grliq_data == g2 # Testing things that will cause a validation error, should only be # because something is "corrupt", not b/c the user is a baddie - def test_corrupt(self, grliq_data): + def test_corrupt(self, grliq_data: "GrlIqData"): """Test for timestamp and timezone offset mismatch validation.""" + from generalresearch.grliq.models.forensic_data import GrlIqData + d = grliq_data.model_dump(mode="json") d.update( { diff --git a/tests/grliq/test_utils.py b/tests/grliq/test_utils.py index d9034d5..7f794e8 100644 --- a/tests/grliq/test_utils.py +++ b/tests/grliq/test_utils.py @@ -1,10 +1,13 @@ +from datetime import datetime from pathlib import Path from uuid import uuid4 class TestUtils: - def test_get_screenshot_fp(self, mnt_grliq_archive_dir, utc_hour_ago): + def test_get_screenshot_fp( + self, mnt_grliq_archive_dir: str, utc_hour_ago: datetime + ): from generalresearch.grliq.utils import get_screenshot_fp fp1 = get_screenshot_fp( |
