-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[py-tx] Implement Matched/UpVote/DownVote in ThreatExchange Client API (
- Loading branch information
1 parent
09ea0c4
commit 505b431
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
python-threatexchange/threatexchange/exchanges/clients/fb_threatexchange/tests/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. |
58 changes: 58 additions & 0 deletions
58
...atexchange/threatexchange/exchanges/clients/fb_threatexchange/tests/test_reactions_api.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
from unittest.mock import Mock | ||
import pytest | ||
import requests | ||
import typing as t | ||
|
||
from threatexchange.exchanges.clients.fb_threatexchange.api import ( | ||
ThreatExchangeAPI, | ||
) | ||
|
||
POST_SUCCESS = """ | ||
{ | ||
"succcess": true | ||
} | ||
""" | ||
|
||
POST_SUCCESS_JSON = {"succcess": True} | ||
|
||
|
||
def mock_post_impl(url: str, data: str, **params): | ||
content = POST_SUCCESS | ||
# Void your warantee by messing with requests state | ||
resp = requests.Response() | ||
resp._content = content.encode() | ||
resp.status_code = 200 | ||
resp.content # Set the rest of Request's internal state | ||
return resp | ||
|
||
|
||
def test_matched_upvote_downvote(monkeypatch: pytest.MonkeyPatch): | ||
api = ThreatExchangeAPI("fake api token") | ||
session = None | ||
session = Mock( | ||
strict_spec=["post", "__enter__", "__exit__"], | ||
post=mock_post_impl, | ||
__enter__=lambda _: session, | ||
__exit__=lambda *args: None, | ||
) | ||
monkeypatch.setattr(api, "_get_session", lambda: session) | ||
|
||
result = api.react_matched_threat_descriptor(1234, showURLs=False, dryRun=False) | ||
|
||
assert result[2] == POST_SUCCESS_JSON | ||
assert result[0] is None | ||
assert result[1] is None | ||
|
||
result = api.react_upvote_threat_descriptor(1234, showURLs=False, dryRun=False) | ||
|
||
assert result[2] == POST_SUCCESS_JSON | ||
assert result[0] is None | ||
assert result[1] is None | ||
|
||
result = api.react_downvote_threat_descriptor(1234, showURLs=False, dryRun=False) | ||
|
||
assert result[2] == POST_SUCCESS_JSON | ||
assert result[0] is None | ||
assert result[1] is None |