示例#1
0
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), "")
示例#2
0
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))
示例#3
0
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), '')
示例#4
0
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), '')
示例#5
0
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), '')
示例#6
0
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), '')
示例#7
0
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), '')
示例#8
0
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), '')
示例#9
0
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))
示例#10
0
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), '')
示例#11
0
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))
示例#12
0
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')
示例#13
0
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')
示例#14
0
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")
示例#15
0
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))
示例#16
0
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')))
示例#17
0
def test_user_link_xss():
    u = UserProfile(username='******',
                    display_name='<script>alert(1)</script>', pk=1)
    html = "&lt;script&gt;alert(1)&lt;/script&gt;"
    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&#34;&#39;&gt;&lt;iframe onload=alert(3)&gt;"""
    eq_(user_link(u), '<a href="%s" title="%s">%s</a>' % (u.get_url_path(),
                                                          html, html))
示例#18
0
def test_user_link_xss():
    u = UserProfile(username='******',
                    display_name='<script>alert(1)</script>', pk=1)
    html = "&lt;script&gt;alert(1)&lt;/script&gt;"
    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&#34;&#39;&gt;&lt;iframe onload=alert(3)&gt;"""
    eq_(user_link(u), '<a href="%s" title="%s">%s</a>' % (u.get_url_path(),
                                                          html, html))
示例#19
0
def test_user_link_xss():
    u = UserProfile(username='******',
                    display_name='<script>alert(1)</script>',
                    pk=1)
    url = reverse('users.profile', args=[1])
    html = "&lt;script&gt;alert(1)&lt;/script&gt;"
    eq_(user_link(u), '<a href="%s">%s</a>' % (url, html))
示例#20
0
    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.'
示例#21
0
    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.'
示例#22
0
    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."
示例#23
0
def test_user_link_xss():
    u = UserProfile(username='******',
                    display_name='<script>alert(1)</script>',
                    pk=1)
    html = "&lt;script&gt;alert(1)&lt;/script&gt;"
    eq_(user_link(u), '<a href="%s">%s</a>' % (u.get_url_path(), html))
示例#24
0
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]))
示例#25
0
def test_user_link_xss():
    u = UserProfile(username='******',
                    display_name='<script>alert(1)</script>', pk=1)
    html = "&lt;script&gt;alert(1)&lt;/script&gt;"
    eq_(user_link(u), '<a href="%s">%s</a>' % (u.get_url_path(), html))
示例#26
0
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), "")
示例#27
0
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]))
示例#28
0
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]))
示例#29
0
def test_user_link_xss():
    u = UserProfile(username="******", display_name="<script>alert(1)</script>", pk=1)
    url = reverse("users.profile", args=[1])
    html = "&lt;script&gt;alert(1)&lt;/script&gt;"
    eq_(user_link(u), '<a href="%s">%s</a>' % (url, html))