forked from CenterForOpenScience/osf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OOPSpam and Akismet metrics to spam report
- Loading branch information
Uditi Mehta
authored and
Uditi Mehta
committed
Oct 21, 2024
1 parent
0fc98f4
commit 0095797
Showing
7 changed files
with
195 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
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
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
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
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
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
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,43 @@ | ||
import datetime | ||
import pytest | ||
from osf.metrics.reporters.spam_count import SpamCountReporter | ||
from osf.external.oopspam.client import OOPSpamClient | ||
from osf.external.askismet.client import AkismetClient | ||
|
||
@pytest.fixture | ||
def mock_oopspam_client(mocker): | ||
mock = mocker.patch('osf.external.oopspam.client.OOPSpamClient') | ||
mock.get_flagged_count.return_value = 10 | ||
mock.get_hammed_count.return_value = 5 | ||
return mock | ||
|
||
@pytest.fixture | ||
def mock_akismet_client(mocker): | ||
mock = mocker.patch('osf.external.askismet.client.AkismetClient') | ||
mock.get_flagged_count.return_value = 20 | ||
mock.get_hammed_count.return_value = 10 | ||
return mock | ||
|
||
@pytest.fixture | ||
def mock_nodelog_model(mocker): | ||
mock = mocker.patch('osf.models.NodeLog') | ||
mock.filter.return_value.count.return_value = 100 | ||
return mock | ||
|
||
@pytest.fixture | ||
def mock_preprintlog_model(mocker): | ||
mock = mocker.patch('osf.models.PreprintLog') | ||
mock.filter.return_value.count.return_value = 50 | ||
return mock | ||
|
||
def test_spam_count_reporter(mock_oopspam_client, mock_akismet_client, mock_nodelog_model, mock_preprintlog_model): | ||
report_month = datetime.datetime(2024, 10, 1) | ||
reporter = SpamCountReporter() | ||
report = reporter.report(report_month) | ||
|
||
assert report[0].oopspam_flagged == 10 | ||
assert report[0].oopspam_hammed == 5 | ||
assert report[0].akismet_flagged == 20 | ||
assert report[0].akismet_hammed == 10 | ||
assert report[0].node_confirmed_spam == 100 | ||
assert report[0].preprint_confirmed_spam == 50 |