Beispiel #1
0
    def test_version_sidebar(self):
        request = RequestFactory()
        request.GET = {}
        request.APP = amo.FIREFOX

        request.get(reverse('search.search'))
        facets = {
            u'platforms': [{u'doc_count': 58, u'key': 1}],
            u'appversions': [{u'doc_count': 58, u'key': 5000000200100}],
            u'categories': [{u'doc_count': 55, u'key': 1}],
            u'tags': [],
        }
        versions = version_sidebar(request, {}, facets)
        assert versions[0].selected

        versions = version_sidebar(request, {'appver': '5.0'}, facets)
        assert versions[1].selected

        # We're not storing the version in the session anymore: no memories.
        versions = version_sidebar(request, {}, facets)
        assert versions[0].selected

        # We read the appver from the cleaned form data.
        request.GET['appver'] = '123.4'
        # No form data, fallback to default (first entry).
        versions = version_sidebar(request, {}, facets)
        assert versions[0].selected
        # Form data has the proper version, use it.
        versions = version_sidebar(request, {'appver': '5.0'}, facets)
        assert versions[1].selected
        # Form data has the proper version, which is new: add it.
        versions = version_sidebar(request, {'appver': '123.4'}, facets)
        assert versions[1].selected
        assert len(versions) == 3
Beispiel #2
0
def req_factory_factory(url, user=None, post=False, data=None):
    """Creates a request factory, logged in with the user."""
    req = RequestFactory()
    if post:
        req = req.post(url, data or {})
    else:
        req = req.get(url, data or {})
    if user:
        req.user = UserProfile.objects.get(id=user.id)
        req.groups = user.groups.all()
    req.APP = None
    req.check_ownership = partial(check_ownership, req)
    return req
Beispiel #3
0
def req_factory_factory(url, user=None, post=False, data=None, session=None):
    """Creates a request factory, logged in with the user."""
    req = RequestFactory()
    if post:
        req = req.post(url, data or {})
    else:
        req = req.get(url, data or {})
    if user:
        req.user = UserProfile.objects.get(id=user.id)
    else:
        req.user = AnonymousUser()
    if session is not None:
        req.session = session
    req.APP = None
    req.check_ownership = partial(check_ownership, req)
    return req
Beispiel #4
0
    def check_appver_filters(self, appver, expected):
        request = RequestFactory()
        request.GET = {}
        request.APP = amo.FIREFOX

        facets = {
            u'platforms': [{u'doc_count': 58, u'key': 1}],
            u'appversions': [{u'doc_count': 58, u'key': 5000000200100}],
            u'categories': [{u'doc_count': 55, u'key': 1}],
            u'tags': []
        }

        versions = version_sidebar(request,
                                   {'appver': floor_version(appver)}, facets)

        all_ = versions.pop(0)
        assert all_.text == 'Any %s' % unicode(request.APP.pretty)
        assert not all_.selected == expected

        return [v.__dict__ for v in versions]