aboutsummaryrefslogtreecommitdiff
path: root/tests/grliq
diff options
context:
space:
mode:
Diffstat (limited to 'tests/grliq')
-rw-r--r--tests/grliq/managers/test_forensic_data.py65
-rw-r--r--tests/grliq/managers/test_forensic_results.py11
-rw-r--r--tests/grliq/models/test_forensic_data.py8
3 files changed, 57 insertions, 27 deletions
diff --git a/tests/grliq/managers/test_forensic_data.py b/tests/grliq/managers/test_forensic_data.py
index e4854e8..2254829 100644
--- a/tests/grliq/managers/test_forensic_data.py
+++ b/tests/grliq/managers/test_forensic_data.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+from collections.abc import Callable
from datetime import timedelta
from typing import TYPE_CHECKING
from uuid import uuid4
@@ -16,6 +17,8 @@ from generalresearch.grliq.models.forensic_result import (
if TYPE_CHECKING:
from generalresearch.grliq.managers.forensic_data import (
GrlIqDataManager,
+ )
+ from generalresearch.grliq.managers.forensic_events import (
GrlIqEventManager,
)
from generalresearch.models.thl.product import Product
@@ -28,10 +31,13 @@ except ImportError:
class TestGrlIqDataManager:
- def test_create_dummy(self, grliq_dm: GrlIqDataManager):
+ def test_factory(
+ self,
+ grliq_data_factory: Callable[..., GrlIqData],
+ ):
from generalresearch.grliq.models.forensic_data import GrlIqData
- gd1: GrlIqData = grliq_dm.create_dummy(is_attempt_allowed=True)
+ gd1: GrlIqData = grliq_data_factory(is_attempt_allowed=True)
assert isinstance(gd1, GrlIqData)
assert isinstance(gd1.results, GrlIqCheckerResults)
@@ -119,7 +125,9 @@ class TestGrlIqDataManager:
class TestForensicDataGetAndFilter:
- def test_events(self, grliq_dm: GrlIqDataManager):
+ def test_events(
+ self, grliq_dm: GrlIqDataManager, grliq_data_factory: Callable[..., GrlIqData]
+ ):
"""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.
@@ -129,7 +137,7 @@ class TestForensicDataGetAndFilter:
"""
# Load Events == False
forensic_uuid = uuid4().hex
- grliq_dm.create_dummy(is_attempt_allowed=True, uuid=forensic_uuid)
+ grliq_data_factory(is_attempt_allowed=True, uuid=forensic_uuid)
instance = grliq_dm.filter_data(uuids=[forensic_uuid])[0]
assert isinstance(instance, GrlIqData)
@@ -144,41 +152,53 @@ class TestForensicDataGetAndFilter:
assert len(instance.events) == 0
assert len(instance.mouse_events) == 0
- def test_timing(self, grliq_dm: GrlIqDataManager, grliq_em: GrlIqEventManager):
+ def test_timing(
+ self,
+ grliq_data_factory: Callable[..., GrlIqData],
+ grliq_data_manager: GrlIqDataManager,
+ grliq_event_manager: GrlIqEventManager,
+ ):
forensic_uuid = uuid4().hex
- grliq_dm.create_dummy(is_attempt_allowed=True, uuid=forensic_uuid)
+ grliq_data_factory(is_attempt_allowed=True, uuid=forensic_uuid)
- instance = grliq_dm.filter_data(uuids=[forensic_uuid])[0]
+ instance = grliq_data_manager.filter_data(uuids=[forensic_uuid])[0]
- grliq_em.update_or_create_timing(
+ grliq_event_manager.update_or_create_timing(
session_uuid=instance.mid,
timing_data=TimingData(
client_rtts=[100, 200, 150], server_rtts=[150, 120, 120]
),
)
- instance = grliq_dm.get_data(forensic_uuid=forensic_uuid, load_events=True)
+ instance = grliq_data_manager.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: GrlIqDataManager, grliq_em: GrlIqEventManager
+ self,
+ grliq_data_factory: Callable[..., GrlIqData],
+ grliq_data_manager: GrlIqDataManager,
+ grliq_event_manager: GrlIqEventManager,
):
forensic_uuid = uuid4().hex
- grliq_dm.create_dummy(is_attempt_allowed=True, uuid=forensic_uuid)
+ grliq_data_factory(is_attempt_allowed=True, uuid=forensic_uuid)
- instance = grliq_dm.filter_data(uuids=[forensic_uuid])[0]
+ instance = grliq_data_manager.filter_data(uuids=[forensic_uuid])[0]
- grliq_em.update_or_create_events(
+ grliq_event_manager.update_or_create_events(
session_uuid=instance.mid,
events=[{"a": "b"}],
mouse_events=[],
event_start=instance.created_at,
event_end=instance.created_at + timedelta(minutes=1),
)
- instance = grliq_dm.get_data(forensic_uuid=forensic_uuid, load_events=True)
+ instance = grliq_data_manager.get_data(
+ forensic_uuid=forensic_uuid, load_events=True
+ )
assert isinstance(instance, GrlIqData)
assert isinstance(instance.events, list)
assert isinstance(instance.mouse_events, list)
@@ -189,11 +209,16 @@ class TestForensicDataGetAndFilter:
assert len(instance.keyboard_events) == 0
def test_events_click(
- self, grliq_dm: GrlIqDataManager, grliq_em: GrlIqEventManager
+ self,
+ grliq_data_factory: Callable[..., GrlIqData],
+ grliq_data_manager: GrlIqDataManager,
+ grliq_event_manager: 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)
+ grliq_data_factory(is_attempt_allowed=True, uuid=forensic_uuid)
+ instance = grliq_data_manager.get_data(
+ forensic_uuid=forensic_uuid, load_events=True
+ )
click_event = {
"type": "click",
@@ -203,14 +228,16 @@ class TestForensicDataGetAndFilter:
"pointerType": "mouse",
}
me = MouseEvent.from_dict(click_event)
- grliq_em.update_or_create_events(
+ grliq_event_manager.update_or_create_events(
session_uuid=instance.mid,
events=[click_event],
mouse_events=[],
event_start=instance.created_at,
event_end=instance.created_at + timedelta(minutes=1),
)
- instance = grliq_dm.get_data(forensic_uuid=forensic_uuid, load_events=True)
+ instance = grliq_data_manager.get_data(
+ forensic_uuid=forensic_uuid, load_events=True
+ )
assert isinstance(instance, GrlIqData)
assert isinstance(instance.events, list)
assert isinstance(instance.mouse_events, list)
diff --git a/tests/grliq/managers/test_forensic_results.py b/tests/grliq/managers/test_forensic_results.py
index a030451..86834d0 100644
--- a/tests/grliq/managers/test_forensic_results.py
+++ b/tests/grliq/managers/test_forensic_results.py
@@ -1,18 +1,21 @@
from __future__ import annotations
+from collections.abc import Callable
from typing import TYPE_CHECKING
if TYPE_CHECKING:
- from generalresearch.grliq.managers.forensic_data import GrlIqDataManager
from generalresearch.grliq.managers.forensic_results import (
GrlIqCategoryResultsReader,
)
+ from generalresearch.grliq.models.forensic_data import GrlIqData
class TestGrlIqCategoryResultsReader:
def test_filter_category_results(
- self, grliq_dm: GrlIqDataManager, grliq_crr: GrlIqCategoryResultsReader
+ self,
+ grliq_data_factory: Callable[..., GrlIqData],
+ grliq_crr: GrlIqCategoryResultsReader,
):
from generalresearch.grliq.models.forensic_result import (
GrlIqForensicCategoryResult,
@@ -20,8 +23,8 @@ class TestGrlIqCategoryResultsReader:
)
# this is just testing that it doesn't fail
- grliq_dm.create_dummy(is_attempt_allowed=True)
- grliq_dm.create_dummy(is_attempt_allowed=True)
+ grliq_data_factory(is_attempt_allowed=True)
+ grliq_data_factory(is_attempt_allowed=True)
res = grliq_crr.filter_category_results(limit=2, phase=Phase.OFFERWALL_ENTER)[0]
assert res.get("category_result")
diff --git a/tests/grliq/models/test_forensic_data.py b/tests/grliq/models/test_forensic_data.py
index 4fbf962..a901dc3 100644
--- a/tests/grliq/models/test_forensic_data.py
+++ b/tests/grliq/models/test_forensic_data.py
@@ -9,16 +9,16 @@ if TYPE_CHECKING:
class TestGrlIqData:
- def test_supported_fonts(self, grliq_data: "GrlIqData"):
+ 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: "GrlIqData"):
+ 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: "GrlIqData"):
+ def test_base(self, grliq_data: GrlIqData):
from generalresearch.grliq.models.forensic_data import Platform
assert grliq_data.timezone == "America/Los_Angeles"
@@ -41,7 +41,7 @@ class TestGrlIqData:
# 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: "GrlIqData"):
+ def test_corrupt(self, grliq_data: GrlIqData):
"""Test for timestamp and timezone offset mismatch validation."""
from generalresearch.grliq.models.forensic_data import GrlIqData