def test_initial_packages_excluded(self): bar = create_addon('super bar') create_addon('super baz') self.es.refresh() data = package_search('super') eq_(0, len(data)) bar.latest.set_version('1.1') self.es.refresh() data2 = package_search('super') eq_(1, len(data2))
def homepage(r): # one more for the main one pkgs_limit = settings.HOMEPAGE_PACKAGES_NUMBER libraries = package_search(type='l').order_by('-activity')[:pkgs_limit] addons = package_search(type='a').order_by('-activity')[:pkgs_limit] try: # force the ES request here addons = list(addons) libraries = list(libraries) except Exception, ex: # can be MaxRetryError, TimeoutError, or internal ES error... # we should catch them all, log it, but still let the homepage show home_log.critical('ElasticSearch error: %s' % ex) addons = [] libraries = []
def test_copied_packages_excluded(self): foo = create_addon('foo tastic') foo.latest.set_version('1.0') fart = foo.copy(foo.author) foo.latest.save_new_revision(fart) self.es.refresh() data = package_search('foo') eq_(1, len(data))
def test_type_facet_filter(self): """ Type facet should not have a type filter in it's facet_filter. """ buzz = create_addon('buzz lightyear') buzz.latest.set_version('Infinity') toystory = create_library('the toy story buzz') toystory.latest.set_version('1') self.es.refresh() data = package_search('buzz', type='a') eq_(1, len(data)) types = dict((f['term'], f['count']) for f in data.facets['types']) eq_(1, types.get('a')) eq_(1, types.get('l'))
def get_object(self, request): form = SearchForm(request.GET) form.is_valid() self.query = query = form.cleaned_data t = query.get('type') self.search_type = _TYPES.get(t) self.search_query = query.get('q', '') filters = {} if t: filters['type'] = t if query.get('author'): filters['author'] = query['author'].id if query.get('copies'): filters['copies_count'] = query['copies'] return package_search(self.search_query, user=request.user, **filters).order_by('-created_at')[:20]
def test_sorting_by_activity(self): #create 10 packages and a random number of revisions now = datetime.datetime.utcnow() addons = [] for i in range(10): addon = create_addon('addon-{0}'.format(i)) addons.append(addon) for k in range(1,random.randrange(1,50)): r = addon.revisions.create(author=addon.author, revision_number=k) r.created_at=now-datetime.timedelta(random.randrange(1,365)) super(PackageRevision, r).save() calculate_activity_rating([a.pk for a in addons]) self.es.refresh() qs = package_search().order_by('activity') last_score = 1 for r in qs: eq_(r.activity<last_score, True) last_score = r.activity