def test_update_url(self): """ test the update_url function. Given an url with possible GET parameter and a dict the function build a url with GET parameters updated by the dictionnary """ url1 = utils.update_url(u"https://www.example.com?toto=1", {u"tata": u"2"}) url2 = utils.update_url(b"https://www.example.com?toto=1", {b"tata": b"2"}) self.assertEqual(url1, u"https://www.example.com?tata=2&toto=1") self.assertEqual(url2, u"https://www.example.com?tata=2&toto=1") url3 = utils.update_url(u"https://www.example.com?toto=1", {u"toto": u"2"}) self.assertEqual(url3, u"https://www.example.com?toto=2")
def get_service_url(self, service, service_pattern, renew): """ Return the url to which the user must be redirected to after a Service Ticket has been generated :param unicode service: The service url for which we want a ticket. :param ServicePattern service_pattern: The service pattern matching ``service``. Beware that ``service`` must match :attr:`ServicePattern.pattern` and the current :class:`User` must pass :meth:`ServicePattern.check_user`. These checks are not done here and you must perform them before calling this method. :param bool renew: Should be ``True`` if authentication has been renewed. Must be ``False`` otherwise. :return unicode: The service url with the ticket GET param added. :rtype: unicode """ ticket = self.get_ticket(ServiceTicket, service, service_pattern, renew) url = utils.update_url(service, {'ticket': ticket.value}) logger.info("Service ticket created for service %s by user %s." % (service, self.username)) return url