def build_send_url(self, router_url, backend, recipients_list, text, priority=1, **kwargs):
        """
        Constructs an appropriate send url for the given message.
        """
        # first build up our list of parameters
        recipients = ' '.join(recipients_list)
        special_chars_mapping = getattr(settings, "SPECIAL_CHARS_MAPPING", {})
        text = replace_characters(text, special_chars_mapping)

        installed_backends = getattr(settings, "BACKENDS_CONFIGURATION", {})

        if backend in installed_backends:
            return self.build_send_url_from_backend(backend, installed_backends[backend], text, recipients_list)
        else:
            params = {
                'backend': backend,
                'recipient': recipients,
                'text': text,
                'priority': priority,
                }

            # make sure our parameters are URL encoded
            params.update(kwargs)
            for k, v in params.items():
                params[k] = quote_plus(stringify(v))

            # is this actually a dict?  if so, we want to look up the appropriate backend
            if type(router_url) is dict:
                router_dict = router_url
                backend_name = backend

                # is there an entry for this backend?
                if backend_name in router_dict:
                    router_url = router_dict[backend_name]

                # if not, look for a default backend
                elif 'default' in router_dict:
                    router_url = router_dict['default']

                # none?  blow the hell up
                else:
                    self.error(
                        "No router url mapping found for backend '%s', check your settings.ROUTER_URL setting" % backend_name)
                    raise Exception(
                        "No router url mapping found for backend '%s', check your settings.ROUTER_URL setting" % backend_name)

        # return our built up url with all our variables substituted in
        full_url = router_url % params
        self.info("Full URL - %s" % full_url)

        return full_url
 def test_encode_returns_original_when_UnicodError_not_raise(self):
     text = 'çà çó'
     self.assertEqual(text, stringify(text))
    def test_incompatible_utf_8_text_are_stringified_2(self):
        Mock.__str__ = new_str_representation
        text = Mock(spec=str)
        text.encode = Mock(return_value = VALID_UNICODE_TEXT)

        self.assertEqual(VALID_UNICODE_TEXT, stringify(text))