def follow_banner_link(request, banner_instance_id): """ Add a click to a banner instance and redirect the user to the Firefox download page. """ try: banner_instance = FacebookBannerInstance.objects.select_related("banner").get(id=banner_instance_id) except FacebookBannerInstance.DoesNotExist: return django_redirect(settings.FACEBOOK_DOWNLOAD_URL) # Do not add a click if the request is from the Facebook bot. if not is_facebook_bot(request): add_click.delay(banner_instance_id) return django_redirect(banner_instance.banner.link)
def follow_banner_link(request, banner_instance_id): """ Add a click to a banner instance and redirect the user to the Firefox download page. """ try: banner_instance = ( FacebookBannerInstance.objects.select_related('banner').get( id=banner_instance_id)) except FacebookBannerInstance.DoesNotExist: return django_redirect(settings.FACEBOOK_DOWNLOAD_URL) # Do not add a click if the request is from the Facebook bot. if not is_facebook_bot(request): add_click.delay(banner_instance_id) return django_redirect(banner_instance.banner.link)
def test_is_not_a_bot(self): request = self.factory.get('/', HTTP_USER_AGENT='not.facebook') eq_(is_facebook_bot(request), False)
def test_is_bot(self): request = self.factory.get('/', HTTP_USER_AGENT=FACEBOOK_USER_AGENT) eq_(is_facebook_bot(request), True)