Example #1
0
    LANG = LANG[:2]  # en, fr, el etc..

os_info = None  # used to cache os information

from common.contacts import LegacyContactsAPI
from common.events import Events

gmail_domains = ['gmail.com', 'googlemail.com']

transport_type = {}  # list the type of transport

last_message_time = {}  # list of time of the latest incomming message
# {acct1: {jid1: time1, jid2: time2}, }
encrypted_chats = {}  # list of encrypted chats {acct1: [jid1, jid2], ..}

contacts = LegacyContactsAPI()
gc_connected = {}  # tell if we are connected to the room or not
# {acct: {room_jid: True}}
gc_passwords = {}  # list of the pass required to enter a room
# {room_jid: password}
automatic_rooms = {}  # list of rooms that must be automaticaly configured
# and for which we have a list of invities
#{account: {room_jid: {'invities': []}}}
new_room_nick = None  # if it's != None, use this nick instead of asking for
# a new nickname when there is a conflict.

groups = {}  # list of groups
newly_added = {}  # list of contacts that has just signed in
to_be_removed = {}  # list of contacts that has just signed out

events = Events()
Example #2
0
 def setUp(self):
     self.contacts = LegacyContactsAPI()
Example #3
0
 def setUp(self):
     self.contacts = LegacyContactsAPI()
Example #4
0
class TestContacts(unittest.TestCase):
    def setUp(self):
        self.contacts = LegacyContactsAPI()

    def test_create_add_get_contact(self):
        jid = '*****@*****.**'
        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 = '*****@*****.**'
        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")

    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 = "*****@*****.**"
        jid2 = "*****@*****.**"
        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, '')))
Example #5
0
class TestContacts(unittest.TestCase):

    def setUp(self):
        self.contacts = LegacyContactsAPI()

    def test_create_add_get_contact(self):
        jid = '*****@*****.**'
        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 = '*****@*****.**'
        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")

    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 = "*****@*****.**"
        jid2 = "*****@*****.**"
        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, '')))