Small enhancements for test_roster_window.

* Make sure that contacts show up under the correct parent
* Add check support for SelfContacts
This commit is contained in:
Stephan Erb 2008-08-28 22:07:40 +00:00
parent d63133d765
commit a16c65873a
2 changed files with 50 additions and 10 deletions

View File

@ -5,6 +5,9 @@ account3 = u'dingdong.org'
contacts = {}
contacts[account1] = {
u'myjid@'+account1: {
'ask': None, 'groups': [], 'name': None, 'resources': {},
'subscription': u'both'},
u'default1@gajim.org': {
'ask': None, 'groups': [], 'name': None, 'resources': {},
'subscription': u'both'},
@ -19,6 +22,9 @@ contacts[account1] = {
'subscription': u'both'}
}
contacts[account2] = {
u'myjid@'+account2: {
'ask': None, 'groups': [], 'name': None, 'resources': {},
'subscription': u'both'},
u'default3@gajim.org': {
'ask': None, 'groups': [u'GroupC',], 'name': None, 'resources': {},
'subscription': u'both'},
@ -46,7 +52,7 @@ contacts[account3] = {
# 'ask': None, 'groups': [], 'name': None,
# 'resources': {}, 'subscription': u'both'}
}
# We have contacts that are not in roster but only specified in the metadata
metacontact_data = [
[{'account': account3,
'jid': u'guypsych0\\40h.com@msn.dingdong.org',

View File

@ -22,23 +22,22 @@ class TestRosterWindow(unittest.TestCase):
gajim.interface = MockInterface()
self.roster = roster_window.RosterWindow()
# Please unuglify :-)
self.C_NAME = roster_window.C_NAME
self.C_TYPE = roster_window.C_TYPE
self.C_JID = roster_window.C_JID
self.C_ACCOUNT = roster_window.C_ACCOUNT
# Add after creating the window
# Add after creating RosterWindow
# We want to test the filling explicitly
for acc in contacts:
gajim.connections[acc] = MockConnection(acc)
def tearDown(self):
self.roster.model.clear()
for acc in contacts:
for acc in gajim.contacts.get_accounts():
gajim.contacts.clear_contacts(acc)
# Custom assertions
### Custom assertions
def assert_all_contacts_are_in_roster(self, acc):
for jid in contacts[acc]:
self.assert_contact_is_in_roster(jid, acc)
@ -47,10 +46,28 @@ class TestRosterWindow(unittest.TestCase):
contacts = gajim.contacts.get_contacts(account, jid)
# check for all resources
for contact in contacts:
iters = self.roster._get_contact_iter(
jid, account, model=self.roster.model)
self.assertTrue(len(iters) == len(contact.get_shown_groups()),
msg='Contact is not in all his groups')
iters = self.roster._get_contact_iter(jid, account,
model=self.roster.model)
if jid != gajim.get_jid_from_account(account):
# We don't care for groups of SelfContact
self.assertTrue(len(iters) == len(contact.get_shown_groups()),
msg='Contact is not in all his groups')
# Are we big brother?
bb_jid = None
bb_account = None
family = gajim.contacts.get_metacontacts_family(account, jid)
if family:
nearby_family, bb_jid, bb_account = \
self.roster._get_nearby_family_and_big_brother(family, account)
is_in_nearby_family = (jid, account) in (
(data['jid'], data['account']) for data in nearby_family)
self.assertTrue(is_in_nearby_family,
msg='Contact not in his own nearby family')
is_big_brother = (bb_jid, bb_account) == (jid, account)
# check for each group tag
for titerC in iters:
@ -66,7 +83,24 @@ class TestRosterWindow(unittest.TestCase):
if not self.roster.regroup:
self.assertEquals(account, c_model[self.C_ACCOUNT],
msg='Account missmatch')
# TODO: Is our parent correct? (group or big b)
# Check for correct nesting
parent_iter = self.roster.model.iter_parent(titerC)
p_model = self.roster.model[parent_iter]
if family:
if is_big_brother:
self.assertTrue(p_model[self.C_TYPE] == 'group',
msg='Big Brother is not on top')
else:
self.assertTrue(p_model[self.C_TYPE] == 'contact',
msg='Little Brother brother has no BigB')
else:
if jid == gajim.get_jid_from_account(account):
self.assertTrue(p_model[self.C_TYPE] == 'account',
msg='SelfContact is not on top')
else:
self.assertTrue(p_model[self.C_TYPE] == 'group',
msg='Contact not found in a group')
def assert_group_is_in_roster(self, group, account):
#TODO