<commit_before>from adhocracy.tests import TestController
from adhocracy.tests.testtools import tt_make_user


class TestUserController(TestController):

    def _make_one(self):
        from adhocracy.model import Badge, UserBadge

        creator = tt_make_user('creator')
        badged_user = tt_make_user('badged_user')
        badge = Badge.create('testbadge', '#ccc')
        UserBadge.create(badged_user, badge, creator)
        return creator, badged_user, badge

    def test_userbadges_created(self):
        from adhocracy.model import Badge, meta
        # the created badge
        creator, badged_user, badge = self._make_one()
        self.assertEqual(meta.Session.query(Badge).count(), 1)
        queried_badge = meta.Session.query(Badge).first()
        self.assertTrue(badge is queried_badge)
        self.assertEqual(queried_badge.title, 'testbadge')

        # references on the badged user
        self.assertEqual(badged_user.badges, [badge])
        self.assertEqual(badged_user.badges[0].users, [badged_user])
        return badge, badged_user

    def test_remove_badge_from_user(self):
        from adhocracy.model import meta, UserBadge
        creator, badged_user, badge = self._make_one()
        self.assertEqual(badged_user.badges, [badge])
        badged_user.badges.remove(badge)
        self.assertEqual(badged_user.badges, [])
        self.assertEqual(badge.users, [])
        self.assertEqual(meta.Session.query(UserBadge).count(), 0)

    def test_remove_user_from_badge(self):
        from adhocracy.model import meta, UserBadge
        creator, badged_user, badge = self._make_one()
        self.assertEqual(badge.users, [badged_user])
        badge.users.remove(badged_user)
        self.assertEqual(badge.users, [])
        self.assertEqual(badged_user.badges, [])
        self.assertEqual(meta.Session.query(UserBadge).count(), 0)

    def test_to_dict(self):
        creator, badged_user, badge = self._make_one()
        result = badge.to_dict()
        self.assertEqual(result, {'color': '#ccc', 'title': 'testbadge',
                                  'id': 1, 'users': [u'badged_user']})<commit_msg>tests: adjust tests for changes in badges<commit_after>from adhocracy.tests import TestController
from adhocracy.tests.testtools import tt_make_user


class TestUserController(TestController):

    def _make_one(self):
        from adhocracy.model import Badge, UserBadge

        creator = tt_make_user('creator')
        badged_user = tt_make_user('badged_user')
        badge = Badge.create('testbadge', '#ccc', 'description')
        UserBadge.create(badged_user, badge, creator)
        return creator, badged_user, badge

    def test_userbadges_created(self):
        from adhocracy.model import Badge, meta
        # the created badge
        creator, badged_user, badge = self._make_one()
        self.assertEqual(meta.Session.query(Badge).count(), 1)
        queried_badge = meta.Session.query(Badge).first()
        self.assertTrue(badge is queried_badge)
        self.assertEqual(queried_badge.title, 'testbadge')

        # references on the badged user
        self.assertEqual(badged_user.badges, [badge])
        self.assertEqual(badged_user.badges[0].users, [badged_user])
        return badge, badged_user

    def test_remove_badge_from_user(self):
        from adhocracy.model import meta, UserBadge
        creator, badged_user, badge = self._make_one()
        self.assertEqual(badged_user.badges, [badge])
        badged_user.badges.remove(badge)
        self.assertEqual(badged_user.badges, [])
        self.assertEqual(badge.users, [])
        self.assertEqual(meta.Session.query(UserBadge).count(), 0)

    def test_remove_user_from_badge(self):
        from adhocracy.model import meta, UserBadge
        creator, badged_user, badge = self._make_one()
        self.assertEqual(badge.users, [badged_user])
        badge.users.remove(badged_user)
        self.assertEqual(badge.users, [])
        self.assertEqual(badged_user.badges, [])
        self.assertEqual(meta.Session.query(UserBadge).count(), 0)

    def test_to_dict(self):
        creator, badged_user, badge = self._make_one()
        result = badge.to_dict()
        self.assertEqual(result, {'color': '#ccc', 'title': 'testbadge',
                                  'id': 1, 'users': [u'badged_user'],
                                  'display_group': False, 'group': None})
{'fraction_non_alphanumeric': 0.11065759637188209, 'fraction_numerical': 0.0022675736961451248, 'mean_word_length': 3.046788990825688, 'pattern_counts': {'":': 0, '<': 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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1348777', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1360, 'n_words': 248}