class TestDetail(amo.tests.TestCase): def setUp(self): self.webapp = Webapp(name='woo', app_slug='yeah') self.webapp.save() def test_more_url(self): response = self.client.get(self.webapp.get_url_path()) eq_(pq(response.content)('#more-webpage').attr('data-more-url'), self.webapp.get_url_path(more=True))
def test_app_slug_collision(self): Webapp(app_slug='slug').save() w2 = Webapp(app_slug='slug') w2.save() eq_(w2.app_slug, 'slug-1') w3 = Webapp(app_slug='slug') w3.save() eq_(w3.app_slug, 'slug-2')
def queue_counts(type=None, **kw): def construct_query(query_type, days_min=None, days_max=None): def apply_query(query, *args): query = query.having(*args) return query query = query_type.objects if days_min: query = apply_query(query, 'waiting_time_days >=', days_min) if days_max: query = apply_query(query, 'waiting_time_days <=', days_max) return query.count counts = {'pending': construct_query(ViewPendingQueue, **kw), 'nominated': construct_query(ViewFullReviewQueue, **kw), 'prelim': construct_query(ViewPreliminaryQueue, **kw), 'moderated': Review.objects.filter(reviewflag__isnull=False, editorreview=1).count, 'apps': Webapp.pending().count} rv = {} if isinstance(type, basestring): return counts[type]() for k, v in counts.items(): if not isinstance(type, list) or k in type: rv[k] = v() return rv
def verify_app_domain(manifest_url): if settings.WEBAPPS_UNIQUE_BY_DOMAIN: domain = Webapp.domain_from_url(manifest_url) if Addon.objects.filter(app_domain=domain).exists(): raise forms.ValidationError( _('An app already exists on this domain, ' 'only one app per domain is allowed.'))
def queue_counts(type=None, **kw): def construct_query(query_type, days_min=None, days_max=None): def apply_query(query, *args): query = query.having(*args) return query query = query_type.objects if days_min: query = apply_query(query, 'waiting_time_days >=', days_min) if days_max: query = apply_query(query, 'waiting_time_days <=', days_max) return query.count counts = { 'pending': construct_query(ViewPendingQueue, **kw), 'nominated': construct_query(ViewFullReviewQueue, **kw), 'prelim': construct_query(ViewPreliminaryQueue, **kw), 'moderated': Review.objects.filter(reviewflag__isnull=False, editorreview=1).count, 'apps': Webapp.pending().count } rv = {} if isinstance(type, basestring): return counts[type]() for k, v in counts.items(): if not isinstance(type, list) or k in type: rv[k] = v() return rv
def app_search(request, template=None): form = ESSearchForm(request.GET or {}, type=amo.ADDON_WEBAPP) form.is_valid() # Let the form try to clean data. query = form.cleaned_data qs = (Webapp.search().query(or_=name_query(query['q'])) .filter(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC, is_disabled=False) .facet(tags={'terms': {'field': 'tag'}}, categories={'terms': {'field': 'category', 'size': 100}})) if query.get('tag'): qs = qs.filter(tag=query['tag']) if query.get('cat'): qs = qs.filter(category=query['cat']) if query.get('sort'): mapping = {'downloads': '-weekly_downloads', 'rating': '-bayesian_rating', 'created': '-created', 'name': '-name_sort', 'hotness': '-hotness'} qs = qs.order_by(mapping[query['sort']]) pager = amo.utils.paginate(request, qs) facets = pager.object_list.facets ctx = { 'pager': pager, 'query': query, 'form': form, 'sorting': sort_sidebar(request, query, form), 'categories': category_sidebar(request, query, facets), 'tags': tag_sidebar(request, query, facets), } return jingo.render(request, template, ctx)
def app_search(request, tag_name=None, template=None): form = ESSearchForm(request.GET.copy() or {}, type=amo.ADDON_WEBAPP) form.is_valid() # Let the form try to clean data. query = form.cleaned_data # TODO(apps): We should figure out if we really want tags for apps. if tag_name: query['tag'] = tag_name qs = (Webapp.search().filter(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC, is_disabled=False).facet( tags={'terms': { 'field': 'tag' }}, categories={ 'terms': { 'field': 'category', 'size': 200 } })) filters = ['cat', 'price', 'sort', 'tag'] mapping = { 'downloads': '-weekly_downloads', 'rating': '-bayesian_rating', 'created': '-created', 'name': 'name_sort', 'hotness': '-hotness', 'price': 'price' } qs = _filter_search(request, qs, query, filters, mapping, [amo.ADDON_WEBAPP]) pager = amo.utils.paginate(request, qs) facets = pager.object_list.facets sort, extra_sort = split_choices(form.sort_choices, 'price') ctx = { 'is_pjax': request.META.get('HTTP_X_PJAX'), 'pager': pager, 'query': query, 'form': form, 'sorting': sort_sidebar(request, query, form), 'sort_opts': sort, 'extra_sort_opts': extra_sort, 'sort': query.get('sort'), 'webapp': True, } if not ctx['is_pjax']: ctx.update({ 'prices': price_sidebar(request, query, facets), 'categories': category_sidebar(request, query, facets), 'tags': tag_sidebar(request, query, facets), }) return jingo.render(request, template, ctx)
def app_search(request, tag_name=None, template=None): form = ESSearchForm(request.GET.copy() or {}, type=amo.ADDON_WEBAPP) form.is_valid() # Let the form try to clean data. query = form.cleaned_data # TODO(apps): We should figure out if we really want tags for apps. if tag_name: query["tag"] = tag_name qs = ( Webapp.search() .filter(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC, is_disabled=False) .facet(tags={"terms": {"field": "tag"}}, categories={"terms": {"field": "category", "size": 200}}) ) filters = ["cat", "price", "sort", "tag"] mapping = { "downloads": "-weekly_downloads", "rating": "-bayesian_rating", "created": "-created", "name": "name_sort", "hotness": "-hotness", "price": "price", } qs = _filter_search(request, qs, query, filters, mapping, [amo.ADDON_WEBAPP]) pager = amo.utils.paginate(request, qs) facets = pager.object_list.facets sort, extra_sort = split_choices(form.sort_choices, "price") ctx = { "is_pjax": request.META.get("HTTP_X_PJAX"), "pager": pager, "query": query, "form": form, "sorting": sort_sidebar(request, query, form), "sort_opts": sort, "extra_sort_opts": extra_sort, "sort": query.get("sort"), "webapp": True, } if not ctx["is_pjax"]: ctx.update( { "prices": price_sidebar(request, query, facets), "categories": category_sidebar(request, query, facets), "tags": tag_sidebar(request, query, facets), } ) return jingo.render(request, template, ctx)
def test_app_slug_collision(self): Webapp(app_slug="slug").save() w2 = Webapp(app_slug="slug") w2.save() eq_(w2.app_slug, "slug-1") w3 = Webapp(app_slug="slug") w3.save() eq_(w3.app_slug, "slug-2")
def app_search(request, tag_name=None, template=None): form = ESSearchForm(request.GET.copy() or {}, type=amo.ADDON_WEBAPP) form.is_valid() # Let the form try to clean data. query = form.cleaned_data # TODO(apps): We should figure out if we really want tags for apps. if tag_name: query['tag'] = tag_name qs = (Webapp.search() .filter(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC, is_disabled=False) .facet(tags={'terms': {'field': 'tag'}}, categories={'terms': {'field': 'category', 'size': 200}})) filters = ['cat', 'price', 'sort', 'tag'] mapping = {'downloads': '-weekly_downloads', 'rating': '-bayesian_rating', 'created': '-created', 'name': 'name_sort', 'hotness': '-hotness', 'price': 'price'} qs = _filter_search(request, qs, query, filters, mapping, [amo.ADDON_WEBAPP]) pager = amo.utils.paginate(request, qs) facets = pager.object_list.facets sort, extra_sort = split_choices(form.sort_choices, 'price') ctx = { 'is_pjax': request.META.get('HTTP_X_PJAX'), 'pager': pager, 'query': query, 'form': form, 'sorting': sort_sidebar(request, query, form), 'sort_opts': sort, 'extra_sort_opts': extra_sort, 'sort': query.get('sort'), 'webapp': True, } if not ctx['is_pjax']: ctx.update({ 'prices': price_sidebar(request, query, facets), 'categories': category_sidebar(request, query, facets), 'tags': tag_sidebar(request, query, facets), }) return jingo.render(request, template, ctx)
def app_search(request, template=None): form = ESSearchForm(request.GET or {}, type=amo.ADDON_WEBAPP) form.is_valid() # Let the form try to clean data. query = form.cleaned_data qs = (Webapp.search().query(or_=name_query(query['q'])).filter( type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC, is_disabled=False).facet( tags={'terms': { 'field': 'tag' }}, categories={'terms': { 'field': 'category', 'size': 100 }})) if query.get('tag'): qs = qs.filter(tag=query['tag']) if query.get('cat'): qs = qs.filter(category=query['cat']) if query.get('sort'): mapping = { 'downloads': '-weekly_downloads', 'rating': '-bayesian_rating', 'created': '-created', 'name': '-name_sort', 'hotness': '-hotness' } qs = qs.order_by(mapping[query['sort']]) pager = amo.utils.paginate(request, qs) facets = pager.object_list.facets ctx = { 'is_pjax': request.META.get('HTTP_X_PJAX'), 'pager': pager, 'query': query, 'form': form, 'sorting': sort_sidebar(request, query, form), 'sort_opts': form.fields['sort'].choices, } if not ctx['is_pjax']: ctx.update({ 'categories': category_sidebar(request, query, facets), 'tags': tag_sidebar(request, query, facets), }) return jingo.render(request, template, ctx)
def app_search(request, template=None): form = ESSearchForm(request.GET or {}, type=amo.ADDON_WEBAPP) form.is_valid() # Let the form try to clean data. query = form.cleaned_data qs = ( Webapp.search() .query(or_=name_query(query["q"])) .filter(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC, is_disabled=False) .facet(tags={"terms": {"field": "tag"}}, categories={"terms": {"field": "category", "size": 100}}) ) if query.get("tag"): qs = qs.filter(tag=query["tag"]) if query.get("cat"): qs = qs.filter(category=query["cat"]) if query.get("sort"): mapping = { "downloads": "-weekly_downloads", "rating": "-bayesian_rating", "created": "-created", "name": "-name_sort", "hotness": "-hotness", } qs = qs.order_by(mapping[query["sort"]]) pager = amo.utils.paginate(request, qs) facets = pager.object_list.facets ctx = { "pager": pager, "query": query, "form": form, "sorting": sort_sidebar(request, query, form), "categories": category_sidebar(request, query, facets), "tags": tag_sidebar(request, query, facets), } return jingo.render(request, template, ctx)
def test_webapp_type(self): webapp = Webapp() webapp.save() eq_(webapp.type, amo.ADDON_WEBAPP)
def test_none(self): Webapp.domain_from_url(None)
def test_subdomains(self): eq_(Webapp.domain_from_url('http://apps.mozilla.com/'), 'apps.mozilla.com')
def test_normalize_www(self): eq_(Webapp.domain_from_url('http://www.mozilla.com/super/rad.webapp'), 'mozilla.com')
def test_simple(self): eq_(Webapp.domain_from_url('http://mozilla.com/'), 'mozilla.com')
def test_app_slugs_separate_from_addon_slugs(self): Addon.objects.create(type=1, slug='slug') webapp = Webapp(app_slug='slug') webapp.save() eq_(webapp.slug, 'app-%s' % webapp.id) eq_(webapp.app_slug, 'slug')
def test_app_slug_blocklist(self): BlacklistedSlug.objects.create(name='slug') w = Webapp(app_slug='slug') w.save() eq_(w.app_slug, 'slug~')
def test_reviewed(self): assert not Webapp().is_unreviewed()
def can_be_purchased(self): assert Webapp(premium_type=True).can_be_purchased() assert not Webapp(premium_type=False).can_be_purchased()
def test_get_origin(self): url = 'http://www.xx.com:4000/randompath/manifest.webapp' webapp = Webapp(manifest_url=url) eq_(webapp.origin, 'http://www.xx.com:4000')
def test_get_url_path_more(self): webapp = Webapp(app_slug='woo') eq_(webapp.get_url_path(more=True), '/en-US/apps/app/woo/more')
def test_get_url_path(self): webapp = Webapp(app_slug='woo') eq_(webapp.get_url_path(), '/en-US/apps/app/woo/')
def test_with_port(self): eq_(Webapp.domain_from_url('http://mozilla.com:9000/'), 'mozilla.com')
def test_empty(self): Webapp.domain_from_url('')
def test_https(self): eq_(Webapp.domain_from_url('https://mozilla.com/'), 'mozilla.com')
def test_get_url_path_more(self): webapp = Webapp(app_slug="woo") eq_(webapp.get_url_path(more=True), "/en-US/apps/app/woo/more")
class WebappTest(amo.tests.TestCase): def setUp(self): self.webapp = Webapp(name="woo", app_slug="yeah") self.webapp.save() self.url = self.webapp.get_url_path()
def test_long_path(self): eq_(Webapp.domain_from_url('http://mozilla.com/super/rad.webapp'), 'mozilla.com')
def setUp(self): self.webapp = Webapp(name="woo", app_slug="yeah") self.webapp.save() self.url = self.webapp.get_url_path()
def test_mark_done_pending(self): w = Webapp() eq_(w.status, amo.STATUS_NULL) w.mark_done() eq_(w.status, amo.STATUS_PENDING)
def test_has_icon_in_manifest(self, get_manifest_json): webapp = Webapp() get_manifest_json.return_value = {} eq_(webapp.has_icon_in_manifest(), False)
def queue_apps(request): qs = Webapp.pending().annotate(Count('abuse_reports')) return _queue(request, WebappQueueTable, 'apps', qs=qs)
def test_mark_done_public(self): w = Webapp() eq_(w.status, amo.STATUS_NULL) w.mark_done() eq_(w.status, amo.STATUS_PUBLIC)
def test_has_icon_in_manifest(self, get_manifest_json): webapp = Webapp() get_manifest_json.return_value = {'icons': {}} eq_(webapp.has_icon_in_manifest(), True)