Beispiel #1
0
    def test_akismet_api_error(self, switch_is_active_mock, mock_requests):
        switch_is_active_mock.return_value = True
        response = MagicMock()
        response.text = 'invalid'
        response.headers = {'x-akismet-debug-help': 'error msg'}
        mock_requests.post.return_value = response
        params = {'user_ip': '127.0.0.1', 'user_agent': 'test-agent'}

        with self.assertRaises(Exception) as cm:
            akismet_spam_check(**params)

        eq_(cm.exception.message, 'Akismet raised an error: error msg')

        url = 'https://akismet_api_key.rest.akismet.com/1.1/comment-check'
        data = params
        data['blog'] = 'http://example.com'
        mock_requests.post.assert_called_with(url, data=data)
    def test_akismet_api_error(self, switch_is_active_mock, mock_requests):
        switch_is_active_mock.return_value = True
        response = MagicMock()
        response.text = "invalid"
        response.headers = {"x-akismet-debug-help": "error msg"}
        mock_requests.post.return_value = response
        params = {"user_ip": "127.0.0.1", "user_agent": "test-agent"}

        with self.assertRaises(Exception) as cm:
            akismet_spam_check(**params)

        eq_(cm.exception.message, "Akismet raised an error: error msg")

        url = "https://akismet_api_key.rest.akismet.com/1.1/comment-check"
        data = params
        data["blog"] = "http://example.com"
        mock_requests.post.assert_called_with(url, data=data)
Beispiel #3
0
    def test_akismet_api_ham(self, switch_is_active_mock, mock_requests):
        switch_is_active_mock.return_value = True
        response = MagicMock()
        response.text = 'false'
        mock_requests.post.return_value = response
        params = {'user_ip': '127.0.0.1', 'user_agent': 'test-agent'}
        eq_(akismet_spam_check(**params), False)

        url = 'https://akismet_api_key.rest.akismet.com/1.1/comment-check'
        data = params
        data['blog'] = 'http://example.com'
        mock_requests.post.assert_called_with(url, data=data)
    def test_akismet_api_ham(self, switch_is_active_mock, mock_requests):
        switch_is_active_mock.return_value = True
        response = MagicMock()
        response.text = "false"
        mock_requests.post.return_value = response
        params = {"user_ip": "127.0.0.1", "user_agent": "test-agent"}
        eq_(akismet_spam_check(**params), False)

        url = "https://akismet_api_key.rest.akismet.com/1.1/comment-check"
        data = params
        data["blog"] = "http://example.com"
        mock_requests.post.assert_called_with(url, data=data)
Beispiel #5
0
    def test_akismet_api_error(self, switch_is_active_mock, mock_requests):
        switch_is_active_mock.return_value = True
        response = MagicMock()
        response.text = 'invalid'
        response.headers = {
            'x-akismet-debug-help': 'error msg'
        }
        mock_requests.post.return_value = response
        params = {
            'user_ip': '127.0.0.1',
            'user_agent': 'test-agent'
        }

        with self.assertRaises(Exception) as cm:
            akismet_spam_check(**params)

        eq_(cm.exception.message, 'Akismet raised an error: error msg')

        url = 'https://akismet_api_key.rest.akismet.com/1.1/comment-check'
        data = params
        data['blog'] = 'http://example.com'
        mock_requests.post.assert_called_with(url, data=data)
Beispiel #6
0
    def test_akismet_api_ham(self, switch_is_active_mock, mock_requests):
        switch_is_active_mock.return_value = True
        response = MagicMock()
        response.text = 'false'
        mock_requests.post.return_value = response
        params = {
            'user_ip': '127.0.0.1',
            'user_agent': 'test-agent'
        }
        eq_(akismet_spam_check(**params), False)

        url = 'https://akismet_api_key.rest.akismet.com/1.1/comment-check'
        data = params
        data['blog'] = 'http://example.com'
        mock_requests.post.assert_called_with(url, data=data)
def check_spam_account(instance_id, **kwargs):
    """Task to check if profile is spam according to akismet"""
    # Avoid circular dependencies
    from mozillians.users.models import AbuseReport, UserProfile

    spam = akismet_spam_check(**kwargs)
    profile = get_object_or_none(UserProfile, id=instance_id)

    if spam and profile:
        kwargs = {
            'type': AbuseReport.TYPE_SPAM,
            'profile': profile,
            'reporter': None,
            'is_akismet': True,
        }

        AbuseReport.objects.get_or_create(**kwargs)
Beispiel #8
0
def check_spam_account(instance_id, **kwargs):
    """Task to check if profile is spam according to akismet"""
    # Avoid circular dependencies
    from mozillians.users.models import AbuseReport, UserProfile

    spam = akismet_spam_check(**kwargs)
    profile = get_object_or_none(UserProfile, id=instance_id)

    if spam and profile:
        kwargs = {
            'type': AbuseReport.TYPE_SPAM,
            'profile': profile,
            'reporter': None,
            'is_akismet': True,
        }

        AbuseReport.objects.get_or_create(**kwargs)