Exemplo n.º 1
0
    def test_cloning(self):
        """
        Make sure cloning works
        """

        msg = NotificationMessage(payload={'foo': 'bar'})

        clone = NotificationMessage.clone(msg)

        self.assertEqual(msg, clone)

        # now change the cloned payload and assert that the original one
        # did not change

        clone.payload['foo'] = 'changed'
        self.assertEqual(msg.payload['foo'], 'bar')
        self.assertEqual(clone.payload['foo'], 'changed')
Exemplo n.º 2
0
    def test_cloning(self):
        """
        Make sure cloning works
        """

        msg = NotificationMessage(
            payload={'foo': 'bar'}
        )

        clone = NotificationMessage.clone(msg)

        self.assertEqual(msg, clone)

        # now change the cloned payload and assert that the original one
        # did not change

        clone.payload['foo'] = 'changed'
        self.assertEqual(msg.payload['foo'], 'bar')
        self.assertEqual(clone.payload['foo'], 'changed')
Exemplo n.º 3
0
    def _get_linked_resolved_msg(self, msg):
        """
        This helper will attempt to resolve all
        links that are present in the message

        resolve any links that may need conversion into URL paths
        This uses a subdict named "_resolve_links" in the msg.resolve_links
        field:

            resolve_links = {
                "_resolve_links": {
                    "_click_link": {
                       "param1": "val1",
                       "param2": "param2"
                    },
                    :
                },
             :
            }

        This above will try to resolve the URL for the link named "_click_link" (for
        example, when a user clicks on a notification, the should go to that URL), with the
        URL parameters "param1"="val1" and "param2"="val2", and put that link name back in
        the main payload dictionary as "_click_link"
        """

        if msg.resolve_links:
            for link_name, link_params in six.iteritems(msg.resolve_links):
                resolved_link = self.resolve_msg_link(msg, link_name,
                                                      link_params)
                if resolved_link:
                    # copy the msg because we are going to alter it and we don't want to affect
                    # the passed in version
                    msg = NotificationMessage.clone(msg)

                    # if we could resolve, then store the resolved link in the payload itself
                    msg.payload[link_name] = resolved_link

        # return the msg which could be a clone of the original one
        return msg
    def _get_linked_resolved_msg(self, msg):
        """
        This helper will attempt to resolve all
        links that are present in the message

        resolve any links that may need conversion into URL paths
        This uses a subdict named "_resolve_links" in the msg.resolve_links
        field:

            resolve_links = {
                "_resolve_links": {
                    "_click_link": {
                       "param1": "val1",
                       "param2": "param2"
                    },
                    :
                },
             :
            }

        This above will try to resolve the URL for the link named "_click_link" (for
        example, when a user clicks on a notification, the should go to that URL), with the
        URL parameters "param1"="val1" and "param2"="val2", and put that link name back in
        the main payload dictionary as "_click_link"
        """

        if msg.resolve_links:
            for link_name, link_params in msg.resolve_links.iteritems():
                resolved_link = self.resolve_msg_link(msg, link_name,
                                                      link_params)
                if resolved_link:
                    # copy the msg because we are going to alter it and we don't want to affect
                    # the passed in version
                    msg = NotificationMessage.clone(msg)

                    # if we could resolve, then store the resolved link in the payload itself
                    msg.payload[link_name] = resolved_link

        # return the msg which could be a clone of the original one
        return msg