Ejemplo n.º 1
0
    def test_serialization(self):
        user_a = User()
        user_a.id = self.id_manager.get_id()
        user_a.name = 'user_a'

        user_b = User()
        user_b.id = self.id_manager.get_id()
        user_b.name = 'user_b'

        user_names = ['user_a', 'user_b']

        self.assertTrue(self.room.add_user(user_a))
        self.assertTrue(self.room.add_user(user_b))

        serialized = self.room.serialize(only_usernames=True)

        self.assertEqual(serialized['users'], user_names)
        self.assertEqual(serialized['id'], 0)
        self.assertFalse(serialized['inGame'])

        serialized = self.room.serialize(only_usernames=False)

        self.assertEqual('user_a', serialized['users'][0]['name'])
        self.assertEqual(0, serialized['users'][0]['id'])

        self.assertEqual('user_b', serialized['users'][1]['name'])
        self.assertEqual(1, serialized['users'][1]['id'])
Ejemplo n.º 2
0
    def test_add_user(self):
        user_a = User()
        user_a.id = self.id_manager.get_id()
        user_a.name = 'user_a'

        self.assertTrue(self.room.add_user(user_a))
        self.assertEqual(user_a, self.room.users[0])
Ejemplo n.º 3
0
    def test_serialization(self):
        user = User()
        user.id = 1
        user.name = 'Franco'
        serialized_user = user.serialize()

        self.assertEqual(serialized_user['name'], 'Franco')
        self.assertEqual(serialized_user['id'], 1)