Beispiel #1
0
 def raise_event(self, payload: str, recipient_id: str) -> AbstractEvent:
     if Payload.match(payload, self.payload_uid):
         self.event.inject_payload(Payload.deserialize(payload))
         self.event.inject_recipient(recipient_id)
         return self.event
     else:
         return self.get_next_chain().raise_event(payload, recipient_id)
    def test_serialize(self):
        payload = Payload('TEST', {'test': 'test'})

        # Serialize
        payload = payload.serialize()

        self.assertEqual(payload, '{"test": "test", "uid": "TEST"}')
    def __process_sticker_message(
            self, messaging_event: Dict) -> Union[View, List[View]]:
        user_fb_id = messaging_event["sender"]["id"]
        sticker_id = messaging_event["message"]["sticker_id"]
        payload = Payload('STICKER', {'sticker_id': sticker_id})

        TypingService().typing_on(user_fb_id)

        logr.info("Processing received STICKER '{}' from '{}'.".format(
            payload, user_fb_id))
        view = self.message_chain_container.get_chain().raise_event(
            payload.serialize(), user_fb_id).raise_view()

        TypingService().typing_off(user_fb_id)

        return view
    def test_inject_payload(self):
        event = self.dummy_event()
        payload = Payload('Test')

        event.inject_payload(payload)

        self.assertEqual(event.payload(), payload)
    def __process_postback_message(
            self, messaging_event: Dict) -> Union[View, List[View]]:
        user_fb_id = messaging_event["sender"]["id"]
        payload = messaging_event["postback"]["payload"]
        payload_title = messaging_event["postback"]["title"]
        payload = Payload(payload, {'title': payload_title})

        TypingService().typing_on(user_fb_id)

        logr.info("Processing received POSTBACK '{}' from '{}'.".format(
            payload.serialize(), user_fb_id))
        view = self.postback_chain_container.get_chain().raise_event(
            payload.serialize(), user_fb_id).raise_view()

        TypingService().typing_off(user_fb_id)

        return view
    def test_raise_event(self, chain_payload_uid: str, payload_uid: str):
        event = self.event_dummy_test_case.dummy_event()

        # Create a chain that accepts payloads with a specified payloads uid
        chain = Chain(event, chain_payload_uid)
        payload = Payload(payload_uid)

        # Raise event with a serialized payloads
        matched_event = chain.raise_event(payload.serialize(), 'recipient')

        # If payloads match - events must be the same
        # If they don't - event must not match
        if chain_payload_uid == payload_uid:
            # Assert that matched event is the same
            self.assertEqual(matched_event, event)
        else:
            # Asset that event is a none event
            self.assertIsInstance(matched_event, NoneEvent)
 def test_match(self):
     self.assertTrue(
         Payload.match('{"test": "test", "uid": "TEST"}', 'TEST'))
    def test_deserialize(self):
        payload = Payload.deserialize('{"test": "test", "uid": "TEST"}')

        self.assertEqual(payload, Payload('TEST', {'test': 'test'}))