def __given_second_list_modifier_returns_no_jid_handles(self):

        UnExpectedJidHandles = []
        UnExpectedJidHandles.append(JidHandle('someUserName', 'someCrazyJid'))
        UnExpectedJidHandles.append(
            JidHandle('someOtherUserName', 'someOtherJid'))

        with Spy() as FirstFilter:
            FirstFilter.getJidHandleGroupResult(any(), any(), any()) >> Result(
                [JidHandleGroup(UnExpectedJidHandles)])

        with Spy() as SecondFilter:
            SecondFilter.getJidHandleGroupResult(any(), any(),
                                                 any()) >> Result([])

        with Spy() as ThirdFilter:
            ThirdFilter.getJidHandleGroupResult(any(), any(), any()) >> Result(
                [JidHandleGroup(UnExpectedJidHandles)])

        with Spy() as MockedConfig:
            MockedConfig.getOrderedRecipientListModifiers() >> [
                FirstFilter, SecondFilter, ThirdFilter
            ]
            MockedConfig.getJidHandleGroups() >> [
                JidHandleGroup(UnExpectedJidHandles)
            ]

        self.__MyConfig = MockedConfig
Esempio n. 2
0
 def getJidHandleGroupResult(self, JidHandleGroups, sender, messageBody):
     if (len(JidHandleGroups) > 0):
         FirstJidHandleGroup = JidHandleGroups[0]
         JidHandles = FirstJidHandleGroup.getJidHandles()
         if (JidHandles):
             FirstJidHandleGroup.setJidHandles([JidHandles[0]])
         return Result([FirstJidHandleGroup])
     else:
         return Result(JidHandleGroups)
Esempio n. 3
0
    def getJidHandleGroupResult(self, JidHandleGroups, sender, messageBody):
        keywordsToIgnore = self.__ConfigParser.findConfigLinesBetween(
            self.START_IGNORE_MESSAGES_WITH_KEYWORDS_KEY,
            self.END_IGNORE_MESSAGES_WITH_KEYWORDS_KEY)

        for keyword in keywordsToIgnore:
            if messageBody.find(keyword) != -1:
                return Result(resultCode=Result.DONT_SEND_ANY_MESSAGE)

        return Result(JidHandleGroups)
Esempio n. 4
0
	def setRequestedRecipientToPassedGroupIdentifier(self, messageBody, JidHandleGroups):
		for JidHandleGroup in JidHandleGroups:
			if (JidHandleGroup.getGroupIdentifierString() in messageBody):
				MyRecipientChooser = RecipientChooser(self.__MyConfig, [JidHandleGroup])
				Result = MyRecipientChooser.getJidHandleGroupResult(None, messageBody)
				if Result.hasJidHandles():
					for JidHandle in Result.getJidHandleGroups()[0].getJidHandles():
						if JidHandle not in self.__IgnoredRecipients:
							self.__RequestedRecipient = Result.getJidHandleGroups()[0].getJidHandles()
							self.__RequestedJidHandleGroup = JidHandleGroup
							self.__timeOutLastConfirmedRecipient()
							return True

		return False
Esempio n. 5
0
	def test_getJidHandleGroupResult_skips_subsequent_filters_if_second_list_modifier_returns_no_jid_handles(self):
		self.__given_second_list_modifier_returns_no_jid_handles()

		MyChooser = RecipientChooser(self.__MyConfig)
		Result = MyChooser.getJidHandleGroupResult('', '')

		self.assertFalse(Result.hasJidHandles())
Esempio n. 6
0
	def test_getJidHandleGroupResult_returns_all_jid_handles_if_no_list_modifiers_are_set(self):
		ExpectedJidHandleGroups = self.__given_multiple_jid_handles_in_configuration_with_no_list_modifiers()

		MyChooser = RecipientChooser(self.__MyConfig)
		Result = MyChooser.getJidHandleGroupResult('', '')

		self.assertEquals(ExpectedJidHandleGroups, Result.getJidHandleGroups())
Esempio n. 7
0
    def getJidHandleGroupResult(self, sender, messageBody):
        if (self.__OrderedRecipientListModifiers):
            ListResult = self.__applyListModifiers(messageBody, sender)
        else:
            ListResult = Result(self.__JidHandleGroups)

        return ListResult
    def getJidHandleGroupResult(self, JidHandleGroups, sender, messageBody):
        if (len(JidHandleGroups) > 0):
            for JidHandleGroup in JidHandleGroups:
                JidHandles = JidHandleGroup.getJidHandles()
                if (len(JidHandles) > 0):
                    timeUnit = self.__RoundRobinSettings.getTimeUnit()
                    numSupportAvailable = len(JidHandles)

                    sortByIndex = 0
                    CurrentDate = date.today()
                    if (timeUnit == 'daily'):
                        day = datetime.now().timetuple().tm_yday
                        sortByIndex = day % numSupportAvailable
                    elif (timeUnit == 'weekly'):
                        isoWeek = CurrentDate.isocalendar()[1]
                        sortByIndex = isoWeek % numSupportAvailable
                    elif (timeUnit == 'monthly'):
                        month = CurrentDate.month
                        sortByIndex = month % numSupportAvailable

                    JidHandles = JidHandles[
                        sortByIndex::] + JidHandles[:sortByIndex]
                    JidHandleGroup.setJidHandles(JidHandles)

        return Result(JidHandleGroups)
    def __given_presence_will_be_confirmed(self, mockMessageBuilder=False):

        if mockMessageBuilder:
            builderMock = Spy()

            with Stub() as RecipientFilter:
                RecipientFilter.presenceConfirmed()
                RecipientFilter.getRequesterJidHandles() >> []
            self.__RecipientFilter = RecipientFilter
        else:
            builderMock = Stub()

        with builderMock as MessageBuilder:
            MessageBuilder.presenceConfirmed()
            MessageBuilder.getRequestConfirmedMessageBody(any()) >> 'something'
            MessageBuilder.getHelpdeskUserConfirmationMessageBody(
            ) >> 'something else'

        self.__MessageBuilder = MessageBuilder

        with Spy() as RecipientChooser:
            JidHandles = [JidHandle.JidHandle('', self.__sender)]
            RecipientChooser.getJidHandleGroupResult(any(), any()) >> Result(
                [JidHandleGroup(JidHandles)])
            RecipientChooser.getJidHandleFromJid(any())
            RecipientChooser.getRecipientListModifierByClass(
                any()) >> self.__RecipientFilter

        self.__RecipientChooser = RecipientChooser

        self.__and_we_have_a_pending_confirmation_request()
    def __given_nobody_is_available(self):
        with Stub(proxy=self.__RecipientChooser) as RecipientChooser:
            RecipientChooser.getJidHandleGroupResult(any(), any()) >> Result(
                [])
            RecipientChooser.getRecipientListModifierByClass(
                any()) >> self.__RecipientFilter

        self.__RecipientChooser = RecipientChooser
    def test_getJidHandleGroupResult_skips_subsequent_filters_if_second_list_modifier_returns_no_jid_handles(
            self):
        self.__given_second_list_modifier_returns_no_jid_handles()

        MyChooser = RecipientChooser(self.__MyConfig)
        Result = MyChooser.getJidHandleGroupResult('', '')

        self.assertFalse(Result.hasJidHandles())
    def test_getJidHandleGroupResult_returns_all_jid_handles_if_no_list_modifiers_are_set(
            self):
        ExpectedJidHandleGroups = self.__given_multiple_jid_handles_in_configuration_with_no_list_modifiers(
        )

        MyChooser = RecipientChooser(self.__MyConfig)
        Result = MyChooser.getJidHandleGroupResult('', '')

        self.assertEquals(ExpectedJidHandleGroups, Result.getJidHandleGroups())
    def __given_sender_is_current_requested_recipient(self):
        with Stub() as RecipientChooser:
            JidHandles = [JidHandle.JidHandle('', self.__sender)]
            RecipientChooser.getJidHandleGroupResult(any(), any()) >> Result(
                [JidHandleGroup(JidHandles)])
            RecipientChooser.getJidHandleFromJid(any())
            RecipientChooser.getRecipientListModifierByClass(
                any()) >> self.__RecipientFilter

        self.__RecipientChooser = RecipientChooser
	def getJidHandleGroupResult(self, JidHandleGroups, sender, messageBody):
		for JidHandleGroup in JidHandleGroups:
			if JidHandleGroup.shouldUseListModifierClass(self.__class__):
				AvailableJidHandles = []
				for MyJidHandle in JidHandleGroup.getJidHandles():
					if self._PresenceManager.isJidHandleAvailable(MyJidHandle):
						AvailableJidHandles.append(MyJidHandle)

				JidHandleGroup.setJidHandles(AvailableJidHandles)

		return Result(JidHandleGroups)
Esempio n. 15
0
    def getJidHandleGroupResult(self, JidHandleGroups, sender, messageBody):

        for JidHandleGroup in JidHandleGroups:
            if JidHandleGroup.shouldUseListModifierClass(self.__class__):
                JidHandles = [
                    JidHandle for JidHandle in JidHandleGroup.getJidHandles()
                    if JidHandle.getJid() != sender
                ]
                JidHandleGroup.setJidHandles(JidHandles)

        return Result(JidHandleGroups)
    def __given_requester_has_already_received_confirmation_message(self):
        with Spy() as RecipientFilter:
            RecipientFilter.alreadyMessagedRequester(self.__sender) >> True

        with Spy() as RecipientChooser:
            RecipientChooser.getJidHandleGroupResult(any(), any()) >> Result(
                [])
            RecipientChooser.getRecipientListModifierByClass(
                any()) >> RecipientFilter

        self.__RecipientChooser = RecipientChooser
    def __given_first_list_modifier_returns_dont_send_message_result(self):
        with Spy() as FirstFilter:
            FirstFilter.getJidHandleGroupResult(any(), any(), any()) >> Result(
                resultCode=Result.DONT_SEND_ANY_MESSAGE)

        UnExpectedJidHandles = []
        UnExpectedJidHandles.append(JidHandle('someUserName', 'someCrazyJid'))
        UnExpectedJidHandles.append(
            JidHandle('someOtherUserName', 'someOtherJid'))

        with Spy() as SecondFilter:
            SecondFilter.getJidHandleGroupResult(
                any(), any(), any()) >> Result(UnExpectedJidHandles)

        with Spy() as MockedConfig:
            MockedConfig.getOrderedRecipientListModifiers() >> [
                FirstFilter, SecondFilter
            ]
            MockedConfig.getJidHandleGroups() >> [
                JidHandleGroup([]),
                JidHandleGroup(UnExpectedJidHandles)
            ]

        self.__MyConfig = MockedConfig
    def __given_sender_is_different_requested_recipient(self):
        with Spy() as RecipientFilter:
            RecipientFilter.getRequesterJidHandles() >> []
            RecipientFilter.addRequester(any())
            RecipientFilter.alreadyMessagedRequester(any()) >> False
        self.__RecipientFilter = RecipientFilter

        with Stub(proxy=self.__RecipientChooser) as RecipientChooser:
            JidHandles = [JidHandle.JidHandle('', '*****@*****.**')]
            RecipientChooser.getJidHandleGroupResult(any(), any()) >> Result(
                [JidHandleGroup(JidHandles)])
            RecipientChooser.getRecipientListModifierByClass(
                any()) >> self.__RecipientFilter

        self.__RecipientChooser = RecipientChooser
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.__sender = "*****@*****.**"

        JidHandles = [JidHandle.JidHandle('', self.__sender)]
        self.__ExpectedMessage = Message.Message([JidHandleGroup(JidHandles)],
                                                 "")
        self.__RequesterConfMessage = Message.Message([], "")

        with Spy() as ItBot:
            pass
        self.__ItBot = ItBot

        self.__nobodyAvailableMsg = 'nobody available!'
        self.__immediateSenderConfMsg = 'someone will assist you shortly!'

        with Spy() as MessageBuilder:
            MessageBuilder.getImmediateSenderConfirmationMessageBody(
            ) >> self.__immediateSenderConfMsg
            MessageBuilder.getNobodyAvailableMessageBody(
            ) >> self.__nobodyAvailableMsg
            MessageBuilder.getRelayMessageBody(any(), any()) >> ""
        self.__MessageBuilder = MessageBuilder

        with Spy() as PresenceConfManager:
            PresenceConfManager.hasPendingRequest() >> True
        self.__PresenceConfirmationManager = PresenceConfManager

        with Spy() as RecipientFilter:
            RecipientFilter.getRequesterJidHandles() >> []
            RecipientFilter.addRequester(any())
            RecipientFilter.alreadyMessagedRequester(any()) >> True
        self.__RecipientFilter = RecipientFilter

        with Spy() as RecipientChooser:
            RecipientChooser.getJidHandleGroupResult(any(), any()) >> Result(
                [])
            RecipientChooser.getJidHandleFromJid(any())
            RecipientChooser.getRecipientListModifierByClass(
                any()) >> self.__RecipientFilter
        self.__RecipientChooser = RecipientChooser

        Spy.__calls__ = [
        ]  #hack job to reset spy call recording in between tests
    def __given_pending_request_exists_and_has_timed_out(self):
        with Spy() as PresenceConfirmationManager:
            PresenceConfirmationManager.hasPendingRequest() >> True
            PresenceConfirmationManager.hasTimedOut() >> True
            PresenceConfirmationManager.startNewRequest()

        self.__PresenceConfirmationManager = PresenceConfirmationManager

        PreviousRequestedRecipient = [
            JidHandle('somePreviousJid', '*****@*****.**')
        ]
        JidHandles = [JidHandle('someJid', '*****@*****.**')]
        JidHandleGroups = [JidHandleGroup(JidHandles)]
        with Spy() as RecipientChooser:
            RecipientChooser.getJidHandleGroupResult(
                any(), any()) >> Result(JidHandleGroups)
            RecipientChooser.getCurrentRequestedRecipient(
            ) >> PreviousRequestedRecipient

        self.__RecipientChooser = RecipientChooser

        relayMessageBody = 'Some Message Body'
        notificationMessageBody = 'Hey snoozer your message has been forwarded'
        with Stub() as MessageBuilder:
            MessageBuilder.getTimedOutNotificationMessageBody(
                any()) >> notificationMessageBody
            MessageBuilder.getPendingMessagesForRequestedRecipient(
            ) >> relayMessageBody

        self.__MessageBuilder = MessageBuilder

        self.__ExpectedForwardedMessage = Message(JidHandleGroups,
                                                  relayMessageBody)
        self.__ExpectedNotificationMessage = Message(
            [JidHandleGroup(PreviousRequestedRecipient)],
            notificationMessageBody)
        self.__ExpectedRequesterNotificationMessage = Message(
            [JidHandleGroup(PreviousRequestedRecipient)],
            notificationMessageBody)

        with Spy() as ItBot:
            pass
        self.__ItBot = ItBot
    def __given_pending_request_exists_and_has_timed_out_and_nobody_is_available(
            self):
        with Spy() as PresenceConfirmationManager:
            PresenceConfirmationManager.hasPendingRequest() >> True
            PresenceConfirmationManager.hasTimedOut() >> True

        self.__PresenceConfirmationManager = PresenceConfirmationManager

        PreviousRequestedRecipient = [
            JidHandle('somePreviousJid', '*****@*****.**')
        ]
        RequesterJidHandles = [
            JidHandle('someRequesterJid', '*****@*****.**')
        ]
        with Spy() as Filter:
            Filter.getRequesterJidHandles() >> RequesterJidHandles
            Filter.getCurrentRequestedRecipient() >> PreviousRequestedRecipient

        JidHandles = [JidHandle('someJid', '*****@*****.**')]
        JidHandleGroups = [JidHandleGroup(JidHandles)]
        with Spy() as RecipientChooser:
            RecipientChooser.getJidHandleGroupResult(
                any(), any()) >> Result(resultCode=Result.NOBODY_AVAILABLE)
            RecipientChooser.getRecipientListModifierByClass(any()) >> Filter

        self.__RecipientChooser = RecipientChooser

        nobodyAvailableMessageBody = 'Nobody here son!'
        with Spy() as MessageBuilder:
            MessageBuilder.getNobodyAvailableMessageBody(
            ) >> nobodyAvailableMessageBody

        self.__MessageBuilder = MessageBuilder

        self.__ExpectedRequesterNotificationMessage = Message(
            [JidHandleGroup(RequesterJidHandles)], nobodyAvailableMessageBody)

        with Spy() as ItBot:
            pass
        self.__ItBot = ItBot
    def __and_message_builder_returns_a_helpdesk_user_confirmation_message(
            self):
        expectedMessageBody = "Presence confirmed."

        with Spy() as MessageBuilder:
            MessageBuilder.getHelpdeskUserConfirmationMessageBody(
            ) >> expectedMessageBody

        self.__MessageBuilder = MessageBuilder

        SenderJidHandle = [JidHandle.JidHandle('', self.__sender)]
        SenderJidHandleGroup = [JidHandleGroup(SenderJidHandle)]
        with Stub() as RecipientChooser:
            RecipientChooser.getJidHandleGroupResult(
                any(), any()) >> Result(SenderJidHandleGroup)
            RecipientChooser.getJidHandleFromJid(any())
            RecipientChooser.getRecipientListModifierByClass(
                any()) >> self.__RecipientFilter

        self.__RecipientChooser = RecipientChooser

        self.__ExpectedMessage = Message.Message(SenderJidHandleGroup,
                                                 expectedMessageBody)
Esempio n. 23
0
    def __getMockedRecipientChooser(self, ExpectedJidHandleGroups):
        with Stub() as MockedRecipientChooser:
            MockedRecipientChooser.getJidHandleGroupResult(
                any(), any()) >> Result(ExpectedJidHandleGroups)

        self.__RecipientChooser = MockedRecipientChooser
Esempio n. 24
0
 def getJidHandleGroupResult(self, JidHandleGroups, sender, messageBody):
     if (self.__isDuringBusinessHours):
         return Result(JidHandleGroups)
     else:
         return Result(resultCode=Result.DONT_SEND_RELAY_MESSAGE)
Esempio n. 25
0
    def __given_recipient_chooser_returns_dont_send_relay_message_result(self):
        with Stub() as RecipientChooser:
            RecipientChooser.getJidHandleGroupResult(any(), any()) >> Result(
                resultCode=Result.DONT_SEND_RELAY_MESSAGE)

        self.__RecipientChooser = RecipientChooser