aboutsummaryrefslogtreecommitdiff
path: root/tests/managers/thl/test_profiling
diff options
context:
space:
mode:
Diffstat (limited to 'tests/managers/thl/test_profiling')
-rw-r--r--tests/managers/thl/test_profiling/test_question.py32
-rw-r--r--tests/managers/thl/test_profiling/test_schema.py18
-rw-r--r--tests/managers/thl/test_profiling/test_uqa.py1
-rw-r--r--tests/managers/thl/test_profiling/test_user_upk.py28
4 files changed, 64 insertions, 15 deletions
diff --git a/tests/managers/thl/test_profiling/test_question.py b/tests/managers/thl/test_profiling/test_question.py
index 998466e..e4afb87 100644
--- a/tests/managers/thl/test_profiling/test_question.py
+++ b/tests/managers/thl/test_profiling/test_question.py
@@ -1,12 +1,20 @@
+from collections.abc import Callable
+from typing import TYPE_CHECKING
from uuid import uuid4
-from generalresearch.managers.thl.profiling.question import QuestionManager
-from generalresearch.models import Source
+from generalresearch.models.definitions import Source
+
+if TYPE_CHECKING:
+ from generalresearch.managers.thl.profiling.question import QuestionManager
class TestQuestionManager:
- def test_get_multi_upk(self, question_manager: QuestionManager, upk_data):
+ def test_get_multi_upk(
+ self, question_manager: QuestionManager, upk_data: Callable[..., None]
+ ):
+ upk_data()
+
qs = question_manager.get_multi_upk(
question_ids=[
"8a22de34f985476aac85e15547100db8",
@@ -17,13 +25,21 @@ class TestQuestionManager:
)
assert len(qs) == 3
- def test_get_questions_ranked(self, question_manager: QuestionManager, upk_data):
+ def test_get_questions_ranked(
+ self, question_manager: QuestionManager, upk_data: Callable[..., None]
+ ):
+ upk_data()
+
qs = question_manager.get_questions_ranked(country_iso="mx", language_iso="spa")
assert len(qs) >= 40
assert qs[0].importance.task_score > qs[40].importance.task_score
assert all(q.country_iso == "mx" and q.language_iso == "spa" for q in qs)
- def test_lookup_by_property(self, question_manager: QuestionManager, upk_data):
+ def test_lookup_by_property(
+ self, question_manager: QuestionManager, upk_data: Callable[..., None]
+ ):
+ upk_data()
+
q = question_manager.lookup_by_property(
property_code="i:industry", country_iso="us", language_iso="eng"
)
@@ -38,7 +54,11 @@ class TestQuestionManager:
)
assert q.explanation_template
- def test_filter_by_property(self, question_manager: QuestionManager, upk_data):
+ def test_filter_by_property(
+ self, question_manager: QuestionManager, upk_data: Callable[..., None]
+ ):
+ upk_data()
+
lookup = [
("i:industry", "us", "eng"),
("i:industry", "mx", "eng"),
diff --git a/tests/managers/thl/test_profiling/test_schema.py b/tests/managers/thl/test_profiling/test_schema.py
index ae61527..feab902 100644
--- a/tests/managers/thl/test_profiling/test_schema.py
+++ b/tests/managers/thl/test_profiling/test_schema.py
@@ -1,9 +1,21 @@
+from collections.abc import Callable
+from typing import TYPE_CHECKING
+
from generalresearch.models.thl.profiling.upk_property import PropertyType
+if TYPE_CHECKING:
+ from generalresearch.managers.thl.profiling.schema import (
+ UpkSchemaManager,
+ )
+
class TestUpkSchemaManager:
- def test_get_props_info(self, upk_schema_manager, upk_data):
+ def test_get_props_info(
+ self, upk_schema_manager: UpkSchemaManager, upk_data: Callable[..., None]
+ ):
+ upk_data()
+
props = upk_schema_manager.get_props_info()
assert (
len(props) == 16955
@@ -35,10 +47,10 @@ class TestUpkSchemaManager:
assert age.prop_type == PropertyType.UPK_NUMERICAL
assert age.gold_standard
- cars = [
+ cars = next(
x
for x in props
if x.country_iso == "us" and x.property_label == "household_auto_type"
- ][0]
+ )
assert not cars.gold_standard
assert cars.categories[0].label == "Autos & Vehicles"
diff --git a/tests/managers/thl/test_profiling/test_uqa.py b/tests/managers/thl/test_profiling/test_uqa.py
deleted file mode 100644
index 8b13789..0000000
--- a/tests/managers/thl/test_profiling/test_uqa.py
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/tests/managers/thl/test_profiling/test_user_upk.py b/tests/managers/thl/test_profiling/test_user_upk.py
index 53bb8fe..0f3140c 100644
--- a/tests/managers/thl/test_profiling/test_user_upk.py
+++ b/tests/managers/thl/test_profiling/test_user_upk.py
@@ -1,8 +1,12 @@
-from datetime import datetime, timezone
+from collections.abc import Callable
+from datetime import UTC, datetime
+from typing import TYPE_CHECKING
-from generalresearch.managers.thl.profiling.user_upk import UserUpkManager
+if TYPE_CHECKING:
+ from generalresearch.managers.thl.profiling.user_upk import UserUpkManager
+ from generalresearch.models.thl.user import User
-now = datetime.now(tz=timezone.utc)
+now = datetime.now(tz=UTC)
base = {
"country_iso": "us",
"language_iso": "eng",
@@ -21,11 +25,25 @@ for a in upk_ans_dict:
class TestUserUpkManager:
- def test_user_upk_empty(self, user_upk_manager: UserUpkManager, upk_data, user):
+ def test_user_upk_empty(
+ self,
+ user_upk_manager: UserUpkManager,
+ upk_data: Callable[..., None],
+ user: User,
+ ):
+ upk_data()
+
res = user_upk_manager.get_user_upk_mysql(user_id=user.user_id)
assert len(res) == 0
- def test_user_upk(self, user_upk_manager: UserUpkManager, upk_data, user):
+ def test_user_upk(
+ self,
+ user_upk_manager: UserUpkManager,
+ upk_data: Callable[..., None],
+ user: User,
+ ):
+ upk_data()
+
for x in upk_ans_dict:
x["user_id"] = user.user_id
user_upk = user_upk_manager.populate_user_upk_from_dict(upk_ans_dict)