<commit_before>import unittest
import fakeredis
from uuid import uuid4 as uuid
import logging

from gridchat.env import env, ConfigKeys
from gridchat import rkeys

redis = fakeredis.FakeStrictRedis()
env.config = dict()
env.config[ConfigKeys.REDIS] = redis
env.config[ConfigKeys.TESTING] = True
env.config[ConfigKeys.SESSION] = dict()
env.config[ConfigKeys.SESSION]['user_id'] = '1234'

from gridchat import api

logging.basicConfig(level='DEBUG')
logger = logging.getLogger(__name__)


class ApiLoginTest(unittest.TestCase):
    USER_ID = '1234'
    USER_NAME = 'Joe'
    ROOM_ID = USER_ID
    ROOM_NAME = USER_ID
    AGE = '30'
    GENDER = 'f'
    MEMBERSHIP = '0'
    IMAGE = 'y'
    HAS_WEBCAM = 'y'
    FAKE_CHECKED = 'n'
    COUNTRY = 'cn'
    CITY = 'Shanghai'

    users_in_room = set()

    @staticmethod
    def emit(event, *args, **kwargs):
        pass

    @staticmethod
    def join_room(room):
        ApiLoginTest.users_in_room.add(ApiLoginTest.USER_ID)

    def setUp(self):
        redis.flushall()
        redis.set(rkeys.room_name_for_id(ApiLoginTest.ROOM_ID), ApiLoginTest.ROOM_NAME)
        ApiLoginTest.users_in_room.clear()

        env.emit = ApiLoginTest.emit
        env.join_room = ApiLoginTest.join_room
        env.redis = redis
        env.session.clear()

    def test_login(self):
        self.assert_login_succeeds()

    def test_login_session_contains_user_id(self):
        self.assert_not_in_session('user_id', ApiLoginTest.USER_ID)
        self.login()
        self.assert_in_session('user_id', ApiLoginTest.USER_ID)

    def test_login_session_contains_user_name(self):
        self.assert_not_in_session('user_name', ApiLoginTest.USER_NAME)
        self.login()
        self.assert_in_session('user_name', ApiLoginTest.USER_NAME)

    def test_login_session_contains_gender(self):
        self.assert_not_in_session('gender', ApiLoginTest.GENDER)
        self.login()
        self.assert_in_session('gender', ApiLoginTest.GENDER)

    def test_login_session_contains_membership(self):
        self.assert_not_in_session('membership', ApiLoginTest.MEMBERSHIP)
        self.login()
        self.assert_in_session('membership', ApiLoginTest.MEMBERSHIP)

    def test_login_session_contains_city(self):
        self.assert_not_in_session('city', ApiLoginTest.CITY)
        self.login()
        self.assert_in_session('city', ApiLoginTest.CITY)

    def test_login_session_contains_country(self):
        self.assert_not_in_session('country', ApiLoginTest.COUNTRY)
        self.login()
        self.assert_in_session('country', ApiLoginTest.COUNTRY)

    def test_login_session_contains_fake_checked(self):
        self.assert_not_in_session('fake_checked', ApiLoginTest.FAKE_CHECKED)
        self.login()
        self.assert_in_session('fake_checked', ApiLoginTest.FAKE_CHECKED)

    def test_login_session_contains_has_webcam(self):
        self.assert_not_in_session('has_webcam', ApiLoginTest.HAS_WEBCAM)
        self.login()
        self.assert_in_session('has_webcam', ApiLoginTest.HAS_WEBCAM)

    def test_login_session_contains_image(self):
        self.assert_not_in_session('image', ApiLoginTest.IMAGE)
        self.login()
        self.assert_in_session('image', ApiLoginTest.IMAGE)

    def test_login_session_contains_age(self):
        self.assert_not_in_session('age', ApiLoginTest.AGE)
        self.login()
        self.assert_in_session('age', ApiLoginTest.AGE)

    def test_login_missing_user_id(self):
        data = self.activity_for_login(skip={'user_id'})
        self.assert_login_fails(data)

    def test_login_missing_user_name(self):
        data = self.activity_for_login(skip={'user_name'})
        self.assert_login_fails(data)

    def test_login_missing_gender(self):
        data = self.activity_for_login(skip={'gender'})
        self.assert_login_fails(data)

    def test_login_missing_age(self):
        data = self.activity_for_login(skip={'age'})<commit_msg>unit tests for missing attachments on actor (user info)<commit_after>import unittest
import fakeredis
from uuid import uuid4 as uuid
import logging

from gridchat.env import env, ConfigKeys
from gridchat import rkeys

redis = fakeredis.FakeStrictRedis()
env.config = dict()
env.config[ConfigKeys.REDIS] = redis
env.config[ConfigKeys.TESTING] = True
env.config[ConfigKeys.SESSION] = dict()
env.config[ConfigKeys.SESSION]['user_id'] = '1234'

from gridchat import api

logging.basicConfig(level='DEBUG')
logger = logging.getLogger(__name__)


class ApiLoginTest(unittest.TestCase):
    USER_ID = '1234'
    USER_NAME = 'Joe'
    ROOM_ID = USER_ID
    ROOM_NAME = USER_ID
    AGE = '30'
    GENDER = 'f'
    MEMBERSHIP = '0'
    IMAGE = 'y'
    HAS_WEBCAM = 'y'
    FAKE_CHECKED = 'n'
    COUNTRY = 'cn'
    CITY = 'Shanghai'

    users_in_room = set()

    @staticmethod
    def emit(event, *args, **kwargs):
        pass

    @staticmethod
    def join_room(room):
        ApiLoginTest.users_in_room.add(ApiLoginTest.USER_ID)

    def setUp(self):
        redis.flushall()
        redis.set(rkeys.room_name_for_id(ApiLoginTest.ROOM_ID), ApiLoginTest.ROOM_NAME)
        ApiLoginTest.users_in_room.clear()

        env.emit = ApiLoginTest.emit
        env.join_room = ApiLoginTest.join_room
        env.redis = redis
        env.session.clear()

    def test_login(self):
        self.assert_login_succeeds()

    def test_login_session_contains_user_id(self):
        self.assert_not_in_session('user_id', ApiLoginTest.USER_ID)
        self.login()
        self.assert_in_session('user_id', ApiLoginTest.USER_ID)

    def test_login_session_contains_user_name(self):
        self.assert_not_in_session('user_name', ApiLoginTest.USER_NAME)
        self.login()
        self.assert_in_session('user_name', ApiLoginTest.USER_NAME)

    def test_login_session_contains_gender(self):
        self.assert_not_in_session('gender', ApiLoginTest.GENDER)
        self.login()
        self.assert_in_session('gender', ApiLoginTest.GENDER)

    def test_login_session_contains_membership(self):
        self.assert_not_in_session('membership', ApiLoginTest.MEMBERSHIP)
        self.login()
        self.assert_in_session('membership', ApiLoginTest.MEMBERSHIP)

    def test_login_session_contains_city(self):
        self.assert_not_in_session('city', ApiLoginTest.CITY)
        self.login()
        self.assert_in_session('city', ApiLoginTest.CITY)

    def test_login_session_contains_country(self):
        self.assert_not_in_session('country', ApiLoginTest.COUNTRY)
        self.login()
        self.assert_in_session('country', ApiLoginTest.COUNTRY)

    def test_login_session_contains_fake_checked(self):
        self.assert_not_in_session('fake_checked', ApiLoginTest.FAKE_CHECKED)
        self.login()
        self.assert_in_session('fake_checked', ApiLoginTest.FAKE_CHECKED)

    def test_login_session_contains_has_webcam(self):
        self.assert_not_in_session('has_webcam', ApiLoginTest.HAS_WEBCAM)
        self.login()
        self.assert_in_session('has_webcam', ApiLoginTest.HAS_WEBCAM)

    def test_login_session_contains_image(self):
        self.assert_not_in_session('image', ApiLoginTest.IMAGE)
        self.login()
        self.assert_in_session('image', ApiLoginTest.IMAGE)

    def test_login_session_contains_age(self):
        self.assert_not_in_session('age', ApiLoginTest.AGE)
        self.login()
        self.assert_in_session('age', ApiLoginTest.AGE)

    def test_login_no_attachments(self):
        data = {
            'actor': {
                'id': ApiLoginTest.USER_ID,
                'summary': ApiLoginTest.USER_NAME,
                'image': {
                    'url': 'http://some-url.com/image.jpg',
                    'width': '120',
                    'height': '120'
                }
            },
            'verb': 'login'
        }
        self.assert_login_fails(data)

    def test_login_missing_all_attachments(self):
        data = {
            'actor': {
                'id': ApiLoginTest.USER_ID,
                'summary': ApiLoginTest.USER_NAME,
                'image': {
                    'url': 'http://some-url.com/image.jpg',
                    'width': '120',
                    'height': '120'
                },
                'attachments': list()
            },
            'verb': 'login'
        }
        self.assert_login_fails(data)

    def test_login_missing_user_id(self):
        data = self.activity_for_login(skip={'user_id'})
        self.assert_login_fails(data)

    def test_login_missing_user_name(self):
        data = self.activity_for_login(skip={'user_name'})
        self.assert_login_fails(data)

    def test_login_missing_gender(self):
        data = self.activity_for_login(skip={'gender'})
        self.assert_login_fails(data)

    def test_login_missing_age(self):
        data = self.activity_for_login(skip={'age'})
{'fraction_non_alphanumeric': 0.10506100316312697, 'fraction_numerical': 0.004066877541798464, 'mean_word_length': 3.1427234440804868, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2228702', 'n_tokens_mistral': 2971, 'n_tokens_neox': 2937, 'n_words': 411}