Skip to content

[pytx] Shared fake SignalExchangeAPI for tests - #2039

Merged
Dcallies merged 3 commits into
meta:mainfrom
Dcallies:test_exchange_cleanup
Nov 9, 2026
Merged

Dcallies merged 3 commits into
meta:mainfrom
Dcallies:test_exchange_cleanup

Conversation

@Dcallies

@Dcallies Dcallies commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Summary

AI-driven refactor to try and consolodate some common functionality. Not sure how to combat the slop that Claude seems to love to add to these tests.

[Slop]:

test_state.py and test_local_dbm.py each defined their own fake exchanges, repeating the same boilerplate (config/checkpoint/record classes, for_collab, scripted fetch_iter, collab factory, and # type: ignore[list-item] on exchange class lists).

Move them into threatexchange/exchanges/tests/fake_exchange.py:

  • FakeExchangeAPIBase: boilerplate + scripted fetches + make_collab()
  • FakeSimpleUpdatesAPI: keyed by (signal_type, signal)
  • FakeIdKeyedAPI / FakeIdRecord: keyed by int id, NCMEC-like, with tombstone deletes and per-owner opinions
  • exchange_types(): typed list of exchange classes

Test Plan

pytest & mypy

test_state.py and test_local_dbm.py each defined their own fake
exchanges, repeating the same boilerplate (config/checkpoint/record
classes, for_collab, scripted fetch_iter, collab factory, and
`# type: ignore[list-item]` on exchange class lists).

Move them into threatexchange/exchanges/tests/fake_exchange.py:
- FakeExchangeAPIBase: boilerplate + scripted fetches + make_collab()
- FakeSimpleUpdatesAPI: keyed by (signal_type, signal)
- FakeIdKeyedAPI / FakeIdRecord: keyed by int id, NCMEC-like, with
  tombstone deletes and per-owner opinions
- exchange_types(): typed list of exchange classes

cli/tests/fake_extension.py is unchanged; its custom config class is
what that test exercises.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@meta-cla meta-cla Bot added the CLA Signed label Nov 9, 2026
@github-actions github-actions Bot added the python-threatexchange Items related to the threatexchange python tool / library label Nov 9, 2026
@Dcallies
Dcallies merged commit c91e539 into meta:main Nov 9, 2026
5 checks passed
@Dcallies
Dcallies deleted the test_exchange_cleanup branch November 9, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed python-threatexchange Items related to the threatexchange python tool / library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant