def setup_env(): # wipe config directory if os.path.isdir(configdir): import shutil shutil.rmtree(configdir) os.mkdir(configdir) os.mkdir(pluginsconfigdir) import gajim.common.configpaths gajim.common.configpaths.gajimpaths.init(configdir) # for some reason gajim.common.app needs to be imported before xmpppy? from gajim.common import app import logging logging.basicConfig() app.DATA_DIR = gajim_root + '/gajim/data' app.use_x = use_x app.contacts = LegacyContactsAPI() app.connections = {} if use_x: from gajim import gtkgui_helpers gtkgui_helpers.GUI_DIR = gajim_root + '/gajim/data/gui' from gajim.gajim import GajimApplication app.app = GajimApplication()
def setup_env(use_x=True): # wipe config directory if os.path.isdir(configdir): import shutil shutil.rmtree(configdir) os.mkdir(configdir) os.mkdir(pluginsconfigdir) os.mkdir(themedir) from gajim.common import configpaths configpaths.set_config_root(configdir) configpaths.init() # for some reason gajim.common.app needs to be imported before xmpppy? from gajim.common import app import logging logging.basicConfig() app.use_x = use_x app.contacts = LegacyContactsAPI() app.connections = {} if use_x: from gajim.application import GajimApplication app.app = GajimApplication()
nec = cast(NetworkEventsControllerT, None) plugin_manager = None # Plugins Manager logger = cast(LoggerT, None) css_config = None os_info = None # used to cache os information transport_type = {} # type: Dict[str, str] # dict of time of the latest incoming message per jid # {acct1: {jid1: time1, jid2: time2}, } last_message_time = {} # type: Dict[str, Dict[str, float]] contacts = LegacyContactsAPI() # tell if we are connected to the room or not # {acct: {room_jid: True}} gc_connected = {} # type: Dict[str, Dict[str, bool]] # dict of the pass required to enter a room # {room_jid: password} gc_passwords = {} # type: Dict[str, str] # dict of rooms that must be automaticaly configured # and for which we have a list of invities # {account: {room_jid: {'invities': []}}} automatic_rooms = {} # type: Dict[str, Dict[str, Dict[str, List[str]]]] # dict of groups, holds if they are expanded or not
def setUp(self): self.contacts = LegacyContactsAPI()
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_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, '')))