def test_advert_empty_one(self): distr_percent_advs_list = [('b', 10, []), ('a', 70, [1, 5, 8]), ('c', 20, [9, 10, 11, 12])] stat = collections.defaultdict(int) for i in range(0, 1000): aa = advert_choice(distr_percent_advs_list) stat[aa[0]] += 1 self.assertEquals({'a': 784, 'c': 216}, stat)
def test_advert_choice(self): distr_percent_advs_list = [('b', 10, [2, 4, 6, 7]), ('a', 70, [1, 5, 8]), ('c', 20, [9, 10, 11, 12])] advert_choisen = [] stat = collections.defaultdict(int) for i in range(0, 1000): aa = advert_choice(distr_percent_advs_list) advert_choisen.append(aa) stat[aa[0]] += 1 self.assertEquals({'a': 711, 'c': 185, 'b': 104}, stat)
def advert_select(request): """view for lookup adverts""" if request.method == 'POST': distr_percent_advs_list = make_dist_adv_list() aa = advert_choice(distr_percent_advs_list) a = Advertisement.objects.get(pk=aa[1]) Distributor.objects.filter(pk=aa[0]).update(shown_adverts=F('shown_adverts')+1) response = JsonResponse({'banner': a.banner.url, 'banner_link': a.banner_link}) else: return HttpResponseNotFound('<h1>use Post instead of GET method</h1>') return response
def advert_select(request): """view for lookup adverts""" if request.method == 'POST': distr_percent_advs_list = make_dist_adv_list() aa = advert_choice(distr_percent_advs_list) a = Advertisement.objects.get(pk=aa[1]) Distributor.objects.filter(pk=aa[0]).update( shown_adverts=F('shown_adverts') + 1) response = JsonResponse({ 'banner': a.banner.url, 'banner_link': a.banner_link }) else: return HttpResponseNotFound('<h1>use Post instead of GET method</h1>') return response