def setUp(self): self.__PresenceManager = PresenceManager() unittest.TestCase.setUp(self) self.__PresenceManager._PresenceManager__presenceRoster = {}
#!/usr/bin/python ## Copyright (C) 2012 Bryan King ## ## 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; either version 2, or (at your option) ## any later version. ## ## 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. import Config import ItBot import sys from PresenceManager import PresenceManager if __name__ == '__main__': configFilePath = sys.argv.pop() MyConfig = Config.Config(configFilePath, PresenceManager()) ItBot.ItBot(MyConfig)
class PresenceManagerTest(unittest.TestCase): def setUp(self): self.__PresenceManager = PresenceManager() unittest.TestCase.setUp(self) self.__PresenceManager._PresenceManager__presenceRoster = {} def tearDown(self): unittest.TestCase.tearDown(self) def test_isJidHandleAvailable_returns_false_if_jid_handle_is_currently_away(self): SomeJidHandle = JidHandle('someUserName', '*****@*****.**') self.__given_jid_handle_status_is_currently(SomeJidHandle, 'away') self.assertFalse(self.__PresenceManager.isJidHandleAvailable(SomeJidHandle)) def test_isJidHandleAvailable_returns_false_if_jid_handle_is_currently_marked_as_offline(self): """ This is the option where you can select to appear as offline """ SomeJidHandle = JidHandle('someUserName', '*****@*****.**') self.__given_jid_handle_is_currently_marked_as_offline(SomeJidHandle) self.assertFalse(self.__PresenceManager.isJidHandleAvailable(SomeJidHandle)) def test_isJidHandleAvailable_returns_false_if_jid_handle_is_do_not_disturb_status(self): SomeJidHandle = JidHandle('someUserName', '*****@*****.**') self.__given_jid_handle_status_is_currently(SomeJidHandle, 'dnd') self.assertFalse(self.__PresenceManager.isJidHandleAvailable(SomeJidHandle)) def test_isJidHandleAvailable_returns_false_if_jid_handle_is_extended_away_status(self): """ This is the option where you can select to appear as offline """ SomeJidHandle = JidHandle('someUserName', '*****@*****.**') self.__given_jid_handle_status_is_currently(SomeJidHandle, 'xa') self.assertFalse(self.__PresenceManager.isJidHandleAvailable(SomeJidHandle)) def test_isJidHandleAvailable_returns_true_if_jid_handle_status_is_available(self): SomeJidHandle = JidHandle('someUserName', '*****@*****.**') self.__given_jid_handle_status_is_currently(SomeJidHandle, None) self.assertTrue(self.__PresenceManager.isJidHandleAvailable(SomeJidHandle)) def test_isJidHandleAvailable_returns_true_if_jid_handle_status_is_chatty(self): SomeJidHandle = JidHandle('someUserName', '*****@*****.**') self.__given_jid_handle_status_is_currently(SomeJidHandle, 'chat') self.assertTrue(self.__PresenceManager.isJidHandleAvailable(SomeJidHandle)) def test_isJidHandleAvailable_returns_false_if_jid_handle_is_not_found(self): '''This can happen if a JidHandle is invalid or if the person is currently logged off''' SomeJidHandle = JidHandle('someUserName', '*****@*****.**') self.assertFalse(self.__PresenceManager.isJidHandleAvailable(SomeJidHandle)) def test_getStatusMsg_returns_correct_status_msg(self): SomeJidHandle = JidHandle('someUserName', '*****@*****.**') expectedMsg = 'On vacation!' self.__given_jid_handle_status_msg_is_currently(SomeJidHandle, expectedMsg) self.assertEquals(expectedMsg, self.__PresenceManager.getStatusMsg(SomeJidHandle)) def __given_jid_handle_status_is_currently(self, AJidHandle, status): with Stub() as presence: presence.getFrom() >> AJidHandle.getJid() presence.getShow() >> status presence.getType() >> None presence.getStatus() >> None self.__PresenceManager.updatePresence(presence) def __given_jid_handle_is_currently_marked_as_offline(self, AJidHandle): with Stub() as presence: presence.getFrom() >> AJidHandle.getJid() presence.getShow() >> None presence.getType() >> 'unavailable' presence.getStatus() >> None self.__PresenceManager.updatePresence(presence) def __given_jid_handle_status_msg_is_currently(self, AJidHandle, statusMsg): with Stub() as presence: presence.getFrom() >> AJidHandle.getJid() presence.getShow() >> None presence.getType() >> 'unavailable' presence.getStatus() >> statusMsg self.__PresenceManager.updatePresence(presence)