2009-10-25 23:56:14 +01:00
|
|
|
'''
|
|
|
|
Test for Contact, GC_Contact and Contacts
|
|
|
|
'''
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import lib
|
|
|
|
lib.setup_env()
|
|
|
|
|
2009-11-05 15:57:43 +01:00
|
|
|
from common.contacts import CommonContact, Contact, GC_Contact, Contacts
|
2009-10-27 20:31:09 +01:00
|
|
|
from common.xmpp import NS_MUC
|
2009-10-25 23:56:14 +01:00
|
|
|
|
2009-10-30 23:01:25 +01:00
|
|
|
from common import caps
|
|
|
|
|
2009-10-27 20:31:09 +01:00
|
|
|
class TestCommonContact(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2009-11-05 15:57:43 +01:00
|
|
|
self.contact = CommonContact(jid='', account="", resource='', show='',
|
|
|
|
status='', name='', our_chatstate=None, composing_xep=None,
|
|
|
|
chatstate=None, client_caps=None)
|
2009-10-25 23:56:14 +01:00
|
|
|
|
2009-10-27 20:31:09 +01:00
|
|
|
def test_default_client_supports(self):
|
|
|
|
'''
|
|
|
|
Test the caps support method of contacts.
|
|
|
|
See test_caps for more enhanced tests.
|
|
|
|
'''
|
2009-10-30 23:01:25 +01:00
|
|
|
caps.capscache = caps.CapsCache()
|
2009-10-27 20:31:09 +01:00
|
|
|
self.assertTrue(self.contact.supports(NS_MUC),
|
|
|
|
msg="Must not backtrace on simple check for supported feature")
|
|
|
|
|
2009-10-30 23:01:25 +01:00
|
|
|
self.contact.client_caps = caps.NullClientCaps()
|
2009-10-27 20:31:09 +01:00
|
|
|
|
|
|
|
self.assertTrue(self.contact.supports(NS_MUC),
|
|
|
|
msg="Must not backtrace on simple check for supported feature")
|
2009-11-05 15:57:43 +01:00
|
|
|
|
2009-10-25 23:56:14 +01:00
|
|
|
|
2009-10-27 20:31:09 +01:00
|
|
|
class TestContact(TestCommonContact):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
TestCommonContact.setUp(self)
|
2009-11-05 15:57:43 +01:00
|
|
|
self.contact = Contact(jid="test@gajim.org", account="account")
|
2009-10-27 20:31:09 +01:00
|
|
|
|
2009-11-05 15:57:43 +01:00
|
|
|
def test_attributes_available(self):
|
|
|
|
'''This test supports the migration from the old to the new contact
|
|
|
|
domain model by smoke testing that no attribute values are lost'''
|
|
|
|
|
|
|
|
attributes = ["jid", "resource", "show", "status", "name", "our_chatstate",
|
|
|
|
"composing_xep", "chatstate", "client_caps", "priority", "sub"]
|
|
|
|
for attr in attributes:
|
|
|
|
self.assertTrue(hasattr(self.contact, attr), msg="expected: " + attr)
|
|
|
|
|
2009-10-27 20:31:09 +01:00
|
|
|
|
|
|
|
class TestGC_Contact(TestCommonContact):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
TestCommonContact.setUp(self)
|
2009-11-05 16:22:21 +01:00
|
|
|
self.contact = GC_Contact(room_jid="confernce@gajim.org", account="account")
|
2009-11-05 15:57:43 +01:00
|
|
|
|
|
|
|
def test_attributes_available(self):
|
|
|
|
'''This test supports the migration from the old to the new contact
|
|
|
|
domain model by asserting no attributes have been lost'''
|
|
|
|
|
|
|
|
attributes = ["jid", "resource", "show", "status", "name", "our_chatstate",
|
|
|
|
"composing_xep", "chatstate", "client_caps", "role", "room_jid"]
|
|
|
|
for attr in attributes:
|
|
|
|
self.assertTrue(hasattr(self.contact, attr), msg="expected: " + attr)
|
2009-10-25 23:56:14 +01:00
|
|
|
|
2009-11-05 20:54:32 +01:00
|
|
|
|
2009-11-05 15:57:43 +01:00
|
|
|
class TestContacts(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.contacts = Contacts()
|
|
|
|
|
|
|
|
def test_create_add_get_contact(self):
|
|
|
|
jid = 'test@gajim.org'
|
|
|
|
account = "account"
|
|
|
|
|
|
|
|
contact = self.contacts.create_contact(jid=jid, account=account)
|
|
|
|
self.contacts.add_contact(account, contact)
|
|
|
|
|
|
|
|
retrieved_contact = self.contacts.get_contact(account, jid)
|
|
|
|
self.assertEqual(contact, retrieved_contact, "Contact must be known")
|
|
|
|
|
|
|
|
self.contacts.remove_contact(account, contact)
|
|
|
|
|
|
|
|
retrieved_contact = self.contacts.get_contact(account, jid)
|
|
|
|
self.assertNotEqual(contact, retrieved_contact,
|
|
|
|
msg="Contact must not be known any longer")
|
|
|
|
|
|
|
|
|
|
|
|
def test_copy_contact(self):
|
|
|
|
jid = 'test@gajim.org'
|
|
|
|
account = "account"
|
|
|
|
|
|
|
|
contact = self.contacts.create_contact(jid=jid, account=account)
|
|
|
|
copy = self.contacts.copy_contact(contact)
|
|
|
|
self.assertFalse(contact is copy, msg="Must not be the same")
|
|
|
|
|
|
|
|
# Not yet implemented to remain backwart compatible
|
|
|
|
# self.assertEqual(contact, copy, msg="Must be equal")
|
|
|
|
|
2009-11-10 22:56:10 +01:00
|
|
|
def test_legacy_accounts_handling(self):
|
|
|
|
self.contacts.add_account("one")
|
|
|
|
self.contacts.add_account("two")
|
|
|
|
|
|
|
|
self.contacts.change_account_name("two", "old")
|
|
|
|
self.contacts.remove_account("one")
|
|
|
|
|
|
|
|
self.assertEqual(["old"], self.contacts.get_accounts())
|
|
|
|
|
|
|
|
def test_legacy_contacts_from_groups(self):
|
|
|
|
jid1 = "test1@gajim.org"
|
|
|
|
jid2 = "test2@gajim.org"
|
|
|
|
account = "account"
|
|
|
|
group = "GroupA"
|
|
|
|
|
|
|
|
contact1 = self.contacts.create_contact(jid=jid1, account=account,
|
|
|
|
groups=[group])
|
|
|
|
self.contacts.add_contact(account, contact1)
|
|
|
|
|
|
|
|
contact2 = self.contacts.create_contact(jid=jid2, account=account,
|
|
|
|
groups=[group])
|
|
|
|
self.contacts.add_contact(account, contact2)
|
|
|
|
|
|
|
|
self.assertEqual(2, len(self.contacts.get_contacts_from_group(account, group)))
|
|
|
|
self.assertEqual(0, len(self.contacts.get_contacts_from_group(account, '')))
|
|
|
|
|
|
|
|
|
2009-10-25 23:56:14 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|