Exemplo n.º 1
0
class TestStress(unittest.TestCase):

	def setUp(self):
		pass

	def tearDown(self):
		pass

	def test_second_system(self):
		start = time.strftime('%S')
		count = 0
		while start == time.strftime('%S'):
			count = count+1
		print "%s calls per second" % str(count)
		self.assertTrue(count > 100000)

	def test_second_ping(self):
		self.client = Client()
	 	self.client.connect_db()
		start = time.strftime('%S')
		count = 0
		while start == time.strftime('%S'):
			count = count+1
			result = self.client.send(b'ping')
		print "%s calls per second" % str(count)
		self.client.connection.close()
		self.assertTrue(count > 1000)
Exemplo n.º 2
0
class TestStress(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_second_system(self):
        start = time.strftime('%S')
        count = 0
        while start == time.strftime('%S'):
            count = count + 1
        print "%s calls per second" % str(count)
        self.assertTrue(count > 100000)

    def test_second_ping(self):
        self.client = Client()
        self.client.connect_db()
        start = time.strftime('%S')
        count = 0
        while start == time.strftime('%S'):
            count = count + 1
            result = self.client.send(b'ping')
        print "%s calls per second" % str(count)
        self.client.connection.close()
        self.assertTrue(count > 1000)
Exemplo n.º 3
0
 def test_second_ping(self):
     self.client = Client()
     self.client.connect_db()
     start = time.strftime('%S')
     count = 0
     while start == time.strftime('%S'):
         count = count + 1
         result = self.client.send(b'ping')
     print "%s calls per second" % str(count)
     self.client.connection.close()
     self.assertTrue(count > 1000)
Exemplo n.º 4
0
class TestChannelSearch(unittest.TestCase):

	def setUp(self):
		self.client = Client()

	def tearDown(self):
		self.client.connection.close()

	def test_simple(self):
		channel = random_channel()
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	self.client.send(b'search %s' % channel)
Exemplo n.º 5
0
class TestPost(unittest.TestCase):

	def setUp(self):
		self.client = Client()

	def test_post_text(self):
		message = 'hello'
		channel = random_channel()
		username = self.client.register_login()
	 	result = self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'join %s' % channel)
	 	post = {
	 		'channel': { 'name':channel },
	 		'user': { 'username':username },
	 		'data': message
	 	}
	 	result = self.client.send(b'post %s %s' % (channel, message))
	 	print result
Exemplo n.º 6
0
	def test_second_ping(self):
		self.client = Client()
	 	self.client.connect_db()
		start = time.strftime('%S')
		count = 0
		while start == time.strftime('%S'):
			count = count+1
			result = self.client.send(b'ping')
		print "%s calls per second" % str(count)
		self.client.connection.close()
		self.assertTrue(count > 1000)
Exemplo n.º 7
0
class TestPost(unittest.TestCase):
    def setUp(self):
        self.client = Client()

    def test_post_text(self):
        message = 'hello'
        channel = random_channel()
        username = self.client.register_login()
        result = self.client.send(b'create %s' % channel)
        result = self.client.send(b'join %s' % channel)
        post = {
            'channel': {
                'name': channel
            },
            'user': {
                'username': username
            },
            'data': message
        }
        result = self.client.send(b'post %s %s' % (channel, message))
        print result
Exemplo n.º 8
0
class TestChannelBan(unittest.TestCase):
    def setUp(self):
        self.client = Client()

    def tearDown(self):
        self.client.connection.close()

    def test_ban(self):
        ban_username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'ban %s %s' % (channel, ban_username))
        self.assertEqual(
            self.client.reply('CHANNEL_BAN', {
                'name': channel,
                "username": ban_username
            }), result)

    def test_ban_not_admin(self):
        channel = random_channel()
        ban_username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'logout')
        username = self.client.register_login()
        result = self.client.send(b'ban %s %s' % (channel, ban_username))
        self.assertEqual(self.client.reply('NO_PERMISSION'), result)

    def test_ban_cannot_join(self):
        channel = random_channel()
        ban_username = random_word()
        ban_password = random_word()
        self.client.register_login(ban_username, ban_password)
        self.client.send(b'logout')
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        self.client.send(b'ban %s %s' % (channel, ban_username))
        self.client.send(b'logout')
        self.client.send(b'login %s %s' % (ban_username, ban_password))
        result = self.client.send(b'join %s' % channel)
        self.assertEqual(
            self.client.reply('CHANNEL_BANNED', {'name': channel}), result)

    def test_ban_cannot_follow(self):
        channel = random_channel()
        ban_username = random_word()
        ban_password = random_word()
        self.client.register_login(ban_username, ban_password)
        self.client.send(b'logout')
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        self.client.send(b'ban %s %s' % (channel, ban_username))
        self.client.send(b'logout')
        self.client.send(b'login %s %s' % (ban_username, ban_password))
        result = self.client.send(b'follow %s' % channel)
        self.assertEqual(
            self.client.reply('CHANNEL_BANNED', {'name': channel}), result)

    def test_ban_add_no_channel(self):
        ban_username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        username = self.client.register_login()
        result = self.client.send(b'ban %s %s' % (channel, ban_username))
        self.assertEqual(
            self.client.reply('CHANNEL_NOT_EXIST', {'name': channel}), result)

    def test_ban_add_exists(self):
        ban_username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'ban %s %s' % (channel, ban_username))
        result = self.client.send(b'ban %s %s' % (channel, ban_username))
        self.assertEqual(
            self.client.reply('CHANNEL_BANNED_ALREADY', {
                'name': channel,
                "username": ban_username
            }), result)

    def test_ban_add_not_admin(self):
        channel = random_channel()
        banned_username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'logout')
        username = self.client.register_login()
        result = self.client.send(b'ban %s %s' % (channel, banned_username))
        self.assertEqual(self.client.reply('NO_PERMISSION'), result)

    def test_unban(self):
        ban_username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'ban %s %s' % (channel, ban_username))
        result = self.client.send(b'unban %s %s' % (channel, ban_username))
        self.assertEqual(
            self.client.reply('CHANNEL_UNBAN', {
                'name': channel,
                "username": ban_username
            }), result)

    def test_ban_not_admin(self):
        channel = random_channel()
        ban_username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'logout')
        username = self.client.register_login()
        result = self.client.send(b'ban %s %s' % (channel, ban_username))
        result = self.client.send(b'unban %s %s' % (channel, ban_username))
        self.assertEqual(self.client.reply('NO_PERMISSION'), result)

    def test_unban_join(self):
        ban_username = random_word()
        ban_password = random_word()
        self.client.register_login(ban_username, ban_password)
        self.client.send(b'logout')

        channel = random_channel()
        self.client.register_login()
        self.client.send(b'create %s' % channel)
        self.client.send(b'ban %s %s' % (channel, ban_username))
        self.client.send(b'unban %s %s' % (channel, ban_username))
        self.client.send(b'logout')
        self.client.send(b'login %s %s' % (ban_username, ban_password))
        result = self.client.send(b'join %s' % channel)
        self.assertEqual(self.client.reply('CHANNEL_JOIN', {'name': channel}),
                         result)
Exemplo n.º 9
0
class TestChannel(unittest.TestCase):
    def setUp(self):
        self.client = Client()

    def test_create(self):
        username = self.client.register_login()
        channel = random_channel()
        result = self.client.send(b'create %s' % channel)
        self.assertEqual('Created %s' % channel, result)

    def test_create_invalid(self):
        username = self.client.register_login()
        channel = random_word()
        result = self.client.send(b'create %s' % channel)
        self.assertEqual(self.client.reply('CHANNEL_INVALID_NAME'), result)

    def test_create_already_exists(self):
        username = self.client.register_login()
        channel = random_channel()
        result = self.client.send(b'create %s' % channel)
        result = self.client.send(b'create %s' % channel)
        self.assertEqual(self.client.reply('CHANNEL_ALREADY_EXISTS'), result)

    def test_create_not_logged_in(self):
        channel = random_channel()
        result = self.client.send(b'create %s' % channel)
        self.assertEqual(self.client.reply('NOT_LOGGED_IN'), result)

    def test_list(self):
        username = self.client.register_login()
        result = self.client.send(b'list')
        self.assertNotEqual(result, 'None')

    def test_join(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'join %s' % name)
        self.assertEqual(self.client.reply('CHANNEL_JOIN', {"name": name}),
                         result)

    def test_part(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'join %s' % name)
        result = self.client.send(b'part %s' % name)
        self.assertEqual(self.client.reply('CHANNEL_PART', {"name": name}),
                         result)

    def test_part_not_joined(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'join %s' % name)
        result = self.client.send(b'part %s' % name)
        result = self.client.send(b'joined')
        self.assertEqual(self.client.reply('USER_JOINED_NONE'), result)

    def test_join_not_exist(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'join %s' % name)
        self.assertEqual(
            self.client.reply('CHANNEL_NOT_EXIST', {"name": name}), result)

    def test_joined_already(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'join %s' % name)
        result = self.client.send(b'join %s' % name)
        self.assertEqual(
            self.client.reply('CHANNEL_JOINED_ALREADY', {"name": name}),
            result)

    def test_follow(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'follow %s' % name)
        self.assertEqual(self.client.reply('CHANNEL_FOLLOW', {"name": name}),
                         result)

    def test_following_already(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'follow %s' % name)
        result = self.client.send(b'follow %s' % name)
        self.assertEqual(
            self.client.reply('CHANNEL_FOLLOWING_ALREADY', {"name": name}),
            result)

    def test_unfollow(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'follow %s' % name)
        result = self.client.send(b'unfollow %s' % name)
        self.assertEqual(self.client.reply('CHANNEL_UNFOLLOW', {"name": name}),
                         result)

    def test_unfollow_not_following(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'unfollow %s' % name)
        self.assertEqual(
            self.client.reply('CHANNEL_UNFOLLOW_NOT_FOLLOWING',
                              {"name": name}), result)

    def test_joined_already(self):
        username = self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'join %s' % name)
        result = self.client.send(b'join %s' % name)
        self.assertEqual(
            self.client.reply('CHANNEL_JOINED_ALREADY', {"name": name}),
            result)

    def test_invite(self):
        username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        self.client.register_login()
        result = self.client.send(b'create %s' % channel)
        result = self.client.send(b'join %s' % channel)
        result = self.client.send(b'invite %s %s' % (channel, username))
        self.assertEqual(
            self.client.reply('CHANNEL_INVITE', {
                "username": username,
                "name": channel
            }), result)

    def test_invite_channel_not_exist(self):
        username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        self.client.register_login()
        result = self.client.send(b'invite %s %s' % (channel, username))
        self.assertEqual(
            self.client.reply('CHANNEL_NOT_EXIST', {"name": channel}), result)

    def test_invite_username_not_exist(self):
        username = random_word()
        channel = random_channel()
        self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'invite %s %s' % (channel, username))
        self.assertEqual(
            self.client.reply('USER_NOT_EXIST', {"username": username}),
            result)

    def test_admins_list(self):
        channel = random_channel()
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'admins %s' % channel)
        self.assertTrue(username in result)

    def test_admins_add(self):
        admin_username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'admin_add %s %s' %
                                  (channel, admin_username))
        self.assertEqual(
            self.client.reply('CHANNEL_ADMINS_ADD', {
                'name': channel,
                "username": admin_username
            }), result)

    def test_admins_add_no_channel(self):
        admin_username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        username = self.client.register_login()
        result = self.client.send(b'admin_add %s %s' %
                                  (channel, admin_username))
        self.assertEqual(
            self.client.reply('CHANNEL_NOT_EXIST', {'name': channel}), result)

    def test_admins_add_exists(self):
        admin_username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'admin_add %s %s' %
                                  (channel, admin_username))
        result = self.client.send(b'admin_add %s %s' %
                                  (channel, admin_username))
        self.assertEqual(
            self.client.reply('CHANNEL_ADMINS_ALREADY', {
                'name': channel,
                "username": admin_username
            }), result)

    def test_admins_add_not_admin(self):
        channel = random_channel()
        admin_username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'logout')
        username = self.client.register_login()
        result = self.client.send(b'admin_add %s %s' %
                                  (channel, admin_username))
        self.assertEqual(self.client.reply('NO_PERMISSION'), result)

    def test_admins_remove(self):
        admin_username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'admin_add %s %s' %
                                  (channel, admin_username))
        result = self.client.send(b'admin_remove %s %s' %
                                  (channel, admin_username))
        self.assertEqual(
            self.client.reply('CHANNEL_ADMINS_REMOVE', {
                'name': channel,
                "username": admin_username
            }), result)

    def test_admins_remove_not_admin(self):
        channel = random_channel()
        admin_username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'logout')
        username = self.client.register_login()
        result = self.client.send(b'admin_remove %s %s' %
                                  (channel, admin_username))
        self.assertEqual(self.client.reply('NO_PERMISSION'), result)

    def test_admins_remove_user_not_added(self):
        admin_username = self.client.register_login()
        result = self.client.send(b'logout')
        channel = random_channel()
        username = self.client.register_login()
        self.client.send(b'create %s' % channel)
        result = self.client.send(b'admin_remove %s %s' %
                                  (channel, admin_username))
        self.assertEqual(
            self.client.reply('CHANNEL_ADMINS_NOT_ADDED', {
                'name': channel,
                "username": admin_username
            }), result)
Exemplo n.º 10
0
 def setUp(self):
     self.client = Client()
Exemplo n.º 11
0
	def setUp(self):
		self.client = Client()
Exemplo n.º 12
0
class TestChannel(unittest.TestCase):

	def setUp(self):
		self.client = Client()

	def test_create(self):
		username = self.client.register_login()
		channel = random_channel()
	 	result = self.client.send(b'create %s' % channel)
	 	self.assertEqual('Created %s' % channel, result)

	def test_create_invalid(self):
		username = self.client.register_login()
		channel = random_word()
	 	result = self.client.send(b'create %s' % channel)
	 	self.assertEqual(self.client.reply('CHANNEL_INVALID_NAME'), result)

	def test_create_already_exists(self):
		username = self.client.register_login()
		channel = random_channel()
	 	result = self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'create %s' % channel)
	 	self.assertEqual(self.client.reply('CHANNEL_ALREADY_EXISTS'), result)

	def test_create_not_logged_in(self):
		channel = random_channel()
	 	result = self.client.send(b'create %s' % channel)
	 	self.assertEqual(self.client.reply('NOT_LOGGED_IN'), result)

	def test_list(self):
		username = self.client.register_login()
	 	result = self.client.send(b'list')
	 	self.assertNotEqual(result,'None')

	def test_join(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'create %s' % name)
	 	result = self.client.send(b'join %s' % name)
	 	self.assertEqual(self.client.reply('CHANNEL_JOIN',{ "name":name }), result)

	def test_part(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'create %s' % name)
	 	result = self.client.send(b'join %s' % name)
	 	result = self.client.send(b'part %s' % name)
	 	self.assertEqual(self.client.reply('CHANNEL_PART',{ "name":name }), result)

	def test_part_not_joined(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'create %s' % name)
	 	result = self.client.send(b'join %s' % name)
	 	result = self.client.send(b'part %s' % name)
	 	result = self.client.send(b'joined')
	 	self.assertEqual(self.client.reply('USER_JOINED_NONE'), result)

	def test_join_not_exist(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'join %s' % name)
	 	self.assertEqual(self.client.reply('CHANNEL_NOT_EXIST', { "name":name }), result)

	def test_joined_already(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'create %s' % name)
	 	result = self.client.send(b'join %s' % name)
	 	result = self.client.send(b'join %s' % name)
	 	self.assertEqual(self.client.reply('CHANNEL_JOINED_ALREADY',{"name":name}), result)

	def test_follow(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'create %s' % name)
	 	result = self.client.send(b'follow %s' % name)
	 	self.assertEqual(self.client.reply('CHANNEL_FOLLOW',{"name":name}), result)

	def test_following_already(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'create %s' % name)
	 	result = self.client.send(b'follow %s' % name)
	 	result = self.client.send(b'follow %s' % name)
	 	self.assertEqual(self.client.reply('CHANNEL_FOLLOWING_ALREADY',{"name":name}), result)

	def test_unfollow(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'create %s' % name)
	 	result = self.client.send(b'follow %s' % name)
	 	result = self.client.send(b'unfollow %s' % name)
	 	self.assertEqual(self.client.reply('CHANNEL_UNFOLLOW',{"name":name}), result)

	def test_unfollow_not_following(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'create %s' % name)
	 	result = self.client.send(b'unfollow %s' % name)
	 	self.assertEqual(self.client.reply('CHANNEL_UNFOLLOW_NOT_FOLLOWING',{ "name":name }), result)

	def test_joined_already(self):
		username = self.client.register_login()
		name = random_channel()
	 	result = self.client.send(b'create %s' % name)
	 	result = self.client.send(b'join %s' % name)
	 	result = self.client.send(b'join %s' % name)
	 	self.assertEqual(self.client.reply('CHANNEL_JOINED_ALREADY',{ "name":name }), result)

	def test_invite(self):
		username = self.client.register_login()
	 	result = self.client.send(b'logout')
		channel = random_channel()
		self.client.register_login()
	 	result = self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'join %s' % channel)
	 	result = self.client.send(b'invite %s %s' % (channel, username))
	 	self.assertEqual(self.client.reply('CHANNEL_INVITE',{ "username": username, "name":channel }), result)

	def test_invite_channel_not_exist(self):
		username = self.client.register_login()
	 	result = self.client.send(b'logout')
		channel = random_channel()
		self.client.register_login()
	 	result = self.client.send(b'invite %s %s' % (channel, username))
	 	self.assertEqual(self.client.reply('CHANNEL_NOT_EXIST',{ "name":channel }), result)

	def test_invite_username_not_exist(self):
		username = random_word()
		channel = random_channel()
		self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'invite %s %s' % (channel, username))
	 	self.assertEqual(self.client.reply('USER_NOT_EXIST',{ "username":username }), result)

	def test_admins_list(self):
		channel = random_channel()
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'admins %s' % channel)
	 	self.assertTrue(username in result)

	def test_admins_add(self):
		admin_username = self.client.register_login()
		result = self.client.send(b'logout')
		channel = random_channel()
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'admin_add %s %s' % (channel, admin_username))
	 	self.assertEqual(self.client.reply('CHANNEL_ADMINS_ADD',{ 'name':channel, "username":admin_username }), result)

	def test_admins_add_no_channel(self):
		admin_username = self.client.register_login()
		result = self.client.send(b'logout')
		channel = random_channel()
		username = self.client.register_login()
	 	result = self.client.send(b'admin_add %s %s' % (channel, admin_username))
	 	self.assertEqual(self.client.reply('CHANNEL_NOT_EXIST',{ 'name':channel }), result)

	def test_admins_add_exists(self):
		admin_username = self.client.register_login()
		result = self.client.send(b'logout')
		channel = random_channel()
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'admin_add %s %s' % (channel, admin_username))
	 	result = self.client.send(b'admin_add %s %s' % (channel, admin_username))
	 	self.assertEqual(self.client.reply('CHANNEL_ADMINS_ALREADY',{ 'name':channel, "username":admin_username }), result)

	def test_admins_add_not_admin(self):
		channel = random_channel()
		admin_username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
		result = self.client.send(b'logout')
		username = self.client.register_login()
	 	result = self.client.send(b'admin_add %s %s' % (channel, admin_username))
	 	self.assertEqual(self.client.reply('NO_PERMISSION'), result)

	def test_admins_remove(self):
		admin_username = self.client.register_login()
		result = self.client.send(b'logout')
		channel = random_channel()
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'admin_add %s %s' % (channel, admin_username))
	 	result = self.client.send(b'admin_remove %s %s' % (channel, admin_username))
	 	self.assertEqual(self.client.reply('CHANNEL_ADMINS_REMOVE',{ 'name':channel, "username":admin_username }), result)

	def test_admins_remove_not_admin(self):
		channel = random_channel()
		admin_username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
		result = self.client.send(b'logout')
		username = self.client.register_login()
	 	result = self.client.send(b'admin_remove %s %s' % (channel, admin_username))
	 	self.assertEqual(self.client.reply('NO_PERMISSION'), result)

	def test_admins_remove_user_not_added(self):
		admin_username = self.client.register_login()
		result = self.client.send(b'logout')
		channel = random_channel()
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'admin_remove %s %s' % (channel, admin_username))
	 	self.assertEqual(self.client.reply('CHANNEL_ADMINS_NOT_ADDED',{ 'name':channel, "username":admin_username }), result)
Exemplo n.º 13
0
 def setUp(self):
     self.client = Client()
     self.client.connect_db()
Exemplo n.º 14
0
class TestChannelBan(unittest.TestCase):

	def setUp(self):
		self.client = Client()

	def tearDown(self):
		self.client.connection.close()

	def test_ban(self):
		ban_username = self.client.register_login()
		result = self.client.send(b'logout')
		channel = random_channel()
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'ban %s %s' % (channel, ban_username))
	 	self.assertEqual(self.client.reply('CHANNEL_BAN',{ 'name':channel, "username":ban_username }), result)

	def test_ban_not_admin(self):
		channel = random_channel()
		ban_username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
		result = self.client.send(b'logout')
		username = self.client.register_login()
	 	result = self.client.send(b'ban %s %s' % (channel, ban_username))
	 	self.assertEqual(self.client.reply('NO_PERMISSION'), result)

	def test_ban_cannot_join(self):
		channel = random_channel()
		ban_username = random_word()
		ban_password = random_word()
		self.client.register_login(ban_username, ban_password)
		self.client.send(b'logout')
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	self.client.send(b'ban %s %s' % (channel, ban_username))
		self.client.send(b'logout')
		self.client.send(b'login %s %s' % (ban_username, ban_password))
	 	result = self.client.send(b'join %s' % channel)
		self.assertEqual(self.client.reply('CHANNEL_BANNED',{ 'name':channel }), result)

	def test_ban_cannot_follow(self):
		channel = random_channel()
		ban_username = random_word()
		ban_password = random_word()
		self.client.register_login(ban_username, ban_password)
		self.client.send(b'logout')
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	self.client.send(b'ban %s %s' % (channel, ban_username))
		self.client.send(b'logout')
		self.client.send(b'login %s %s' % (ban_username, ban_password))
	 	result = self.client.send(b'follow %s' % channel)
		self.assertEqual(self.client.reply('CHANNEL_BANNED',{ 'name':channel }), result)

	def test_ban_add_no_channel(self):
		ban_username = self.client.register_login()
		result = self.client.send(b'logout')
		channel = random_channel()
		username = self.client.register_login()
	 	result = self.client.send(b'ban %s %s' % (channel, ban_username))
	 	self.assertEqual(self.client.reply('CHANNEL_NOT_EXIST',{ 'name':channel }), result)

	def test_ban_add_exists(self):
		ban_username = self.client.register_login()
		result = self.client.send(b'logout')
		channel = random_channel()
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'ban %s %s' % (channel, ban_username))
	 	result = self.client.send(b'ban %s %s' % (channel, ban_username))
	 	self.assertEqual(self.client.reply('CHANNEL_BANNED_ALREADY',{ 'name':channel, "username":ban_username }), result)

	def test_ban_add_not_admin(self):
		channel = random_channel()
		banned_username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
		result = self.client.send(b'logout')
		username = self.client.register_login()
	 	result = self.client.send(b'ban %s %s' % (channel, banned_username))
	 	self.assertEqual(self.client.reply('NO_PERMISSION'), result)

	def test_unban(self):
		ban_username = self.client.register_login()
		result = self.client.send(b'logout')
		channel = random_channel()
		username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	result = self.client.send(b'ban %s %s' % (channel, ban_username))
	 	result = self.client.send(b'unban %s %s' % (channel, ban_username))
	 	self.assertEqual(self.client.reply('CHANNEL_UNBAN',{ 'name':channel, "username":ban_username }), result)

	def test_ban_not_admin(self):
		channel = random_channel()
		ban_username = self.client.register_login()
	 	self.client.send(b'create %s' % channel)
		result = self.client.send(b'logout')
		username = self.client.register_login()
	 	result = self.client.send(b'ban %s %s' % (channel, ban_username))
	 	result = self.client.send(b'unban %s %s' % (channel, ban_username))
	 	self.assertEqual(self.client.reply('NO_PERMISSION'), result)

	def test_unban_join(self):
		ban_username = random_word()
		ban_password = random_word()
		self.client.register_login(ban_username, ban_password)
		self.client.send(b'logout')

		channel = random_channel()
		self.client.register_login()
	 	self.client.send(b'create %s' % channel)
	 	self.client.send(b'ban %s %s' % (channel, ban_username))
	 	self.client.send(b'unban %s %s' % (channel, ban_username))
		self.client.send(b'logout')
	 	self.client.send(b'login %s %s' % (ban_username, ban_password))
	 	result = self.client.send(b'join %s' % channel)
	 	self.assertEqual(self.client.reply('CHANNEL_JOIN',{ 'name':channel }), result)
Exemplo n.º 15
0
class TestChannelMode(unittest.TestCase):
    def setUp(self):
        self.modes = ['private', 'moderated', 'registered_only']
        self.client = Client()

    def tearDown(self):
        self.client.connection.close()

    def test_set_anonymous(self):
        result = self.mode_on('anonymous', 'on')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_SET', {
                'field': 'anonymous',
                'mode_value': True
            }), result)

    def test_set_anonymous_ff(self):
        result = self.mode_on('anonymous', 'off')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_SET', {
                'field': 'anonymous',
                'mode_value': False
            }), result)

    def test_set_private(self):
        result = self.mode_on('private', 'on')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_SET', {
                'field': 'private',
                'mode_value': True
            }), result)

    def test_set_private_ff(self):
        result = self.mode_on('private', 'off')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_SET', {
                'field': 'private',
                'mode_value': False
            }), result)

    def test_set_moderated(self):
        result = self.mode_on('moderated', 'on')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_SET', {
                'field': 'moderated',
                'mode_value': True
            }), result)

    def test_set_moderated_off(self):
        result = self.mode_on('moderated', 'off')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_SET', {
                'field': 'moderated',
                'mode_value': False
            }), result)

    def test_set_registered_only(self):
        result = self.mode_on('registered_only', 'on')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_SET', {
                'field': 'registered_only',
                'mode_value': True
            }), result)

    def test_set_registered_only_off(self):
        result = self.mode_on('registered_only', 'off')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_SET', {
                'field': 'registered_only',
                'mode_value': False
            }), result)

    def test_set_invalid_mode(self):
        result = self.mode_on('foobar', 'on')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_NOT_FOUND', {'field': 'foobar'}),
            result)

    def test_set_invalid_value(self):
        result = self.mode_on('private', 'foobar')
        self.assertEqual(
            self.client.reply('CHANNEL_MODE_INVALID_VALUE',
                              {'value': 'foobar'}), result)

    def mode_on(self, mode, switch):
        self.client.register_login()
        channel = random_word()
        result = self.client.send(b'create #%s' % channel)
        return self.client.send(b'mode #%s %s %s' % (channel, mode, switch))

    def test_set_no_permission(self):
        self.client.register_login()
        channel = random_word()
        result = self.client.send(b'create #%s' % channel)
        result = self.client.send(b'logout')
        self.client.register_login()
        result = self.client.send(b'mode #%s %s %s' %
                                  (channel, 'private', 'on'))
        self.assertEqual(self.client.reply('NO_PERMISSION'), result)

    def test_private_join(self):
        '''Make sure cannot join private channel'''
        self.client.register_login()
        channel = random_word()
        self.client.send(b'create #%s' % channel)
        a = self.client.send(b'mode #%s %s %s' % (channel, 'private', 'on'))
        self.client.send(b'logout')
        self.client.register_login()
        result = self.client.send(b'join #%s' % channel)
        self.assertEqual(
            self.client.reply('CHANNEL_PRIVATE', {'name': '#' + channel}),
            result)

    def test_not_private_join(self):
        self.client.register_login()
        channel = random_word()
        self.client.send(b'create #%s' % channel)
        self.client.send(b'logout')
        self.client.register_login()
        result = self.client.send(b'join #%s' % channel)
        self.assertEqual(
            self.client.reply('CHANNEL_JOIN', {'name': '#' + channel}), result)

    def test_private_follow(self):
        self.client.register_login()
        channel = random_word()
        self.client.send(b'create #%s' % channel)
        a = self.client.send(b'mode #%s %s %s' % (channel, 'private', 'on'))
        self.client.send(b'logout')
        self.client.register_login()
        result = self.client.send(b'follow #%s' % channel)
        self.assertEqual(
            self.client.reply('CHANNEL_PRIVATE', {'name': '#' + channel}),
            result)

    def test_not_private_follow(self):
        self.client.register_login()
        channel = random_word()
        self.client.send(b'create #%s' % channel)
        self.client.send(b'logout')
        self.client.register_login()
        result = self.client.send(b'follow #%s' % channel)
        self.assertEqual(
            self.client.reply('CHANNEL_FOLLOW', {'name': '#' + channel}),
            result)

    def test_private_invite_join(self):
        channel = random_word()
        invited_username = random_word()
        invited_password = random_word()

        self.client.register_login(invited_username, invited_password)
        self.client.send(b'logout')

        b = self.client.register_login()
        self.client.send(b'create #%s' % channel)
        self.client.send(b'mode #%s %s %s' % (channel, 'private', 'on'))
        self.client.send(b'invite #%s %s' % (channel, invited_username))
        self.client.send(b'logout')
        self.client.send(b'login %s %s' % (invited_username, invited_password))
        result = self.client.send(b'join #%s' % channel)
        self.assertEqual(
            self.client.reply('CHANNEL_JOIN', {'name': '#' + channel}), result)
Exemplo n.º 16
0
class TestUser(unittest.TestCase):
    def setUp(self):
        self.client = Client()
        self.client.connect_db()

    def tearDown(self):
        self.client.connection.close()

    def test_whoami_not_logged_in(self):
        result = self.client.send(b'whoami')
        self.assertEqual(self.client.reply('ERR_NOT_LOGGED_IN'), result)

    def test_whoami(self):
        username = random_word()
        password = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        result = self.client.send(b'whoami')
        self.assertEqual(username, result)

    def test_register(self):
        username = random_word()
        password = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        self.assertEqual(self.client.reply('USER_REGISTER'), result)

    def test_register_already_logged_in(self):
        username = random_word()
        password = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        username = random_word()
        password = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        self.assertEqual(self.client.reply('ERR_ALREADY_LOGGED_IN'), result)

    def test_register_username_already_taken(self):
        username = random_word()
        password = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        result = self.client.send(b'logout')
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        self.assertEqual(self.client.reply('USER_USERNAME_ALREADY_TAKEN'),
                         result)

    def test_logout(self):
        username = random_word()
        password = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        result = self.client.send(b'logout')
        self.assertEqual(self.client.reply('USER_LOGOUT'), result)

    def test_logout_not_logged_in(self):
        result = self.client.send(b'logout')
        self.assertEqual(self.client.reply('NOT_LOGGED_IN'), result)

    def test_login(self):
        username = random_word()
        email = random_email()
        password = random_word()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        result = self.client.send(b'logout')
        result = self.client.send(b'login %s %s' % (username, password))
        self.assertEqual(self.client.reply('USER_LOGIN'), result)

    def test_login_username_not_found(self):
        username = random_word()
        password = random_word()
        result = self.client.send(b'login %s %s' % (username, password))
        self.assertEqual(self.client.reply('USER_USERNAME_NOT_FOUND'), result)

    def test_login_password_invalid(self):
        username = random_word()
        password = random_word()
        password_invalid = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        result = self.client.send(b'logout')
        result = self.client.send(b'login %s %s' %
                                  (username, password_invalid))
        self.assertEqual(self.client.reply('USER_PASSWORD_INVALID'), result)

    def test_protocol(self):
        result = self.client.send(b'protocol text')
        self.assertEqual(self.client.reply('USER_PROTOCOL'), result)

    def test_protocol_not_found(self):
        result = self.client.send(b'protocol foobar')
        self.assertEqual(self.client.reply('USER_PROTOCOL_NOT_FOUND'), result)

    def test_session(self):
        username = random_word()
        password = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        result = self.client.send(b'session')
        self.assertNotEqual(result, 'None')

    def test_token(self):
        username = random_word()
        password = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        result = self.client.send(b'token')
        self.assertNotEqual(result, 'None')

    def test_set_full(self):
        profile = {
            'name': 'Foo Bar',
            'bio': 'This is my bio',
            'url': 'www.foobar.com',
            'facebook': 'foobar1',
            'twitter': 'foobar2',
            'instagram': 'foobar3'
        }
        username = random_word()
        password = random_word()
        email = random_email()

        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))

        for key, value in profile.iteritems():
            result = self.client.send(b'set %s %s' % (key, value))

        pass_count = 0
        for key, value in profile.iteritems():
            result = self.client.send(b'profile %s' % key)
            if result == profile[key]:
                pass_count += 1

        self.assertNotEqual(pass_count, len(profile))

    def test_following(self):
        self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'follow %s' % name)
        result = self.client.send(b'following')
        self.assertNotEqual(self.client.reply('USER_FOLLOWING_NONE'), 'None')

    def test_following_none(self):
        self.client.register_login()
        result = self.client.send(b'following')
        self.assertEqual(self.client.reply('USER_FOLLOWING_NONE'), result)

    def test_joined(self):
        self.client.register_login()
        name = random_channel()
        result = self.client.send(b'create %s' % name)
        result = self.client.send(b'join %s' % name)
        result = self.client.send(b'joined')
        self.assertNotEqual(self.client.reply('USER_JOINED_NONE'), 'None')

    def test_joined_none(self):
        self.client.register_login()
        result = self.client.send(b'joined')
        self.assertEqual(self.client.reply('USER_JOINED_NONE'), result)

    def test_forgotten(self):
        username = random_word()
        password = random_word()
        password_new = random_word()
        email = random_email()
        result = self.client.send(b'register %s %s %s' %
                                  (username, password, email))
        result = self.client.send(b'login %s %s' % (username, password))
        result = self.client.send(b'logout')
        result = self.client.send(b'forgotten %s' % username)
        user = self.client.db.User.find_one({'username': username})
        result = self.client.send(b'reset %s %s' %
                                  (user['reset_token'], password_new))
        result = self.client.send(b'login %s %s' % (username, password_new))
        self.assertEqual(self.client.reply('USER_LOGIN'), result)

    def test_status_away(self):
        status = 'away'
        self.client.register_login()
        result = self.client.send(b'status %s' % status)
        self.assertEqual(self.client.reply('USER_STATUS', {'status': status}),
                         result)

    def test_status_offline(self):
        status = 'offline'
        self.client.register_login()
        result = self.client.send(b'status %s' % status)
        self.assertEqual(self.client.reply('USER_STATUS', {'status': status}),
                         result)

    def test_status_dnd(self):
        status = 'dnd'
        self.client.register_login()
        result = self.client.send(b'status %s' % status)
        self.assertEqual(self.client.reply('USER_STATUS', {'status': status}),
                         result)

    def test_status_online(self):
        status = 'online'
        self.client.register_login()
        result = self.client.send(b'status %s' % status)
        self.assertEqual(self.client.reply('USER_STATUS', {'status': status}),
                         result)

    def test_status_invalid(self):
        status = 'foobar'
        self.client.register_login()
        result = self.client.send(b'status %s' % status)
        self.assertEqual(
            self.client.reply('USER_STATUS_INVALID', {'status': status}),
            result)
Exemplo n.º 17
0
 def setUp(self):
     self.modes = ['private', 'moderated', 'registered_only']
     self.client = Client()