aboutsummaryrefslogtreecommitdiff
path: root/tests/models/precision
diff options
context:
space:
mode:
Diffstat (limited to 'tests/models/precision')
-rw-r--r--tests/models/precision/__init__.py115
-rw-r--r--tests/models/precision/test_survey.py42
2 files changed, 18 insertions, 139 deletions
diff --git a/tests/models/precision/__init__.py b/tests/models/precision/__init__.py
index 8006fa3..e69de29 100644
--- a/tests/models/precision/__init__.py
+++ b/tests/models/precision/__init__.py
@@ -1,115 +0,0 @@
-survey_json = {
- "cpi": "1.44",
- "country_isos": "ca",
- "language_isos": "eng",
- "country_iso": "ca",
- "language_iso": "eng",
- "buyer_id": "7047",
- "bid_loi": 1200,
- "bid_ir": 0.45,
- "source": "e",
- "used_question_ids": ["age", "country_iso", "gender", "gender_1"],
- "survey_id": "0000",
- "group_id": "633473",
- "status": "open",
- "name": "beauty survey",
- "survey_guid": "c7f375c5077d4c6c8209ff0b539d7183",
- "category_id": "-1",
- "global_conversion": None,
- "desired_count": 96,
- "achieved_count": 0,
- "allowed_devices": "1,2,3",
- "entry_link": "https://www.opinionetwork.com/survey/entry.aspx?mid=[%MID%]&project=633473&key=%%key%%",
- "excluded_surveys": "470358,633286",
- "quotas": [
- {
- "name": "25-34,Male,Quebec",
- "id": "2324110",
- "guid": "23b5760d24994bc08de451b3e62e77c7",
- "status": "open",
- "desired_count": 48,
- "achieved_count": 0,
- "termination_count": 0,
- "overquota_count": 0,
- "condition_hashes": ["b41e1a3", "bc89ee8", "4124366", "9f32c61"],
- },
- {
- "name": "25-34,Female,Quebec",
- "id": "2324111",
- "guid": "0706f1a88d7e4f11ad847c03012e68d2",
- "status": "open",
- "desired_count": 48,
- "achieved_count": 0,
- "termination_count": 4,
- "overquota_count": 0,
- "condition_hashes": ["b41e1a3", "0cdc304", "500af2c", "9f32c61"],
- },
- ],
- "conditions": {
- "b41e1a3": {
- "logical_operator": "OR",
- "value_type": 1,
- "negate": False,
- "question_id": "country_iso",
- "values": ["ca"],
- "criterion_hash": "b41e1a3",
- "value_len": 1,
- "sizeof": 2,
- },
- "bc89ee8": {
- "logical_operator": "OR",
- "value_type": 1,
- "negate": False,
- "question_id": "gender",
- "values": ["male"],
- "criterion_hash": "bc89ee8",
- "value_len": 1,
- "sizeof": 4,
- },
- "4124366": {
- "logical_operator": "OR",
- "value_type": 1,
- "negate": False,
- "question_id": "gender_1",
- "values": ["male"],
- "criterion_hash": "4124366",
- "value_len": 1,
- "sizeof": 4,
- },
- "9f32c61": {
- "logical_operator": "OR",
- "value_type": 1,
- "negate": False,
- "question_id": "age",
- "values": ["25", "26", "27", "28", "29", "30", "31", "32", "33", "34"],
- "criterion_hash": "9f32c61",
- "value_len": 10,
- "sizeof": 20,
- },
- "0cdc304": {
- "logical_operator": "OR",
- "value_type": 1,
- "negate": False,
- "question_id": "gender",
- "values": ["female"],
- "criterion_hash": "0cdc304",
- "value_len": 1,
- "sizeof": 6,
- },
- "500af2c": {
- "logical_operator": "OR",
- "value_type": 1,
- "negate": False,
- "question_id": "gender_1",
- "values": ["female"],
- "criterion_hash": "500af2c",
- "value_len": 1,
- "sizeof": 6,
- },
- },
- "expected_end_date": "2024-06-28T10:40:33.000000Z",
- "created": None,
- "updated": None,
- "is_live": True,
- "all_hashes": ["0cdc304", "b41e1a3", "9f32c61", "bc89ee8", "4124366", "500af2c"],
-}
diff --git a/tests/models/precision/test_survey.py b/tests/models/precision/test_survey.py
index ff2d6d1..4d671f2 100644
--- a/tests/models/precision/test_survey.py
+++ b/tests/models/precision/test_survey.py
@@ -1,10 +1,15 @@
-class TestPrecisionQuota:
+from __future__ import annotations
+
+from typing import Any
+
+from generalresearch.models.precision import PrecisionStatus
+from generalresearch.models.precision.survey import PrecisionSurvey
- def test_quota_passes(self):
- from generalresearch.models.precision.survey import PrecisionSurvey
- from tests.models.precision import survey_json
- s = PrecisionSurvey.model_validate(survey_json)
+class TestPrecisionQuota:
+
+ def test_quota_passes(self, precision_survey_json: dict[str, Any]):
+ s = PrecisionSurvey.model_validate(precision_survey_json)
q = s.quotas[0]
ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]}
assert q.matches(ce)
@@ -16,12 +21,9 @@ class TestPrecisionQuota:
assert not q.matches(ce)
assert not q.matches({})
- def test_quota_passes_closed(self):
- from generalresearch.models.precision import PrecisionStatus
- from generalresearch.models.precision.survey import PrecisionSurvey
- from tests.models.precision import survey_json
+ def test_quota_passes_closed(self, precision_survey_json: dict[str, Any]):
- s = PrecisionSurvey.model_validate(survey_json)
+ s = PrecisionSurvey.model_validate(precision_survey_json)
q = s.quotas[0]
q.status = PrecisionStatus.CLOSED
ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]}
@@ -32,20 +34,15 @@ class TestPrecisionQuota:
class TestPrecisionSurvey:
- def test_passes(self):
- from generalresearch.models.precision.survey import PrecisionSurvey
- from tests.models.precision import survey_json
+ def test_passes(self, precision_survey_json: dict[str, Any]):
- s = PrecisionSurvey.model_validate(survey_json)
+ s = PrecisionSurvey.model_validate(precision_survey_json)
ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]}
assert s.determine_eligibility(ce)
- def test_elig_closed_quota(self):
- from generalresearch.models.precision import PrecisionStatus
- from generalresearch.models.precision.survey import PrecisionSurvey
- from tests.models.precision import survey_json
+ def test_elig_closed_quota(self, precision_survey_json: dict[str, Any]):
- s = PrecisionSurvey.model_validate(survey_json)
+ s = PrecisionSurvey.model_validate(precision_survey_json)
ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]}
q = s.quotas[0]
q.status = PrecisionStatus.CLOSED
@@ -57,12 +54,9 @@ class TestPrecisionSurvey:
# Now me match an open quota and dont match the closed quota, so we should be eligible
assert s.determine_eligibility(ce)
- def test_passes_sp(self):
- from generalresearch.models.precision import PrecisionStatus
- from generalresearch.models.precision.survey import PrecisionSurvey
- from tests.models.precision import survey_json
+ def test_passes_sp(self, precision_survey_json: dict[str, Any]):
- s = PrecisionSurvey.model_validate(survey_json)
+ s = PrecisionSurvey.model_validate(precision_survey_json)
ce = {k: True for k in ["b41e1a3", "bc89ee8", "4124366", "9f32c61"]}
passes, hashes = s.determine_eligibility_soft(ce)