Skip to content

Enforce unique provider slugs (closes #3628) - #3712

Open
Karlhezenberg wants to merge 1 commit into
Chain-Love:json-toolsfrom
Karlhezenberg:fix/unique-provider-slugs-3628
Open

Enforce unique provider slugs (closes #3628)#3712
Karlhezenberg wants to merge 1 commit into
Chain-Love:json-toolsfrom
Karlhezenberg:fix/unique-provider-slugs-3628

Conversation

@Karlhezenberg

Copy link
Copy Markdown
Contributor

Summary

This PR adds a uniqueness validation for provider slugs in csv_to_json.py. Previously, two providers with the same slug would silently overwrite each other during JSON generation. Now, a deterministic ValueError is raised listing the duplicated slug values.

This reuses the existing build_index_by_slug() function already used for offer slug validation — no new function was written.

Changes

  • tools/csv_to_json.py: Added one line calling build_index_by_slug(providers, ...) after loading providers, before building the provider-by-name index
  • tools/test_provider_slugs.py: New unit test file with 13 tests covering:
    • build_index_by_slug(): unique slugs, empty lists, duplicates rejected, error message content, whitespace handling
    • load_providers() + build_index_by_slug(): integration with CSV files
    • csv_to_json.py main(): full integration test

Tests

12 passed, 1 skipped in 0.12s
validate_csv.py: All checks passed.

All existing tests unchanged and green. New tests verify:

  • Duplicates are rejected with clear error message listing duplicated values
  • Unique slugs pass without error
  • Empty/whitespace-only slugs are skipped (not counted as duplicates)
  • Real providers.csv loads without duplicate slugs

Footer

Closes #3628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant