Skip to content

Commit

Permalink
Add spam/ham metrics for OOPSpam and Akismet with FK join fix, test c…
Browse files Browse the repository at this point in the history
…leanup
  • Loading branch information
Uditi Mehta authored and Uditi Mehta committed Oct 28, 2024
1 parent 0095797 commit 418499e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions osf/external/askismet/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_flagged_count(self, start_date, end_date):
action=NodeLog.FLAG_SPAM,
created__gt=start_date,
created__lt=end_date,
spam_data__who_flagged='akismet'
node__spam_data__who_flagged__in=['akismet', 'both']
).count()

return flagged_count
Expand All @@ -153,7 +153,7 @@ def get_hammed_count(self, start_date, end_date):
action=NodeLog.CONFIRM_HAM,
created__gt=start_date,
created__lt=end_date,
spam_data__who_flagged='akismet'
node__spam_data__who_flagged__in=['akismet', 'both']
).count()

return hammed_count
4 changes: 2 additions & 2 deletions osf/external/oopspam/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_flagged_count(self, start_date, end_date):
action=NodeLog.FLAG_SPAM,
created__gt=start_date,
created__lt=end_date,
spam_data__who_flagged='oopspam'
node__spam_data__who_flagged__in=['oopspam', 'both']
).count()

return flagged_count
Expand All @@ -65,7 +65,7 @@ def get_hammed_count(self, start_date, end_date):
action=NodeLog.CONFIRM_HAM,
created__gt=start_date,
created__lt=end_date,
spam_data__who_flagged='oopspam'
node__spam_data__who_flagged__in=['oopspam', 'both']
).count()

return hammed_count
1 change: 0 additions & 1 deletion osf_tests/external/akismet/test_akismet.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,3 @@ def test_get_hammed_count(self, mock_filter, user):
spam_data__who_flagged='akismet'
)
assert hammed_count == 4

41 changes: 21 additions & 20 deletions osf_tests/metrics/test_spam_count_reporter.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
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
from unittest import mock

@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
def mock_oopspam_client():
with mock.patch('osf.external.oopspam.client.OOPSpamClient') as mock_client:
instance = mock_client.return_value
instance.get_flagged_count.return_value = 10
instance.get_hammed_count.return_value = 5
yield instance

@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
def mock_akismet_client():
with mock.patch('osf.external.askismet.client.AkismetClient') as mock_client:
instance = mock_client.return_value
instance.get_flagged_count.return_value = 20
instance.get_hammed_count.return_value = 10
yield instance

@pytest.fixture
def mock_nodelog_model(mocker):
mock = mocker.patch('osf.models.NodeLog')
mock.filter.return_value.count.return_value = 100
return mock
def mock_nodelog_model():
with mock.patch('osf.models.NodeLog') as mock_nodelog:
mock_nodelog.objects.filter.return_value.count.return_value = 100
yield mock_nodelog

@pytest.fixture
def mock_preprintlog_model(mocker):
mock = mocker.patch('osf.models.PreprintLog')
mock.filter.return_value.count.return_value = 50
return mock
def mock_preprintlog_model():
with mock.patch('osf.models.PreprintLog') as mock_preprintlog:
mock_preprintlog.objects.filter.return_value.count.return_value = 50
yield mock_preprintlog

def test_spam_count_reporter(mock_oopspam_client, mock_akismet_client, mock_nodelog_model, mock_preprintlog_model):
report_month = datetime.datetime(2024, 10, 1)
Expand Down

0 comments on commit 418499e

Please sign in to comment.