def prepare(self, context): super(PollBox, self).prepare(context) SECOND_RENDER = context.get('SECOND_RENDER', False) self.state = None if DOUBLE_RENDER and SECOND_RENDER or context.has_key('request'): from ella.polls import views self.state = views.poll_check_vote(context['request'], self.obj)
def prepare(self, context): super(PollBox, self).prepare(context) SECOND_RENDER = context.get('SECOND_RENDER', False) self.state = None if getattr(settings, 'DOUBLE_RENDER', False) and not SECOND_RENDER or 'request' not in context: return from ella.polls import views self.state = views.poll_check_vote(context['request'], self.obj)
def test_check_vote_authetnticated_user_allready_voted_by_session(self): user = User.objects.create(username='******') session = {views.POLLS_COOKIE_NAME: [self.poll.pk]} self.assert_equals( views.POLL_USER_ALLREADY_VOTED, views.poll_check_vote(build_request(user=user, session=session), self.poll))
def test_check_vote_annonymous_user_allready_voted_by_cookies(self): cookies = {views.POLLS_COOKIE_NAME: ','.join(str(self.poll.pk))} self.assert_equals( views.POLL_USER_ALLREADY_VOTED, views.poll_check_vote(build_request(cookies=cookies), self.poll))
def test_check_vote_authetnticated_user_allready_voted_by_vote_object(self): user = User.objects.create(username='******') Vote.objects.create(poll=self.poll, user=user) self.assert_equals( views.POLL_USER_ALLREADY_VOTED, views.poll_check_vote(build_request(user=user), self.poll))
def test_check_vote_annonymous_user_allready_voted_by_vote_object(self): Vote.objects.create(poll=self.poll, ip_address='127.0.0.1') self.assert_equals( views.POLL_USER_ALLREADY_VOTED, views.poll_check_vote(build_request(ip_address='127.0.0.1'), self.poll))
def test_check_vote_authetnticated_user_not_yet_voted(self): user = User.objects.create(username='******') self.assert_equals( views.POLL_USER_NOT_YET_VOTED, views.poll_check_vote(build_request(user=user), self.poll))
def test_check_vote_annonymous_user_not_yet_voted(self): self.assert_equals( views.POLL_USER_NOT_YET_VOTED, views.poll_check_vote(build_request(ip_address='127.0.0.1'), self.poll))
def test_check_vote_authetnticated_user_allready_voted_by_session(self): user = User.objects.create(username='******') session = {conf.POLL_COOKIE_NAME: [self.poll.pk]} self.assert_equals( conf.USER_ALLREADY_VOTED, views.poll_check_vote(build_request(user=user, session=session), self.poll))
def test_check_vote_annonymous_user_allready_voted_by_cookies(self): cookies = {conf.POLL_COOKIE_NAME: ','.join(str(self.poll.pk))} self.assert_equals( conf.USER_ALLREADY_VOTED, views.poll_check_vote(build_request(cookies=cookies), self.poll))
def test_check_vote_authetnticated_user_allready_voted_by_vote_object(self): user = User.objects.create(username='******') Vote.objects.create(poll=self.poll, user=user) self.assert_equals( conf.USER_ALLREADY_VOTED, views.poll_check_vote(build_request(user=user), self.poll))
def test_check_vote_annonymous_user_allready_voted_by_vote_object(self): Vote.objects.create(poll=self.poll, ip_address='127.0.0.1') self.assert_equals( conf.USER_ALLREADY_VOTED, views.poll_check_vote(build_request(ip_address='127.0.0.1'), self.poll))
def test_check_vote_authetnticated_user_not_yet_voted(self): user = User.objects.create(username='******') self.assert_equals( conf.USER_NOT_YET_VOTED, views.poll_check_vote(build_request(user=user), self.poll))
def test_check_vote_annonymous_user_not_yet_voted(self): self.assert_equals( conf.USER_NOT_YET_VOTED, views.poll_check_vote(build_request(ip_address='127.0.0.1'), self.poll))