Fix distribution_type
This commit is contained in:
parent
bd73f8d250
commit
bd66f3071e
2 changed files with 43 additions and 6 deletions
|
|
@ -521,7 +521,7 @@ class Command(BaseCommand):
|
||||||
options=options,
|
options=options,
|
||||||
)
|
)
|
||||||
|
|
||||||
if broken_dir:
|
if broken_dir is not None:
|
||||||
# File already moved due to validation failure; signal caller to skip further handling.
|
# File already moved due to validation failure; signal caller to skip further handling.
|
||||||
return False, broken_dir
|
return False, broken_dir
|
||||||
|
|
||||||
|
|
@ -648,12 +648,13 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def _get_or_update_benefit(self, benefit_schema: DropBenefitSchema) -> DropBenefit:
|
def _get_or_update_benefit(self, benefit_schema: DropBenefitSchema) -> DropBenefit:
|
||||||
"""Return a DropBenefit, updating stale cached values when needed."""
|
"""Return a DropBenefit, updating stale cached values when needed."""
|
||||||
|
distribution_type: str = (benefit_schema.distribution_type or "").strip()
|
||||||
benefit_defaults: dict[str, str | int | datetime | bool | None] = {
|
benefit_defaults: dict[str, str | int | datetime | bool | None] = {
|
||||||
"name": benefit_schema.name,
|
"name": benefit_schema.name,
|
||||||
"image_asset_url": benefit_schema.image_asset_url,
|
"image_asset_url": benefit_schema.image_asset_url,
|
||||||
"entitlement_limit": benefit_schema.entitlement_limit,
|
"entitlement_limit": benefit_schema.entitlement_limit,
|
||||||
"is_ios_available": benefit_schema.is_ios_available,
|
"is_ios_available": benefit_schema.is_ios_available,
|
||||||
"distribution_type": benefit_schema.distribution_type,
|
"distribution_type": distribution_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if benefit_schema.created_at:
|
if benefit_schema.created_at:
|
||||||
|
|
@ -872,7 +873,7 @@ class Command(BaseCommand):
|
||||||
matched: str | None = detect_non_campaign_keyword(raw_text)
|
matched: str | None = detect_non_campaign_keyword(raw_text)
|
||||||
if matched:
|
if matched:
|
||||||
if not options.get("skip_broken_moves"):
|
if not options.get("skip_broken_moves"):
|
||||||
broken_dir: Path = move_file_to_broken_subdir(
|
broken_dir: Path | None = move_file_to_broken_subdir(
|
||||||
file_path,
|
file_path,
|
||||||
matched,
|
matched,
|
||||||
operation_name=operation_name,
|
operation_name=operation_name,
|
||||||
|
|
@ -916,7 +917,7 @@ class Command(BaseCommand):
|
||||||
if isinstance(parsed_json_local, (dict, list))
|
if isinstance(parsed_json_local, (dict, list))
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
broken_dir: Path = move_failed_validation_file(file_path, operation_name=op_name)
|
broken_dir = move_failed_validation_file(file_path, operation_name=op_name)
|
||||||
return {"success": False, "broken_dir": str(broken_dir)}
|
return {"success": False, "broken_dir": str(broken_dir)}
|
||||||
return {"success": False, "broken_dir": "(skipped)"}
|
return {"success": False, "broken_dir": "(skipped)"}
|
||||||
else:
|
else:
|
||||||
|
|
@ -950,7 +951,7 @@ class Command(BaseCommand):
|
||||||
matched: str | None = detect_non_campaign_keyword(raw_text)
|
matched: str | None = detect_non_campaign_keyword(raw_text)
|
||||||
if matched:
|
if matched:
|
||||||
if not options.get("skip_broken_moves"):
|
if not options.get("skip_broken_moves"):
|
||||||
broken_dir: Path = move_file_to_broken_subdir(
|
broken_dir: Path | None = move_file_to_broken_subdir(
|
||||||
file_path,
|
file_path,
|
||||||
matched,
|
matched,
|
||||||
operation_name=operation_name,
|
operation_name=operation_name,
|
||||||
|
|
@ -1015,7 +1016,7 @@ class Command(BaseCommand):
|
||||||
if isinstance(parsed_json_local, (dict, list))
|
if isinstance(parsed_json_local, (dict, list))
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
broken_dir: Path = move_failed_validation_file(file_path, operation_name=op_name)
|
broken_dir = move_failed_validation_file(file_path, operation_name=op_name)
|
||||||
progress_bar.write(f"{Fore.RED}✗{Style.RESET_ALL} {file_path.name} → {broken_dir}/{file_path.name}")
|
progress_bar.write(f"{Fore.RED}✗{Style.RESET_ALL} {file_path.name} → {broken_dir}/{file_path.name}")
|
||||||
else:
|
else:
|
||||||
progress_bar.write(f"{Fore.RED}✗{Style.RESET_ALL} {file_path.name} (move skipped)")
|
progress_bar.write(f"{Fore.RED}✗{Style.RESET_ALL} {file_path.name} (move skipped)")
|
||||||
|
|
|
||||||
36
twitch/tests/test_better_import_drops.py
Normal file
36
twitch/tests/test_better_import_drops.py
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from twitch.management.commands.better_import_drops import Command
|
||||||
|
from twitch.schemas import DropBenefitSchema
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from twitch.models import DropBenefit
|
||||||
|
|
||||||
|
|
||||||
|
class GetOrUpdateBenefitTests(TestCase):
|
||||||
|
"""Tests for the _get_or_update_benefit method in better_import_drops.Command."""
|
||||||
|
|
||||||
|
def test_defaults_distribution_type_when_missing(self) -> None:
|
||||||
|
"""Ensure importer sets distribution_type to empty string when absent."""
|
||||||
|
command = Command()
|
||||||
|
command.benefit_cache = {}
|
||||||
|
|
||||||
|
benefit_schema: DropBenefitSchema = DropBenefitSchema.model_validate(
|
||||||
|
{
|
||||||
|
"id": "benefit-missing-distribution-type",
|
||||||
|
"name": "Test Benefit",
|
||||||
|
"imageAssetURL": "https://example.com/benefit.png",
|
||||||
|
"entitlementLimit": 1,
|
||||||
|
"isIosAvailable": False,
|
||||||
|
"__typename": "DropBenefit",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
benefit: DropBenefit = command._get_or_update_benefit(benefit_schema) # noqa: SLF001
|
||||||
|
|
||||||
|
benefit.refresh_from_db()
|
||||||
|
assert not benefit.distribution_type
|
||||||
Loading…
Add table
Add a link
Reference in a new issue