def test_users_list(): u1 = UserProfile(username="******", display_name="John Connor", pk=1) u2 = UserProfile(username="******", display_name="Sarah Connor", pk=2) eq_(users_list([u1, u2]), ", ".join((user_link(u1), user_link(u2)))) # handle None gracefully eq_(user_link(None), "")
def test_user_link_unicode(): """make sure helper won't choke on unicode input""" u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller', pk=1) eq_(user_link(u), u'<a href="%s">Jürgen Müller</a>' % u.get_url_path()) u = UserProfile(username='******', pk=1) eq_(user_link(u), u'<a href="%s">%s</a>' % (u.get_url_path(), u.username))
def test_user_link(): u = UserProfile(username='******', display_name='John Connor', pk=1) eq_(user_link(u), '<a href="%s" title="%s">John Connor</a>' % (u.get_url_path(), u.name)) # handle None gracefully eq_(user_link(None), '')
def test_user_link(): u = UserProfile(username='******', display_name='John Connor', pk=1) eq_(user_link(u), '<a href="%s">John Connor</a>' % reverse('users.profile', args=[1])) # handle None gracefully eq_(user_link(None), '')
def test_users_list(): u1 = UserProfile(username='******', display_name='John Connor', pk=1) u2 = UserProfile(username='******', display_name='Sarah Connor', pk=2) eq_(users_list([u1, u2]), ', '.join((user_link(u1), user_link(u2)))) # handle None gracefully eq_(user_link(None), '')
def test_users_list(): u1 = UserProfile(firstname='John', lastname='Connor', pk=1) u2 = UserProfile(firstname='Sarah', lastname='Connor', pk=2) eq_(users_list([u1, u2]), ', '.join((user_link(u1), user_link(u2)))) # handle None gracefully eq_(user_link(None), '')
def test_user_link_unicode(): """make sure helper won't choke on unicode input""" u = UserProfile(username=u"jmüller", display_name=u"Jürgen Müller", pk=1) eq_(user_link(u), u'<a href="%s">Jürgen Müller</a>' % reverse("users.profile", args=[1])) u = UserProfile(username="******", pk=1) url = reverse("users.profile", args=[1]) eq_(user_link(u), u'<a href="%s">%s</a>' % (url, u.username))
def test_short_users_list(): """Test the option to shortened the users list to a certain size.""" # short list with 'others' u1 = UserProfile(username='******', display_name='Oscar the Grouch', pk=1) u2 = UserProfile(username='******', display_name='Grover', pk=2) u3 = UserProfile(username='******', display_name='Cookie Monster', pk=3) shortlist = users_list([u1, u2, u3], size=2) eq_(shortlist, ', '.join((user_link(u1), user_link(u2))) + ', others')
def test_short_users_list(): """Test the option to shortened the users list to a certain size.""" # short list with 'others' u1 = UserProfile(username="******", display_name="Oscar the Grouch", pk=1) u2 = UserProfile(username="******", display_name="Grover", pk=2) u3 = UserProfile(username="******", display_name="Cookie Monster", pk=3) shortlist = users_list([u1, u2, u3], size=2) eq_(shortlist, ", ".join((user_link(u1), user_link(u2))) + ", others")
def test_user_link_unicode(): """make sure helper won't choke on unicode input""" u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller', pk=1) eq_(user_link(u), u'<a href="%s">Jürgen Müller</a>' % reverse('users.profile', args=[1])) u = UserProfile(username='******', pk=1) url = reverse('users.profile', args=[1]) eq_(user_link(u), u'<a href="%s">%s</a>' % (url, u.username))
def test_user_link_unicode(): """make sure helper won't choke on unicode input""" u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller', pk=1) eq_(user_link(u), u'<a href="%s">Jürgen Müller</a>' % reverse('users.profile', args=[1])) u = UserProfile(username='******', pk=1) url = reverse('users.profile', args=[1]) eq_(user_link(u), u'<a href="%s">%s</a>' % (url, u.username.decode('utf-8')))
def test_user_link_xss(): u = UserProfile(username='******', display_name='<script>alert(1)</script>', pk=1) html = "<script>alert(1)</script>" eq_(user_link(u), '<a href="%s" title="%s">%s</a>' % (u.get_url_path(), html, html)) u = UserProfile(username='******', display_name="""xss"'><iframe onload=alert(3)>""", pk=1) html = """xss"'><iframe onload=alert(3)>""" eq_(user_link(u), '<a href="%s" title="%s">%s</a>' % (u.get_url_path(), html, html))
def test_user_link_xss(): u = UserProfile(username='******', display_name='<script>alert(1)</script>', pk=1) url = reverse('users.profile', args=[1]) html = "<script>alert(1)</script>" eq_(user_link(u), '<a href="%s">%s</a>' % (url, html))
def to_string(self, type_=None): log_type = amo.LOG_BY_ID[self.action] if type_ and hasattr(log_type, '%s_format' % type_): format = getattr(log_type, '%s_format' % type_) else: format = log_type.format # We need to copy arguments so we can remove elements from it # while we loop over self.arguments. arguments = copy(self.arguments) addon = None review = None version = None collection = None tag = None group = None for arg in self.arguments: if isinstance(arg, Addon) and not addon: if arg.is_listed: addon = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.name) else: addon = self.f(u'{0}', arg.name) arguments.remove(arg) if isinstance(arg, Review) and not review: review = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), _('Review')) arguments.remove(arg) if isinstance(arg, Version) and not version: text = _('Version {0}') if arg.is_listed: version = self.f(u'<a href="{1}">%s</a>' % text, arg.version, arg.get_url_path()) else: version = self.f(text, arg.version) arguments.remove(arg) if isinstance(arg, Collection) and not collection: collection = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.name) arguments.remove(arg) if isinstance(arg, Tag) and not tag: if arg.can_reverse(): tag = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.tag_text) else: tag = self.f('{0}', arg.tag_text) if isinstance(arg, Group) and not group: group = arg.name arguments.remove(arg) user = user_link(self.user) try: kw = dict(addon=addon, review=review, version=version, collection=collection, tag=tag, user=user, group=group) return self.f(format, *arguments, **kw) except (AttributeError, KeyError, IndexError): log.warning('%d contains garbage data' % (self.id or 0)) return 'Something magical happened.'
def to_string(self, type_=None): log_type = amo.LOG_BY_ID[self.action] if type_ and hasattr(log_type, '%s_format' % type_): format = getattr(log_type, '%s_format' % type_) else: format = log_type.format # We need to copy arguments so we can remove elements from it # while we loop over self.arguments. arguments = copy(self.arguments) addon = None review = None version = None collection = None tag = None group = None for arg in self.arguments: if isinstance(arg, Addon) and not addon: addon = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.name) arguments.remove(arg) if isinstance(arg, Review) and not review: review = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), _('Review')) arguments.remove(arg) if isinstance(arg, Version) and not version: text = _('Version {0}') version = self.f(u'<a href="{1}">%s</a>' % text, arg.version, arg.get_url_path()) arguments.remove(arg) if isinstance(arg, Collection) and not collection: collection = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.name) arguments.remove(arg) if isinstance(arg, Tag) and not tag: if arg.can_reverse(): tag = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.tag_text) else: tag = self.f('{0}', arg.tag_text) if isinstance(arg, Group) and not group: group = arg.name arguments.remove(arg) user = user_link(self.user) try: kw = dict(addon=addon, review=review, version=version, collection=collection, tag=tag, user=user, group=group) return self.f(format, *arguments, **kw) except (AttributeError, KeyError, IndexError): log.warning('%d contains garbage data' % (self.id or 0)) return 'Something magical happened.'
def to_string(self, type=None): log_type = amo.LOG_BY_ID[self.action] if type and hasattr(log_type, "%s_format" % type): format = getattr(log_type, "%s_format" % type) else: format = log_type.format # We need to copy arguments so we can remove elements from it # while we loop over self.arguments. arguments = copy(self.arguments) addon = None review = None version = None collection = None tag = None for arg in self.arguments: if isinstance(arg, Addon) and not addon: addon = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.name) arguments.remove(arg) if isinstance(arg, Review) and not review: review = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), _("Review")) arguments.remove(arg) if isinstance(arg, Version) and not version: text = _("Version %s") % arg.version version = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), text) arguments.remove(arg) if isinstance(arg, Collection) and not collection: collection = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.name) arguments.remove(arg) if isinstance(arg, Tag) and not tag: if arg.can_reverse(): tag = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.tag_text) else: tag = self.f("{0}", arg.tag_text) user = user_link(self.user) try: kw = dict(addon=addon, review=review, version=version, collection=collection, tag=tag, user=user) return self.f(format, *arguments, **kw) except (AttributeError, KeyError, IndexError): log.warning("%d contains garbage data" % (self.id or 0)) return "Something magical happened."
def test_user_link_xss(): u = UserProfile(username='******', display_name='<script>alert(1)</script>', pk=1) html = "<script>alert(1)</script>" eq_(user_link(u), '<a href="%s">%s</a>' % (u.get_url_path(), html))
def test_user_link_unicode(): """make sure helper won't choke on unicode input""" u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller', pk=1) eq_(user_link(u), u'<a href="%s">Jürgen Müller</a>' % reverse('users.profile', args=[1]))
def test_user_link(): u = UserProfile(username="******", display_name="John Connor", pk=1) eq_(user_link(u), '<a href="%s">John Connor</a>' % reverse("users.profile", args=[1])) # handle None gracefully eq_(user_link(None), "")
def test_user_link_unicode(): """make sure helper won't choke on unicode input""" u = UserProfile(firstname=u'Jürgen', lastname=u'Müller', pk=1) eq_(user_link(u), u'<a href="%s">Jürgen Müller</a>' % reverse('users.profile', args=[1]))
def test_user_link(): u = UserProfile(firstname='John', lastname='Connor', pk=1) eq_(user_link(u), '<a href="%s">John Connor</a>' % reverse('users.profile', args=[1]))
def test_user_link_xss(): u = UserProfile(username="******", display_name="<script>alert(1)</script>", pk=1) url = reverse("users.profile", args=[1]) html = "<script>alert(1)</script>" eq_(user_link(u), '<a href="%s">%s</a>' % (url, html))