1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
# -*- coding: utf-8 -*-
"""
Minbif - IRC instant messaging gateway
Copyright(C) 2009 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import sys
import re
from test import Test, Instance
class TestBuddyList(Test):
NAME = 'buddy_list'
INSTANCES = {'minbif1': Instance(), 'minbif2': Instance()}
TESTS = ['init', ]#'addbuddy', 'renamebuddy', 'delbuddy']
def test_init(self):
if not self['minbif1'].create_account('jabber', channel='&minbif'): return False
if not self['minbif1'].wait_connected('jabber'): return False
if not self['minbif1'].clean_buddies(): return False
if not self['minbif2'].create_account('jabber', channel='&minbif'): return False
if not self['minbif2'].wait_connected('jabber'): return False
if not self['minbif2'].clean_buddies(): return False
return True
def test_addbuddy(self):
self['minbif1'].request_answer('New request:', 'authorize', 1)
acc1name, acc1 = self['minbif1'].get_accounts().popitem()
self['minbif2'].write('INVITE %s:jabber &minbif' % acc1.username)
self['minbif1'].request_answer('New request:', 'authorize', 5)
self['minbif2'].log('Wait for join')
while 1:
msg = self['minbif2'].readmsg('JOIN', 4)
if not msg:
return False
m = re.match('([^!]*)!([^@]*)@(.*)', msg.sender)
if m:
return m.group(2) == acc1.username.split('@')[0]
def test_renamebuddy(self):
buddies = self['minbif2'].get_buddies()
if len(buddies) < 1:
return False
nick, buddy = buddies.popitem()
self['minbif2'].write('SVSNICK %s cacaprout' % nick)
while 1:
msg = self['minbif2'].readmsg('NICK', 2)
if not msg:
return False
if msg.sender.startswith('%s!' % nick) and msg.receiver == 'cacaprout':
return True
def test_delbuddy(self):
buddies = self['minbif2'].get_buddies()
if len(buddies) < 1:
self['minbif2'].log('Assert failed "len(buddies) == 1"')
return False
nick, buddy = buddies.popitem()
self['minbif2'].write('KILL %s' % nick)
self['minbif2'].log("Wait for quit")
while 1:
msg = self['minbif2'].readmsg('QUIT', 2)
if not msg:
return False
return msg.sender.startswith('%s!' % nick)
if __name__ == '__main__':
test = TestBuddyList()
if test.run():
sys.exit(0)
else:
sys.exit(1)
|