Ejemplo n.º 1
0
    def test_basic(self):
        instance = BadgeInstance.objects.all()[0]
        old_clicks = (instance.clickstats_set
                      .aggregate(Sum('clicks'))['clicks__sum'])

        response = handle_affiliate_link(instance)
        new_clicks = (instance.clickstats_set
                      .aggregate(Sum('clicks'))['clicks__sum'])

        eq_(new_clicks, old_clicks + 1)
        eq_(response['Location'], instance.badge.href)
Ejemplo n.º 2
0
def link(request, user_id, banner_id, banner_img_id):
    try:
        instance, created = (BannerInstance.objects.select_related()
                             .get_or_create(user_id=user_id,
                                            badge_id=banner_id,
                                            image_id=banner_img_id))
    except (IntegrityError):
        return HttpResponseRedirect(settings.DEFAULT_AFFILIATE_LINK)

    if created:
        banner_img = BannerImage.objects.select_related().get(pk=banner_img_id)
        instance.badge = banner_img.banner
        instance.save()

    return handle_affiliate_link(instance)