<commit_before>from gittip.testing import load, serve_request


def participants(foo_starts_suspicious=None):
    participants = ( {"id": "foo"}
                   , {"id": "bar", "is_admin": True}
                    )
    if foo_starts_suspicious is not None:
        participants[0]["is_suspicious"] = foo_starts_suspicious
    return load('participants', *participants)


def toggle_is_suspicious():
    response = serve_request('/foo/toggle-is-suspicious.json', user='bar')
    return response.body


def test_participants_start_out_with_is_suspicious_None():
    with participants() as context:
        actual = context.dump()['participants']['foo']['is_suspicious']
        assert actual is None, actual

def test_toggling_NULL_gives_true():
    with participants() as context:
        toggle_is_suspicious()
        actual = context.diff()['participants']['updates'][1]['is_suspicious']
        assert actual is True, actual

def test_toggling_changes_two_things():
    with participants() as context:
        toggle_is_suspicious()
        actual = context.diff(compact=True)
        assert actual == {'participants': [0,2,0]}, actual

def test_but_the_first_thing_is_just_bars_session():
    with participants() as context:
        toggle_is_suspicious()
        expected = ('bar', ['id', 'session_expires', 'session_token'])
        second = context.diff()['participants']['updates'][0]
        actual = (second['id'], sorted(second.keys()))
        assert actual == expected, actual

def test_toggling_true_gives_false():
    with participants(True) as context:
        toggle_is_suspicious()
        actual = context.diff()['participants']['updates'][1]['is_suspicious']
        assert actual is False, actual

def test_toggling_false_gives_true():
    with participants(False) as context:
        toggle_is_suspicious()
        actual = context.diff()['participants']['updates'][1]['is_suspicious']
        assert actual is True, actual<commit_msg>Trim & convert tests/test_is_suspicious.py to use Harness & TestClient.<commit_after>from nose.tools import assert_equals

from gittip.testing import Harness
from gittip.testing.client import TestClient


class TestIsSuspicious(Harness):
    def setUp(self):
        super(Harness, self).setUp()
        self.make_participant('bar', is_admin=True)

    def toggle_is_suspicious(self):
        client = TestClient()
        client.get('/foo/toggle-is-suspicious.json', user='bar')

    def test_that_is_suspicious_defaults_to_None(self):
        foo = self.make_participant('foo')
        actual = foo.is_suspicious
        assert_equals(actual, None)

    def test_toggling_NULL_gives_true(self):
        foo = self.make_participant('foo')
        self.toggle_is_suspicious()
        actual = foo.is_suspicious
        assert_equals(actual, True)

    def test_toggling_true_gives_false(self):
        foo = self.make_participant('foo', is_suspicious=True)
        self.toggle_is_suspicious()
        actual = foo.is_suspicious
        assert_equals(actual, False)

    def test_toggling_false_gives_true(self):
        foo = self.make_participant('foo', is_suspicious=False)
        self.toggle_is_suspicious()
        actual = foo.is_suspicious
        assert_equals(actual, True)
{'fraction_non_alphanumeric': 0.11282367447595561, 'fraction_numerical': 0.002466091245376079, 'mean_word_length': 3.675792507204611, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2616810', 'n_tokens_mistral': 1048, 'n_tokens_neox': 966, 'n_words': 189}