diff options
| author | stuppie | 2026-08-18 19:09:22 -0600 |
|---|---|---|
| committer | stuppie | 2026-08-18 19:09:22 -0600 |
| commit | 28729d407470407bbc78bc7fb6574953b2f03f59 (patch) | |
| tree | 698a5820105f0ff02c93b5205faee7747fcb6ad9 /tests | |
| parent | 4d4fce08f3a4c9dbd78fdacf3193b345cf982da3 (diff) | |
| parent | 0742210fc7eaa54d8068bfd18414158dc9b33672 (diff) | |
| download | generalresearch-28729d407470407bbc78bc7fb6574953b2f03f59.tar.gz generalresearch-28729d407470407bbc78bc7fb6574953b2f03f59.zip | |
Merge branch 'master' of ssh://code.g-r-l.com/generalresearch
Diffstat (limited to 'tests')
28 files changed, 305 insertions, 292 deletions
diff --git a/tests/models/gr/test_business.py b/tests/models/gr/test_business.py index 0b78374..e8bd06a 100644 --- a/tests/models/gr/test_business.py +++ b/tests/models/gr/test_business.py @@ -9,20 +9,14 @@ import pytest # noinspection PyUnresolvedReferences from distributed.utils_test import ( - gen_cluster, client_no_amm, - loop, - loop_in_thread, - cleanup, - cluster_fixture, - client, ) from pytest import approx from generalresearch.currency import USDCent from generalresearch.models.thl.finance import ( - ProductBalances, BusinessBalances, + ProductBalances, ) # from test_utils.incite.conftest import mnt_filepath @@ -669,8 +663,6 @@ class TestBusinessBalance: user_factory, mnt_filepath, bp_payout_factory, - thl_lm, - lm, duration, offset, start, @@ -679,7 +671,6 @@ class TestBusinessBalance: session_with_tx_factory, delete_ledger_db, create_main_accounts, - client_no_amm, ledger_collection, task_adj_collection, pop_ledger_merge, diff --git a/tests/models/legacy/test_offerwall_parse_response.py b/tests/models/legacy/test_offerwall_parse_response.py index 7fb5315..b1c96ad 100644 --- a/tests/models/legacy/test_offerwall_parse_response.py +++ b/tests/models/legacy/test_offerwall_parse_response.py @@ -2,20 +2,20 @@ import json from generalresearch.models import Source from generalresearch.models.legacy.bucket import ( - TopNPlusBucket, - SurveyEligibilityCriterion, + BucketTask, DurationSummary, PayoutSummary, - BucketTask, + SurveyEligibilityCriterion, + TopNPlusBucket, ) class TestOfferwallTopNAndStarwall: def test_45b7228a7(self): from generalresearch.models.legacy.offerwall import ( + StarwallOfferWallResponse, TopNOfferWall, TopNOfferWallResponse, - StarwallOfferWallResponse, ) from tests.models.legacy.data import ( RESPONSE_45b7228a7, @@ -31,8 +31,8 @@ class TestOfferwallTopNAndStarwall: def test_b145b803(self): from generalresearch.models.legacy.offerwall import ( - TopNPlusOfferWallResponse, StarwallPlusOfferWallResponse, + TopNPlusOfferWallResponse, ) from tests.models.legacy.data import ( RESPONSE_b145b803, @@ -44,8 +44,8 @@ class TestOfferwallTopNAndStarwall: def test_d48cce47(self): from generalresearch.models.legacy.offerwall import ( - TopNPlusBlockOfferWallResponse, StarwallPlusBlockOfferWallResponse, + TopNPlusBlockOfferWallResponse, ) from tests.models.legacy.data import ( RESPONSE_b145b803, @@ -62,12 +62,12 @@ class TestOfferwallTopNAndStarwall: def test_1e5f0af8(self): from generalresearch.models.legacy.offerwall import ( - TopNPlusBlockRecontactOfferWallResponse, StarwallPlusBlockRecontactOfferWallResponse, + TopNPlusBlockRecontactOfferWallResponse, ) from tests.models.legacy.data import ( - RESPONSE_d48cce47, RESPONSE_1e5f0af8, + RESPONSE_d48cce47, ) res = json.loads(RESPONSE_1e5f0af8) @@ -149,7 +149,6 @@ class TestMarketplace: from generalresearch.models.legacy.offerwall import ( MarketplaceOfferwallResponse, ) - from tests.models.legacy.data import ( RESPONSE_5fa23085, ) @@ -175,8 +174,8 @@ class TestTimebucks: TimeBucksBlockOfferwallResponse, ) from tests.models.legacy.data import ( - RESPONSE_1705e4f8, RESPONSE_0af0f7ec, + RESPONSE_1705e4f8, ) res = json.loads(RESPONSE_0af0f7ec) diff --git a/tests/models/legacy/test_user_question_answer_in.py b/tests/models/legacy/test_user_question_answer_in.py index 253c46e..224334a 100644 --- a/tests/models/legacy/test_user_question_answer_in.py +++ b/tests/models/legacy/test_user_question_answer_in.py @@ -24,12 +24,12 @@ class TestUserQuestionAnswers: session_factory, utc_hour_ago, ): - from generalresearch.models.thl.session import Session, Wall - from generalresearch.models.thl.user import User from generalresearch.models import Source from generalresearch.models.legacy.questions import ( UserQuestionAnswers, ) + from generalresearch.models.thl.session import Session, Wall + from generalresearch.models.thl.user import User u: User = user_factory(product=product) @@ -161,10 +161,7 @@ class TestUserQuestionAnswers: def test_allow_answer_failures_silent( self, - product_manager, user_manager, - session_manager, - wall_manager, product, user_factory, utc_hour_ago, @@ -176,11 +173,11 @@ class TestUserQuestionAnswers: that one QuestionAnswerIn without "loosing" any of the other QuestionAnswerIn items that they provided. """ - from generalresearch.models.thl.session import Session, Wall - from generalresearch.models.thl.user import User from generalresearch.models.legacy.questions import ( UserQuestionAnswers, ) + from generalresearch.models.thl.session import Session, Wall + from generalresearch.models.thl.user import User u: User = user_factory(product=product) diff --git a/tests/models/morning/test.py b/tests/models/morning/test.py index cf4982d..bedf9c2 100644 --- a/tests/models/morning/test.py +++ b/tests/models/morning/test.py @@ -185,8 +185,11 @@ class TestMorningBid: from generalresearch.models.morning.survey import MorningBid s = MorningBid.model_validate(bid) - d = s.model_dump(mode="json") - d = s.to_mysql() + res = s.model_dump(mode="json") + assert isinstance(res, dict) + + res = s.to_mysql() + assert isinstance(res, dict) def test_manager(self): # todo: credentials n stuff diff --git a/tests/models/network/test_nmap.py b/tests/models/network/test_nmap.py index 0be98d4..a135a13 100644 --- a/tests/models/network/test_nmap.py +++ b/tests/models/network/test_nmap.py @@ -1,20 +1,21 @@ import subprocess -from generalresearch.models.network.definitions import IPProtocol -from generalresearch.models.network.nmap.execute import execute_nmap import faker +from generalresearch.managers.network.tool_run import ToolRunManager +from generalresearch.models.network.definitions import IPProtocol +from generalresearch.models.network.nmap.execute import execute_nmap from generalresearch.models.network.nmap.result import PortState -from generalresearch.models.network.tool_run import ToolName, ToolClass +from generalresearch.models.network.tool_run import ToolClass, ToolName fake = faker.Faker() -def resolve(host): +def resolve(host: str): return subprocess.check_output(["dig", host, "+short"]).decode().strip() -def test_execute_nmap_scanme(toolrun_manager): +def test_execute_nmap_scanme(toolrun_manager: ToolRunManager): ip = resolve("scanme.nmap.org") run = execute_nmap(ip=ip, top_ports=None, ports="20-30", enable_advanced=False) diff --git a/tests/models/network/test_nmap_parser.py b/tests/models/network/test_nmap_parser.py index 96d7b37..abc83c9 100644 --- a/tests/models/network/test_nmap_parser.py +++ b/tests/models/network/test_nmap_parser.py @@ -7,7 +7,7 @@ from generalresearch.models.network.nmap.parser import parse_nmap_xml @pytest.fixture def nmap_raw_output_2(request) -> str: fp = os.path.join(request.config.rootpath, "data/nmaprun2.xml") - with open(fp, "r") as f: + with open(fp) as f: data = f.read() return data diff --git a/tests/models/network/test_rdns.py b/tests/models/network/test_rdns.py index e56c494..5c3b024 100644 --- a/tests/models/network/test_rdns.py +++ b/tests/models/network/test_rdns.py @@ -1,12 +1,13 @@ -from generalresearch.models.network.rdns.execute import execute_rdns import faker -from generalresearch.models.network.tool_run import ToolName, ToolClass +from generalresearch.managers.network.tool_run import ToolRunManager +from generalresearch.models.network.rdns.execute import execute_rdns +from generalresearch.models.network.tool_run import ToolClass, ToolName fake = faker.Faker() -def test_execute_rdns_grl(toolrun_manager): +def test_execute_rdns_grl(toolrun_manager: ToolRunManager): ip = "65.19.129.53" run = execute_rdns(ip=ip) assert run.tool_name == ToolName.DIG @@ -20,7 +21,7 @@ def test_execute_rdns_grl(toolrun_manager): toolrun_manager.create_rdns_run(run) -def test_execute_rdns_none(toolrun_manager): +def test_execute_rdns_none(toolrun_manager: ToolRunManager): ip = fake.ipv6() run = execute_rdns(ip) result = run.parsed diff --git a/tests/models/prodege/test_survey_participation.py b/tests/models/prodege/test_survey_participation.py index b85cc91..68d7838 100644 --- a/tests/models/prodege/test_survey_participation.py +++ b/tests/models/prodege/test_survey_participation.py @@ -1,4 +1,4 @@ -from datetime import timezone, datetime, timedelta +from datetime import datetime, timedelta, timezone class TestProdegeParticipation: diff --git a/tests/models/spectrum/test_survey.py b/tests/models/spectrum/test_survey.py index 65dec60..b612a63 100644 --- a/tests/models/spectrum/test_survey.py +++ b/tests/models/spectrum/test_survey.py @@ -1,4 +1,4 @@ -from datetime import timezone, datetime +from datetime import datetime, timezone from decimal import Decimal diff --git a/tests/models/test_device.py b/tests/models/test_device.py index 480e0c0..bf72c81 100644 --- a/tests/models/test_device.py +++ b/tests/models/test_device.py @@ -1,5 +1,3 @@ -import pytest - iphone_ua_string = ( "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) " "Version/5.1 Mobile/9B179 Safari/7534.48.3" diff --git a/tests/models/test_finance.py b/tests/models/test_finance.py index 888bf49..bd548b3 100644 --- a/tests/models/test_finance.py +++ b/tests/models/test_finance.py @@ -1,36 +1,36 @@ -from datetime import timezone, timedelta +from datetime import datetime, timedelta, timezone from itertools import product as iter_product from random import randint +from typing import Callable from uuid import uuid4 import pandas as pd import pytest +from dask.distributed import Client as DaskClient # noinspection PyUnresolvedReferences from distributed.utils_test import ( - gen_cluster, client_no_amm, - loop, - loop_in_thread, - cleanup, - cluster_fixture, - client, ) from faker import Faker +from generalresearch.incite.collections.thl_web import LedgerDFCollection +from generalresearch.incite.mergers.pop_ledger import PopLedgerMerge from generalresearch.incite.schemas.mergers.pop_ledger import ( numerical_col_names, ) +from generalresearch.managers.thl.ledger_manager.thl_ledger import ThlLedgerManager from generalresearch.models.thl.finance import ( + BusinessBalances, POPFinancial, ProductBalances, - BusinessBalances, ) -from test_utils.conftest import delete_df_collection +from generalresearch.models.thl.product import Product +from generalresearch.models.thl.session import Session +from generalresearch.models.thl.user import User from test_utils.incite.collections.conftest import ledger_collection from test_utils.incite.mergers.conftest import pop_ledger_merge from test_utils.managers.ledger.conftest import ( - create_main_accounts, session_with_tx_factory, ) @@ -665,20 +665,12 @@ class TestProductFinanceData: def test_base( self, - client_no_amm, - ledger_collection, - pop_ledger_merge, - mnt_filepath, - session_with_tx_factory, - product, - user_factory, - start, - duration, - delete_df_collection, - thl_lm, - create_main_accounts, + product: Product, + user_factory: Callable[..., User], + start: datetime, + duration: timedelta, + thl_lm: ThlLedgerManager, ): - from generalresearch.models.thl.user import User # -- Build & Setup # assert ledger_collection.start is None @@ -687,7 +679,7 @@ class TestProductFinanceData: for item in ledger_collection.items: - for s_idx in range(3): + for _ in range(3): rand_item_time = fake.date_time_between( start_date=item.start, end_date=item.finish, @@ -736,8 +728,8 @@ class TestProductFinanceData: # On this, we can assert all products are the same, and that there are # no overlapping time intervals - assert 1 == len(set(list([i.product_id for i in res]))) - assert len(res) == len(set(list([i.time for i in res]))) + assert 1 == len({i.product_id for i in res}) + assert len(res) == len({i.time for i in res}) @pytest.mark.parametrize( @@ -753,18 +745,16 @@ class TestPOPFinancialData: def test_base( self, - client_no_amm, - ledger_collection, - pop_ledger_merge, - mnt_filepath, - user_factory, - product, - start, - duration, + client_no_amm: DaskClient, + ledger_collection: LedgerDFCollection, + pop_ledger_merge: PopLedgerMerge, + user_factory: Callable[..., User], + product: Product, + start: datetime, + duration: timedelta, create_main_accounts, - session_with_tx_factory, - session_manager, - thl_lm, + session_with_tx_factory: Callable[..., Session], + thl_lm: ThlLedgerManager, delete_df_collection, delete_ledger_db, ): @@ -776,7 +766,7 @@ class TestPOPFinancialData: # assert ledger_collection.offset is None users = [] - for idx in range(5): + for _ in range(5): u = user_factory(product=product) for item in ledger_collection.items: @@ -853,25 +843,19 @@ class TestPOPFinancialData: class TestBusinessBalanceData: def test_from_pandas( self, - client_no_amm, - ledger_collection, - pop_ledger_merge, - user_factory, - product, + client_no_amm: DaskClient, + ledger_collection: LedgerDFCollection, + pop_ledger_merge: PopLedgerMerge, + user_factory: Callable[..., User], + product: Product, create_main_accounts, - session_factory, - thl_lm, - session_manager, - start, + thl_lm: ThlLedgerManager, thl_web_rr, - duration, delete_df_collection, delete_ledger_db, - session_with_tx_factory, - offset, + session_with_tx_factory: Callable[..., Session], rm_ledger_collection, ): - from generalresearch.models.thl.user import User from generalresearch.models.thl.ledger import LedgerAccount delete_ledger_db() @@ -879,7 +863,7 @@ class TestBusinessBalanceData: delete_df_collection(coll=ledger_collection) rm_ledger_collection() - for idx in range(5): + for _ in range(5): u: User = user_factory(product=product, created=ledger_collection.start) for item in ledger_collection.items: diff --git a/tests/models/thl/test_adjustments.py b/tests/models/thl/test_adjustments.py index 15d01d0..27091bb 100644 --- a/tests/models/thl/test_adjustments.py +++ b/tests/models/thl/test_adjustments.py @@ -1,16 +1,20 @@ -from datetime import datetime, timezone, timedelta +from datetime import datetime, timedelta, timezone from decimal import Decimal +from typing import Callable import pytest from generalresearch.models import Source +from generalresearch.models.thl.product import Product from generalresearch.models.thl.session import ( - Wall, + Session, + SessionAdjustedStatus, Status, StatusCode1, + Wall, WallAdjustedStatus, - SessionAdjustedStatus, ) +from generalresearch.models.thl.user import User started1 = datetime(2023, 1, 1, tzinfo=timezone.utc) started2 = datetime(2023, 1, 1, 0, 10, 0, tzinfo=timezone.utc) @@ -25,14 +29,18 @@ adj_ts3 = datetime(2023, 2, 4, tzinfo=timezone.utc) class TestProductAdjustments: @pytest.mark.parametrize("payout", [".6", "1", "1.8", "2", "500.0000"]) - def test_determine_bp_payment_no_rounding(self, product_factory, payout): + def test_determine_bp_payment_no_rounding( + self, product_factory: Callable[..., Product], payout + ): p1 = product_factory(commission_pct=Decimal("0.05")) res = p1.determine_bp_payment(thl_net=Decimal(payout)) assert isinstance(res, Decimal) assert res == Decimal(payout) * Decimal("0.95") @pytest.mark.parametrize("payout", [".01", ".05", ".5"]) - def test_determine_bp_payment_rounding(self, product_factory, payout): + def test_determine_bp_payment_rounding( + self, product_factory: Callable[..., Product], payout + ): p1 = product_factory(commission_pct=Decimal("0.05")) res = p1.determine_bp_payment(thl_net=Decimal(payout)) assert isinstance(res, Decimal) @@ -41,7 +49,7 @@ class TestProductAdjustments: class TestSessionAdjustments: - def test_status_complete(self, session_factory, user): + def test_status_complete(self, session_factory: Callable[..., Session], user: User): # Completed Session with 2 wall events s1 = session_factory( user=user, @@ -64,7 +72,9 @@ class TestSessionAdjustments: class TestAdjustments: - def test_finish_with_status(self, session_factory, user, session_manager): + def test_finish_with_status( + self, session_factory: Callable[..., Session], user: User, session_manager + ): # Completed Session with 2 wall events s1 = session_factory( user=user, @@ -86,7 +96,9 @@ class TestAdjustments: assert Decimal("0.95") == payout - def test_never_adjusted(self, session_factory, user, session_manager): + def test_never_adjusted( + self, session_factory: Callable[..., Session], user: User, session_manager + ): s1 = session_factory( user=user, wall_count=5, @@ -115,7 +127,11 @@ class TestAdjustments: assert s1.adjusted_timestamp is None def test_adjustment_wall_values( - self, session_factory, user, session_manager, wall_manager + self, + session_factory: Callable[..., Session], + user: User, + session_manager, + wall_manager, ): # Completed Session with 2 wall events s1 = session_factory( @@ -162,7 +178,11 @@ class TestAdjustments: assert s1.adjusted_user_payout is None def test_adjustment_session_values( - self, wall_manager, session_manager, session_factory, user + self, + wall_manager, + session_manager, + session_factory: Callable[..., Session], + user: User, ): # Completed Session with 2 wall events s1 = session_factory( @@ -202,7 +222,11 @@ class TestAdjustments: assert s1.adjusted_user_payout is None def test_double_adjustment_session_values( - self, wall_manager, session_manager, session_factory, user + self, + wall_manager, + session_manager, + session_factory: Callable[..., Session], + user: User, ): # Completed Session with 2 wall events s1 = session_factory( @@ -251,7 +275,11 @@ class TestAdjustments: assert s1.adjusted_user_payout is None def test_double_adjustment_sm_vs_db_values( - self, wall_manager, session_manager, session_factory, user + self, + wall_manager, + session_manager, + session_factory: Callable[..., Session], + user: User, ): # Completed Session with 2 wall events s1 = session_factory( @@ -314,7 +342,11 @@ class TestAdjustments: ) == w_db.model_dump_json(exclude={"cpi", "req_cpi"}) def test_double_adjustment_double_completes( - self, wall_manager, session_manager, session_factory, user + self, + wall_manager, + session_manager, + session_factory: Callable[..., Session], + user: User, ): # Completed Session with 2 wall events s1 = session_factory( @@ -384,7 +416,12 @@ class TestAdjustments: assert adj_ts3 == s1.adjusted_timestamp def test_complete_to_fail( - self, session_factory, user, session_manager, wall_manager, utc_hour_ago + self, + session_factory: Callable[..., Session], + user: User, + session_manager, + wall_manager, + utc_hour_ago: datetime, ): s1 = session_factory( user=user, @@ -422,6 +459,7 @@ class TestAdjustments: assert Status.FAIL == new_status assert Decimal(0) == new_payout + assert isinstance(user.product, Product) assert not user.product.user_wallet_config.enabled assert new_user_payout is None @@ -477,7 +515,12 @@ class TestAdjustments: # assert Decimal("0.24") == s1.adjusted_user_payout assert s1.adjusted_user_payout is None - def test_complete_to_fail_to_complete(self, user, session_factory, utc_hour_ago): + def test_complete_to_fail_to_complete( + self, + user: User, + session_factory: Callable[..., Session], + utc_hour_ago: datetime, + ): # Setup: Complete, then adjust it to fail s1 = session_factory( user=user, @@ -529,7 +572,10 @@ class TestAdjustments: assert s1.adjusted_user_payout is None def test_complete_to_fail_to_complete_adj( - self, user, session_factory, utc_hour_ago + self, + user: User, + session_factory: Callable[..., Session], + utc_hour_ago: datetime, ): s1 = session_factory( user=user, @@ -634,7 +680,12 @@ class TestAdjustments: # assert Decimal("0.48") == s.adjusted_user_payout assert s1.adjusted_user_payout is None - def test_fail_to_complete_to_fail(self, user, session_factory, utc_hour_ago): + def test_fail_to_complete_to_fail( + self, + user: User, + session_factory: Callable[..., Session], + utc_hour_ago: datetime, + ): # End with an abandon s1 = session_factory( user=user, diff --git a/tests/models/thl/test_contest/test_contest.py b/tests/models/thl/test_contest/test_contest.py index d53eee5..0fbd4cc 100644 --- a/tests/models/thl/test_contest/test_contest.py +++ b/tests/models/thl/test_contest/test_contest.py @@ -1,4 +1,8 @@ +from typing import Callable + import pytest + +from generalresearch.models.thl.product import Product from generalresearch.models.thl.user import User @@ -11,13 +15,13 @@ class TestContest: """ @pytest.fixture(scope="function") - def user_1(self, user_factory, product) -> User: + def user_1(self, user_factory: Callable[..., User], product: Product) -> User: return user_factory(product=product) @pytest.fixture(scope="function") - def user_2(self, user_factory, product) -> User: + def user_2(self, user_factory: Callable[..., User], product: Product) -> User: return user_factory(product=product) @pytest.fixture(scope="function") - def user_3(self, user_factory, product) -> User: + def user_3(self, user_factory: Callable[..., User], product: Product) -> User: return user_factory(product=product) diff --git a/tests/models/thl/test_contest/test_leaderboard_contest.py b/tests/models/thl/test_contest/test_leaderboard_contest.py index 98f3215..8b714ee 100644 --- a/tests/models/thl/test_contest/test_leaderboard_contest.py +++ b/tests/models/thl/test_contest/test_leaderboard_contest.py @@ -7,8 +7,8 @@ from generalresearch.currency import USDCent from generalresearch.managers.leaderboard.manager import LeaderboardManager from generalresearch.models.thl.contest import ContestPrize from generalresearch.models.thl.contest.definitions import ( - ContestType, ContestPrizeKind, + ContestType, ) from generalresearch.models.thl.contest.leaderboard import ( LeaderboardContest, @@ -17,6 +17,7 @@ from generalresearch.models.thl.contest.utils import ( distribute_leaderboard_prizes, ) from generalresearch.models.thl.leaderboard import LeaderboardRow +from generalresearch.models.thl.product import Product from tests.models.thl.test_contest.test_contest import TestContest @@ -24,7 +25,7 @@ class TestLeaderboardContest(TestContest): @pytest.fixture def leaderboard_contest( - self, product, thl_redis, user_manager + self, product: Product, thl_redis, user_manager ) -> "LeaderboardContest": board_key = f"leaderboard:{product.uuid}:us:weekly:2025-05-26:complete_count" diff --git a/tests/models/thl/test_contest/test_raffle_contest.py b/tests/models/thl/test_contest/test_raffle_contest.py index e1c0a15..d7920f0 100644 --- a/tests/models/thl/test_contest/test_raffle_contest.py +++ b/tests/models/thl/test_contest/test_raffle_contest.py @@ -6,26 +6,26 @@ from pytest import approx from generalresearch.currency import USDCent from generalresearch.models.thl.contest import ( - ContestPrize, ContestEndCondition, + ContestPrize, ) from generalresearch.models.thl.contest.contest_entry import ContestEntry from generalresearch.models.thl.contest.definitions import ( + ContestEndReason, ContestEntryType, ContestPrizeKind, - ContestType, ContestStatus, - ContestEndReason, + ContestType, ) from generalresearch.models.thl.contest.raffle import RaffleContest - +from generalresearch.models.thl.product import Product from tests.models.thl.test_contest.test_contest import TestContest class TestRaffleContest(TestContest): @pytest.fixture(scope="function") - def raffle_contest(self, product) -> RaffleContest: + def raffle_contest(self, product: Product) -> RaffleContest: return RaffleContest( product_id=product.uuid, name=f"Raffle Contest {uuid4().hex}", diff --git a/tests/models/thl/test_ledger.py b/tests/models/thl/test_ledger.py index d706357..257de3c 100644 --- a/tests/models/thl/test_ledger.py +++ b/tests/models/thl/test_ledger.py @@ -1,12 +1,16 @@ from datetime import datetime, timezone -from decimal import Decimal from uuid import uuid4 import pytest from pydantic import ValidationError -from generalresearch.models.thl.ledger import LedgerAccount, Direction, AccountType -from generalresearch.models.thl.ledger import LedgerTransaction, LedgerEntry +from generalresearch.models.thl.ledger import ( + AccountType, + Direction, + LedgerAccount, + LedgerEntry, + LedgerTransaction, +) class TestLedgerTransaction: @@ -43,14 +47,6 @@ class TestLedgerTransaction: LedgerEntry( direction=Direction.CREDIT, account_uuid="3f3735eaed264c2a9f8a114934afa121", - amount=Decimal("1"), - ) - assert "Input should be a valid integer" in str(cm.value) - - with pytest.raises(ValidationError) as cm: - LedgerEntry( - direction=Direction.CREDIT, - account_uuid="3f3735eaed264c2a9f8a114934afa121", amount=1.2, ) assert "Input should be a valid integer" in str(cm.value) diff --git a/tests/models/thl/test_marketplace_condition.py b/tests/models/thl/test_marketplace_condition.py index 217616d..8a4b25c 100644 --- a/tests/models/thl/test_marketplace_condition.py +++ b/tests/models/thl/test_marketplace_condition.py @@ -7,8 +7,8 @@ class TestMarketplaceCondition: def test_list_or(self): from generalresearch.models import LogicalOperator from generalresearch.models.thl.survey.condition import ( - MarketplaceCondition, ConditionValueType, + MarketplaceCondition, ) user_qas = {"q1": {"a2"}} @@ -48,8 +48,8 @@ class TestMarketplaceCondition: def test_list_or_negate(self): from generalresearch.models import LogicalOperator from generalresearch.models.thl.survey.condition import ( - MarketplaceCondition, ConditionValueType, + MarketplaceCondition, ) user_qas = {"q1": {"a2"}} @@ -89,8 +89,8 @@ class TestMarketplaceCondition: def test_list_and(self): from generalresearch.models import LogicalOperator from generalresearch.models.thl.survey.condition import ( - MarketplaceCondition, ConditionValueType, + MarketplaceCondition, ) user_qas = {"q1": {"a1", "a2"}} @@ -139,8 +139,8 @@ class TestMarketplaceCondition: def test_list_and_negate(self): from generalresearch.models import LogicalOperator from generalresearch.models.thl.survey.condition import ( - MarketplaceCondition, ConditionValueType, + MarketplaceCondition, ) user_qas = {"q1": {"a1", "a2"}} @@ -180,8 +180,8 @@ class TestMarketplaceCondition: def test_ranges(self): from generalresearch.models import LogicalOperator from generalresearch.models.thl.survey.condition import ( - MarketplaceCondition, ConditionValueType, + MarketplaceCondition, ) user_qas = {"q1": {"2", "50"}} @@ -247,8 +247,8 @@ class TestMarketplaceCondition: def test_ranges_to_list(self): from generalresearch.models import LogicalOperator from generalresearch.models.thl.survey.condition import ( - MarketplaceCondition, ConditionValueType, + MarketplaceCondition, ) user_qas = {"q1": {"2", "50"}} @@ -267,8 +267,8 @@ class TestMarketplaceCondition: def test_ranges_infinity(self): from generalresearch.models import LogicalOperator from generalresearch.models.thl.survey.condition import ( - MarketplaceCondition, ConditionValueType, + MarketplaceCondition, ) user_qas = {"q1": {"2", "50"}} @@ -310,8 +310,8 @@ class TestMarketplaceCondition: def test_answered(self): from generalresearch.models.thl.survey.condition import ( - MarketplaceCondition, ConditionValueType, + MarketplaceCondition, ) user_qas = {"q1": {"a2"}} @@ -346,8 +346,8 @@ class TestMarketplaceCondition: def test_invite(self): from generalresearch.models.thl.survey.condition import ( - MarketplaceCondition, ConditionValueType, + MarketplaceCondition, ) user_groups = {"g1", "g2", "g3"} @@ -357,14 +357,14 @@ class TestMarketplaceCondition: value_type=ConditionValueType.RECONTACT, values=["g1", "g4"], ) - assert c.evaluate_criterion(user_qas=dict(), user_groups=user_groups) + assert c.evaluate_criterion(user_qas={}, user_groups=user_groups) c = MarketplaceCondition( question_id=None, negate=False, value_type=ConditionValueType.RECONTACT, values=["g4"], ) - assert not c.evaluate_criterion(user_qas=dict(), user_groups=user_groups) + assert not c.evaluate_criterion(user_qas={}, user_groups=user_groups) c = MarketplaceCondition( question_id=None, @@ -372,11 +372,11 @@ class TestMarketplaceCondition: value_type=ConditionValueType.RECONTACT, values=["g1", "g4"], ) - assert not c.evaluate_criterion(user_qas=dict(), user_groups=user_groups) + assert not c.evaluate_criterion(user_qas={}, user_groups=user_groups) c = MarketplaceCondition( question_id=None, negate=True, value_type=ConditionValueType.RECONTACT, values=["g4"], ) - assert c.evaluate_criterion(user_qas=dict(), user_groups=user_groups) + assert c.evaluate_criterion(user_qas={}, user_groups=user_groups) diff --git a/tests/models/thl/test_payout_format.py b/tests/models/thl/test_payout_format.py index dc91f39..83fde25 100644 --- a/tests/models/thl/test_payout_format.py +++ b/tests/models/thl/test_payout_format.py @@ -2,8 +2,8 @@ import pytest from pydantic import BaseModel from generalresearch.models.thl.payout_format import ( - PayoutFormatType, PayoutFormatField, + PayoutFormatType, format_payout_format, ) @@ -20,16 +20,16 @@ class TestPayoutFormat: PayoutFormatTestClass(payout_format="${payout/100:.2f}") # invalid - with pytest.raises(expected_exception=Exception) as e: + with pytest.raises(expected_exception=ValueError): PayoutFormatTestClass(payout_format="{payout10:,.0f} Points") - with pytest.raises(expected_exception=Exception) as e: + with pytest.raises(expected_exception=ValueError): PayoutFormatTestClass(payout_format="payout:,.0f} Points") - with pytest.raises(expected_exception=Exception): + with pytest.raises(expected_exception=ValueError): PayoutFormatTestClass(payout_format="payout") - with pytest.raises(expected_exception=Exception): + with pytest.raises(expected_exception=ValueError): PayoutFormatTestClass(payout_format="{payout;import sys:.0f}") def test_payout_format(self): diff --git a/tests/models/thl/test_product.py b/tests/models/thl/test_product.py index 52f60c2..5e9b249 100644 --- a/tests/models/thl/test_product.py +++ b/tests/models/thl/test_product.py @@ -1,26 +1,39 @@ import os import shutil -from datetime import datetime, timezone, timedelta +from datetime import datetime, timedelta, timezone from decimal import Decimal -from typing import Optional +from typing import Callable, Optional from uuid import uuid4 import pytest +from dask.distributed import Client as DaskClient from pydantic import ValidationError from generalresearch.currency import USDCent +from generalresearch.incite import GRLDatasets +from generalresearch.incite.mergers.pop_ledger import PopLedgerMerge +from generalresearch.managers.thl.ledger_manager.thl_ledger import ( + ThlLedgerManager, +) +from generalresearch.managers.thl.product import ProductManager from generalresearch.models import Source +from generalresearch.models.gr.business import Business +from generalresearch.models.thl.finance import ProductBalances from generalresearch.models.thl.product import ( - Product, + BrokerageProductPayoutEvent, + BrokerageProductPayoutEventManager, + IntegrationMode, PayoutConfig, PayoutTransformation, + Product, ProfilingConfig, + SourceConfig, SourcesConfig, - IntegrationMode, SupplyConfig, - SourceConfig, SupplyPolicy, ) +from generalresearch.models.thl.session import Session +from generalresearch.models.thl.user import User class TestProduct: @@ -28,11 +41,11 @@ class TestProduct: def test_init(self): # By default, just a Pydantic instance doesn't have an id_int instance = Product.model_validate( - dict( - id="968a9acc79b74b6fb49542d82516d284", - name="test-968a9acc", - redirect_url="https://www.google.com/hey", - ) + obj={ + "id": "968a9acc79b74b6fb49542d82516d284", + "name": "test-968a9acc", + "redirect_url": "https://www.google.com/hey", + } ) assert instance.id_int is None @@ -40,29 +53,31 @@ class TestProduct: # We're not excluding anything here, only in the "*Out" variants assert "id_int" in res - def test_init_db(self, product_manager): + def test_init_db(self, product_manager: ProductManager): # By default, just a Pydantic instance doesn't have an id_int instance = product_manager.create_dummy() assert isinstance(instance.id_int, int) res = instance.model_dump_json() + assert isinstance(res, Product) # we json skip & exclude res = instance.model_dump() + assert isinstance(res, Product) def test_redirect_url(self): p = Product.model_validate( - dict( - id="968a9acc79b74b6fb49542d82516d284", - created="2023-09-21T22:13:09.274672Z", - commission_pct=Decimal("0.05"), - enabled=True, - sources=[{"name": "d", "active": True}], - name="test-968a9acc", - max_session_len=600, - team_id="8b5e94afd8a246bf8556ad9986486baa", - redirect_url="https://www.google.com/hey", - ) + obj={ + "id": "968a9acc79b74b6fb49542d82516d284", + "created": "2023-09-21T22:13:09.274672Z", + "commission_pct": Decimal("0.05"), + "enabled": True, + "sources": [{"name": "d", "active": True}], + "name": "test-968a9acc", + "max_session_len": 600, + "team_id": "8b5e94afd8a246bf8556ad9986486baa", + "redirect_url": "https://www.google.com/hey", + } ) with pytest.raises(expected_exception=ValidationError): @@ -99,14 +114,14 @@ class TestProduct: p.harmonizer_domain = "https://profile.generalresearch.com/" p.harmonizer_domain = "https://profile.generalresearch.com" assert p.harmonizer_domain == "https://profile.generalresearch.com/" - with pytest.raises(expected_exception=Exception): + with pytest.raises(expected_exception=ValueError): p.harmonizer_domain = "" - with pytest.raises(expected_exception=Exception): + with pytest.raises(expected_exception=ValueError): p.harmonizer_domain = None - with pytest.raises(expected_exception=Exception): + with pytest.raises(expected_exception=ValueError): # no https p.harmonizer_domain = "http://profile.generalresearch.com" - with pytest.raises(expected_exception=Exception): + with pytest.raises(expected_exception=ValueError): # "/a" at the end p.harmonizer_domain = "https://profile.generalresearch.com/a" @@ -201,23 +216,29 @@ class TestProduct: assert p.calculate_user_payment( Decimal("0.10"), user_wallet_balance=Decimal(0) ) == Decimal("0.07") + assert p.calculate_user_payment( Decimal("1.05"), user_wallet_balance=Decimal(0) ) == Decimal("0.97") + assert p.calculate_user_payment( Decimal(".05"), user_wallet_balance=Decimal(1) ) == Decimal("0.02") + # final balance will be <0, so pay the full amount assert p.calculate_user_payment( Decimal(".50"), user_wallet_balance=Decimal(-1) ) == p.calculate_user_payment(Decimal("0.50")) + # final balance will be >0, so do the 7c rounding - assert p.calculate_user_payment( + res1 = p.calculate_user_payment( Decimal(".50"), user_wallet_balance=Decimal("-0.10") - ) == ( - p.calculate_user_payment(Decimal(".40"), user_wallet_balance=Decimal(0)) - - Decimal("-0.10") ) + res2 = p.calculate_user_payment( + bp_payout=Decimal(".40"), user_wallet_balance=Decimal(0) + ) + assert res2 + assert res1 == (res2 - Decimal("-0.10")) def test_payout_xform_none(self): p = Product( @@ -568,34 +589,26 @@ class TestProductFinancials: def test_balance( self, - business, - product_factory, - user_factory, - mnt_filepath, - bp_payout_factory, - thl_lm, - lm, - duration, - offset, - thl_redis_config, - start, - thl_web_rr, - brokerage_product_payout_event_manager, - session_with_tx_factory, + business: Business, + product_factory: Callable[..., Product], + user_factory: Callable[..., User], + mnt_filepath: GRLDatasets, + bp_payout_factory: Callable[..., BrokerageProductPayoutEvent], + thl_lm: ThlLedgerManager, + start: datetime, + brokerage_product_payout_event_manager: BrokerageProductPayoutEventManager, + session_with_tx_factory: Callable[..., Session], delete_ledger_db, create_main_accounts, - client_no_amm, + client_no_amm: DaskClient, ledger_collection, - pop_ledger_merge, + pop_ledger_merge: PopLedgerMerge, delete_df_collection, ): delete_ledger_db() create_main_accounts() delete_df_collection(coll=ledger_collection) - from generalresearch.models.thl.product import Product - from generalresearch.models.thl.user import User - from generalresearch.models.thl.finance import ProductBalances from generalresearch.currency import USDCent p1: Product = product_factory(business=business) @@ -759,20 +772,16 @@ class TestProductBalance: def test_inconsistent( self, - product, - mnt_filepath, - thl_lm, - client_no_amm, - thl_redis_config, - brokerage_product_payout_event_manager, + product: Product, + mnt_filepath: GRLDatasets, + thl_lm: ThlLedgerManager, + client_no_amm: DaskClient, delete_ledger_db, create_main_accounts, delete_df_collection, ledger_collection, - business, - user_factory, - product_factory, - session_with_tx_factory, + user_factory: Callable[..., User], + session_with_tx_factory: Callable[..., Session], pop_ledger_merge, start, bp_payout_factory, @@ -817,22 +826,18 @@ class TestProductBalance: def test_not_inconsistent( self, - product, + product: Product, mnt_filepath, - thl_lm, - client_no_amm, - thl_redis_config, - brokerage_product_payout_event_manager, + thl_lm: ThlLedgerManager, + client_no_amm: DaskClient, delete_ledger_db, create_main_accounts, delete_df_collection, ledger_collection, - business, - user_factory, - product_factory, + user_factory: Callable[..., User], session_with_tx_factory, - pop_ledger_merge, - start, + pop_ledger_merge: PopLedgerMerge, + start: datetime, bp_payout_factory, payout_event_manager, ): @@ -896,22 +901,16 @@ class TestProductPOPFinancial: self, product, mnt_filepath, - thl_lm, + thl_lm: ThlLedgerManager, client_no_amm, - thl_redis_config, - brokerage_product_payout_event_manager, delete_ledger_db, create_main_accounts, delete_df_collection, ledger_collection, - business, - user_factory, - product_factory, + user_factory: Callable[..., User], session_with_tx_factory, - pop_ledger_merge, - start, - bp_payout_factory, - payout_event_manager, + pop_ledger_merge: PopLedgerMerge, + start: datetime, ): # This is very similar to the test_complete_payout_pq_inconsistent # test, however this time we're only going to assign the payout @@ -975,22 +974,20 @@ class TestProductCache: def test_basic( self, - product, + product: Product, mnt_filepath, thl_lm, - client_no_amm, + client_no_amm: DaskClient, thl_redis_config, brokerage_product_payout_event_manager, delete_ledger_db, create_main_accounts, delete_df_collection, ledger_collection, - business, - user_factory, - product_factory, + user_factory: Callable[..., User], session_with_tx_factory, - pop_ledger_merge, - start, + pop_ledger_merge: PopLedgerMerge, + start: datetime, ): # Now let's load it up and actually test some things delete_ledger_db() @@ -999,7 +996,7 @@ class TestProductCache: # Confirm the default / null behavior rc = thl_redis_config.create_redis_client() - res: Optional[str] = rc.get(product.cache_key) + res: str | None = rc.get(product.cache_key) assert res is None with pytest.raises(expected_exception=AssertionError): product.set_cache( @@ -1034,13 +1031,14 @@ class TestProductCache: ) # Fetch from cache and assert the instance loaded from redis - res: Optional[str] = rc.get(product.cache_key) + res: str | None = rc.get(product.cache_key) assert isinstance(res, str) from generalresearch.models.thl.ledger import LedgerAccount assert isinstance(product.bp_account, LedgerAccount) p1: Product = Product.model_validate_json(res) + assert isinstance(p1.balance, ProductBalances) assert p1.balance.product_id == product.uuid assert p1.balance.payout_usd_str == "$0.71" assert p1.balance.retainer_usd_str == "$0.17" @@ -1048,22 +1046,20 @@ class TestProductCache: def test_neg_balance_cache( self, - product, + product: Product, mnt_filepath, thl_lm, - client_no_amm, + client_no_amm: DaskClient, thl_redis_config, brokerage_product_payout_event_manager, delete_ledger_db, create_main_accounts, delete_df_collection, ledger_collection, - business, - user_factory, - product_factory, + user_factory: Callable[..., User], session_with_tx_factory, - pop_ledger_merge, - start, + pop_ledger_merge: PopLedgerMerge, + start: datetime, bp_payout_factory, payout_event_manager, adj_to_fail_with_tx_factory, diff --git a/tests/models/thl/test_product_userwalletconfig.py b/tests/models/thl/test_product_userwalletconfig.py index 4583c46..4f6a6cc 100644 --- a/tests/models/thl/test_product_userwalletconfig.py +++ b/tests/models/thl/test_product_userwalletconfig.py @@ -4,7 +4,6 @@ from random import shuffle as rshuffle from generalresearch.models.thl.product import ( UserWalletConfig, ) - from generalresearch.models.thl.wallet import PayoutType diff --git a/tests/models/thl/test_soft_pair.py b/tests/models/thl/test_soft_pair.py index bac0e8d..588847e 100644 --- a/tests/models/thl/test_soft_pair.py +++ b/tests/models/thl/test_soft_pair.py @@ -4,8 +4,8 @@ from generalresearch.models.thl.soft_pair import SoftPairResult, SoftPairResultT def test_model(): from generalresearch.models.dynata.survey import ( - DynataCondition, ConditionValueType, + DynataCondition, ) c1 = DynataCondition( diff --git a/tests/models/thl/test_upkquestion.py b/tests/models/thl/test_upkquestion.py index e67427e..d32875c 100644 --- a/tests/models/thl/test_upkquestion.py +++ b/tests/models/thl/test_upkquestion.py @@ -9,8 +9,12 @@ class TestUpkQuestion: UPKImportance, ) - ui = UPKImportance(task_score=1, task_count=None) - ui = UPKImportance(task_score=0) + res = UPKImportance(task_score=1, task_count=None) + assert isinstance(res, UPKImportance) + + res = UPKImportance(task_score=0) + assert isinstance(res, UPKImportance) + with pytest.raises(ValidationError) as e: UPKImportance(task_score=-1) assert "Input should be greater than or equal to 0" in str(e.value) @@ -27,11 +31,11 @@ class TestUpkQuestion: def test_mc(self): from generalresearch.models.thl.profiling.upk_question import ( + UpkQuestion, UpkQuestionChoice, + UpkQuestionConfigurationMC, UpkQuestionSelectorMC, UpkQuestionType, - UpkQuestion, - UpkQuestionConfigurationMC, ) q = UpkQuestion( @@ -123,12 +127,12 @@ class TestUpkQuestion: def test_te(self): from generalresearch.models.thl.profiling.upk_question import ( - UpkQuestionType, + PatternValidation, UpkQuestion, + UpkQuestionConfigurationTE, UpkQuestionSelectorTE, + UpkQuestionType, UpkQuestionValidation, - PatternValidation, - UpkQuestionConfigurationTE, ) q = UpkQuestion( @@ -223,10 +227,10 @@ class TestUpkQuestion: def test_order(self): from generalresearch.models.thl.profiling.upk_question import ( + UpkQuestion, UpkQuestionChoice, UpkQuestionSelectorMC, UpkQuestionType, - UpkQuestion, order_exclusive_options, ) @@ -296,7 +300,7 @@ class TestUpkQuestionValidateAnswer: answer = ("0", "1") assert question.validate_question_answer(answer) == ( False, - "Single Answer MC question with >1 selected " "answers", + "Single Answer MC question with >1 selected answers", ) def test_validate_answer_MA(self): diff --git a/tests/models/thl/test_user.py b/tests/models/thl/test_user.py index 4f10861..943ae8e 100644 --- a/tests/models/thl/test_user.py +++ b/tests/models/thl/test_user.py @@ -1,7 +1,8 @@ import json -from datetime import datetime, timezone, timedelta +from datetime import datetime, timedelta, timezone from decimal import Decimal -from random import randint, choice as rand_choice +from random import choice as rand_choice +from random import randint from uuid import uuid4 import pytest @@ -100,11 +101,6 @@ class TestUserProductID: assert "1 validation error for User" in str(cm.value) assert "Input should be a valid string" in str(cm.value) - with pytest.raises(expected_exception=ValueError) as cm: - User(user_id=self.user_id, product_id=Decimal("0")) - assert "1 validation error for User" in str(cm.value) - assert "Input should be a valid string" in str(cm.value) - def test_empty(self): from generalresearch.models.thl.user import User @@ -120,8 +116,8 @@ class TestUserProductID: product_id = uuid4().hex[:31] with pytest.raises(expected_exception=ValueError) as cm: User(user_id=self.user_id, product_id=product_id) - assert "1 validation error for User", str(cm.value) - assert "String should have at least 32 characters", str(cm.value) + assert "1 validation error for User" in str(cm.value) + assert "String should have at least 32 characters" in str(cm.value) product_id = uuid4().hex * 2 with pytest.raises(ValueError) as cm: @@ -315,7 +311,7 @@ class TestUserUUID: with pytest.raises(ValueError) as cm: User(user_id=self.user_id, uuid=Decimal("0")) - assert "1 validation error for User", str(cm.value) + assert "1 validation error for User" in str(cm.value) assert "Input should be a valid string" in str(cm.value) def test_empty(self): @@ -323,8 +319,8 @@ class TestUserUUID: with pytest.raises(ValueError) as cm: User(user_id=self.user_id, uuid="") - assert "1 validation error for User", str(cm.value) - assert "String should have at least 32 characters", str(cm.value) + assert "1 validation error for User" in str(cm.value) + assert "String should have at least 32 characters" in str(cm.value) def test_invalid_len(self): from generalresearch.models.thl.user import User diff --git a/tests/models/thl/test_user_iphistory.py b/tests/models/thl/test_user_iphistory.py index 46018e0..596849c 100644 --- a/tests/models/thl/test_user_iphistory.py +++ b/tests/models/thl/test_user_iphistory.py @@ -1,4 +1,4 @@ -from datetime import timezone, datetime, timedelta +from datetime import datetime, timedelta, timezone from generalresearch.models.thl.user_iphistory import ( UserIPHistory, diff --git a/tests/models/thl/test_user_streak.py b/tests/models/thl/test_user_streak.py index 72efd05..0cacd3e 100644 --- a/tests/models/thl/test_user_streak.py +++ b/tests/models/thl/test_user_streak.py @@ -1,14 +1,14 @@ from datetime import datetime, timedelta -from zoneinfo import ZoneInfo import pytest from pydantic import ValidationError +from zoneinfo import ZoneInfo from generalresearch.models.thl.user_streak import ( - UserStreak, - StreakPeriod, StreakFulfillment, + StreakPeriod, StreakState, + UserStreak, ) diff --git a/tests/models/thl/test_wall.py b/tests/models/thl/test_wall.py index 057aad2..8398c81 100644 --- a/tests/models/thl/test_wall.py +++ b/tests/models/thl/test_wall.py @@ -1,4 +1,4 @@ -from datetime import datetime, timezone, timedelta +from datetime import datetime, timedelta, timezone from decimal import Decimal from uuid import uuid4 @@ -76,7 +76,7 @@ class TestWall: ) assert "If status is f, status_code_1 should be in" in str(e.value) - with pytest.raises(expected_exception=ValidationError) as cm: + with pytest.raises(expected_exception=ValidationError): Wall( user_id=1, source=Source.DYNATA, diff --git a/tests/models/thl/test_wall_session.py b/tests/models/thl/test_wall_session.py index ab140e9..1208c56 100644 --- a/tests/models/thl/test_wall_session.py +++ b/tests/models/thl/test_wall_session.py @@ -1,4 +1,4 @@ -from datetime import datetime, timezone, timedelta +from datetime import datetime, timedelta, timezone from decimal import Decimal import pytest diff --git a/tests/wall_status_codes/test_analyze.py b/tests/wall_status_codes/test_analyze.py index da6efb3..fa53dbb 100644 --- a/tests/wall_status_codes/test_analyze.py +++ b/tests/wall_status_codes/test_analyze.py @@ -1,4 +1,4 @@ -from generalresearch.models.thl.definitions import StatusCode1, Status +from generalresearch.models.thl.definitions import Status, StatusCode1 from generalresearch.wall_status_codes import innovate @@ -16,43 +16,35 @@ class TestInnovate: assert status_code_2 is None def test_unknown(self): - status, status_code_1, status_code_2 = innovate.annotate_status_code( - "69420", None - ) + status, status_code_1, _ = innovate.annotate_status_code("69420", None) assert Status.FAIL == status assert StatusCode1.UNKNOWN == status_code_1 - status, status_code_1, status_code_2 = innovate.annotate_status_code( - "69420", "Speeder" - ) + status, status_code_1, _ = innovate.annotate_status_code("69420", "Speeder") assert Status.FAIL == status assert StatusCode1.UNKNOWN == status_code_1 def test_ps(self): - status, status_code_1, status_code_2 = innovate.annotate_status_code("5", None) + status, status_code_1, _ = innovate.annotate_status_code("5", None) assert Status.FAIL == status assert StatusCode1.PS_FAIL == status_code_1 # The ext_status_code_2 should reclassify this as PS_FAIL - status, status_code_1, status_code_2 = innovate.annotate_status_code( - "8", "DeviceType" - ) + status, status_code_1, _ = innovate.annotate_status_code("8", "DeviceType") assert Status.FAIL == status assert StatusCode1.PS_FAIL == status_code_1 # this should be reclassified from PS_FAIL to PS_OQ - status, status_code_1, status_code_2 = innovate.annotate_status_code( - "5", "Group NA" - ) + status, status_code_1, _ = innovate.annotate_status_code("5", "Group NA") assert Status.FAIL == status assert StatusCode1.PS_OVERQUOTA == status_code_1 def test_dupe(self): # innovate calls it a quality, should be dupe - status, status_code_1, status_code_2 = innovate.annotate_status_code( + status, status_code_1, _ = innovate.annotate_status_code( "8", "Duplicated to token Tq2SwRVX7PUWnFunGPAYWHk" ) assert Status.FAIL == status assert StatusCode1.PS_DUPLICATE == status_code_1 # stay as quality - status, status_code_1, status_code_2 = innovate.annotate_status_code( + status, status_code_1, _ = innovate.annotate_status_code( "8", "Selected threat potential score at joblevel not allow the survey" ) assert Status.FAIL == status |
