def test_was_published_today_with_old_poll(self):
   """
   was_published_today should return False for poll whose
   pub_date is older than today.
   """
   old_poll=Poll(pub_date=timezone.now()-datetime.timedelta(days=1))
   self.assertEqual(old_poll.was_published_today(), False)
Exemple #2
0
    def test_was_published_recently_with_future_poll(self):
        """
        was_published_recently() should return False for polls whose
        pub_date is in the future
        """
        future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30))
        #for i in dir(future_poll):
        #	print(i)
        self.assertEqual(future_poll.was_published_recently(), False)

	def test_was_published_recently_with_old_poll(self):
	    """
	    was_published_recently() should return False for polls whose pub_date
	    is older than 1 day
	    """
	    old_poll = Poll(pub_date=timezone.now() - datetime.timedelta(days=30))
	    self.assertEqual(old_poll.was_published_recently(), False)

	def test_was_published_recently_with_recent_poll(self):
	    """
	    was_published_recently() should return True for polls whose pub_date
	    is within the last day
	    """
	    recent_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
	    self.assertEqual(recent_poll.was_published_recently(), True)
 def test_was_published_today_with_recent_poll(self):
   """
   was_published_today should return True for poll whose
   pub_date are today.
   """
   recent_poll=Poll(pub_date=timezone.now()-datetime.timedelta(hours=1))
   self.assertEqual(recent_poll.was_published_today(), True)
Exemple #4
0
 def test_was_published_recently_with_old_poll(self):
     """
     was_published_recently() should return False for polls whose pub_date
     is older than 1 day
     """
     old_poll = Poll(pub_date=timezone.now() - datetime.timedelta(days=30))
     self.assertEqual(old_poll.was_published_recently(), False)
    def test_creating_some_choices_for_a_poll(self):
        # start by creating a new Poll object
        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()
        poll.save()

        # now create a Choice object
        choice = Choice()

        # link it with our Poll
        choice.poll = poll

        # give it some text
        choice.choice = "doin' fine..."

        # and let's say it's had some votes
        choice.votes = 3

        # save it
        choice.save()

        # try retrieving it from the database, using the poll object's reverse
        # lookup
        poll_choices = poll.choice_set.all()
        self.assertEquals(poll_choices.count(), 1)

        # finally, check its attributes have been saved
        choice_from_db = poll_choices[0]
        self.assertEquals(choice_from_db, choice)
        self.assertEquals(choice_from_db.choice, "doin' fine...")
        self.assertEquals(choice_from_db.votes, 3)
    def test_was_published_recently_with_old_poll(self):
        old_poll = Poll(pub_date=timezone.now() - datetime.timedelta(days=30))
        self.assertEqual(old_poll.was_published_recently(), False)

	def test_was_published_recently_with_recent_poll(self):
		recent_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
		self.assertEqual(recent_poll.was_published_recently(), True)
Exemple #7
0
def createquestion(request):    
    p=Poll()
    p.question=request.GET['question']
    #p.pub_date=request.getparameter('pub_date')
    p.pub_date=timezone.now()
    p.save()
    return index(request)
def create(request):
    """
    The logic behind the poll creation form.

    Like the voting form, if you pass it some invalid inputs, it screams at you.
    Otherwise, it leads you the poll's detail view.
    """
    
    import datetime
    
    if len(request.POST['question']) == 0 and len(request.POST['choice']) == 0:
	return render_to_response('pollsIndex.html', {
                      	'error_message': "You need to type a choice and question in.", 'latest_poll_list' : Poll.objects.all().order_by('-pub_date')[:5],
                    	}, context_instance=RequestContext(request))
    elif len(request.POST['choice']) == 0:
	return render_to_response('pollsIndex.html', {
                      	'error_message': "You need to type a choice in.", 'latest_poll_list' : Poll.objects.all().order_by('-pub_date')[:5],
                    	}, context_instance=RequestContext(request))
    elif len(request.POST['question']) == 0:
	return render_to_response('pollsIndex.html', {
                      	'error_message': "You need to type a question in.", 'latest_poll_list' : Poll.objects.all().order_by('-pub_date')[:5],
                    	}, context_instance=RequestContext(request))
    else:
    	p = Poll(question=request.POST['question'], pub_date=datetime.datetime.now())
    	p.save()
    	p.choice_set.create(choice=request.POST['choice'], votes=0)
    	return HttpResponseRedirect(reverse('poll_detail', args=(p.id,)))
Exemple #9
0
 def test_was_published_recently_with_old_poll(self):
 	"""
 	was_published_recently() deve returnar False para polls onde pub_date
 	eh maior que 1 dia
 	"""
 	old_poll = Poll(pub_date=timezone.now() - datetime.timedelta(days=30))
 	self.assertEqual(old_poll.was_published_recently(), False)
Exemple #10
0
  def test_was_published_recently_with_recent_poll(self):
  	"""
  	was_published_recently() deve retornar True para polls onde pub_date
  	 eh do mesmo dia
 		"""
  	recent_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
  	self.assertEqual(recent_poll.was_published_recently(), True)
Exemple #11
0
 def test_was_published_recently_with_future_poll(self):
     """
     was_published_recently() should return False for polls whose
     pub_date is in the future
     """
     future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30))
     self.assertEqual(future_poll.is_recent(), False)
Exemple #12
0
 def test_was_published_recently_with_future_poll(self):
     """
     was_published_recently() retorna False para pesquisas onde
     pub_date esta no futuro
     """
     future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30))
     self.assertEqual(future_poll.was_published_recently(), False)
Exemple #13
0
    def test_creating_some_choices_for_a_poll(self):
        # Start by creating a new Poll object
        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()
        poll.save()

        # Now we create a Choice object
        choice = Choice()

        # Link it to our poll
        choice.poll = poll
        choice.choice = 'Doing fine...'
        choice.votes = 3
        choice.save()

        # Try retrieving from the database using the poll object's reverse lookup
        poll_choices = poll.choice_set.all()
        self.assertEquals(poll_choices.count(), 1)

        # Finally, check that its attributes have been saved
        choice_from_db = poll_choices[0]
        self.assertEquals(choice_from_db, choice)
        self.assertEquals(choice_from_db.choice, 'Doing fine...')
        self.assertEquals(choice_from_db.votes, 3)
    def test_create_some_choices_for_a_poll(self):
        # Create new poll object
        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()
        poll.save()

        # Create Choice object
        choice = Choice()
        choice.poll = poll
        choice.choice = "doin' fine..."

        # Give it faux votes
        choice.votes = 3
        choice.save()

        # Try to retrieve from DB using poll's reverse lookup.
        poll_choices = poll.choice_set.all()
        self.assertEquals(poll_choices.count(), 1)

        # Finally, check attrbs have been saved
        choice_from_db = poll_choices[0]
        self.assertEqual(choice_from_db, choice)
        self.assertEqual(choice_from_db.choice, "doin' fine...")
        self.assertEqual(choice_from_db.votes, 3)
Exemple #15
0
 def test_was_published_recently_with_recent_poll(self):
     '''
     was_published_recently should return true with recent poll
     '''
     recent_poll = Poll(pub_date=timezone.now() -
                        datetime.timedelta(hours=1))
     self.assertEqual(recent_poll.was_published_recently(), True)
Exemple #16
0
 def test_was_published_recently_with_recent_poll(self):
     """
     was_published_recently() should return True for polls whose pub_date
     is within the last day
     """
     recent_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
     self.assertEqual(recent_poll.was_published_recently(), True)
Exemple #17
0
 def test_was_published_recently_with_future_poll(self):
     '''
     was_published_recently should return false with future poll
     '''
     future_poll = Poll(pub_date=timezone.now() +
                        datetime.timedelta(days=10))
     self.assertEqual(future_poll.was_published_recently(), False)
Exemple #18
0
def seed_polls(num_entries=10, choice_min=2, choice_max=5, overwrite=False):
    """
    Seeds num_entries poll with random users as owners
    Each poll will be seeded with # choices from choice_min to choice_max
    """
    if overwrite:
        print('Overwriting polls')
        Poll.objects.all().delete()
    users = list(User.objects.all())
    count = 0
    for _ in range(num_entries):
        p = Poll(
            owner = random.choice(users),
            text = fake.paragraph(),
            pub_date = datetime.datetime.now()
        )
        p.save()
        for _ in range(choice_min, choice_max + 1):
            c = Choice(
                poll = p,
                choice_text = fake.sentence()
            ).save()
        count += 1
        percent_complete = count / num_entries * 100
        print(
                "Adding {} new Polls: {:.2f}%".format(num_entries, percent_complete),
                end='\r',
                flush=True
                )
    print()
Exemple #19
0
	def testWasPublishedRecentlyWithNewPoll(self):
		"""
		wasPublishedRecently() should return False for polls created
		within the last hour
		"""
		newPoll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
		self.assertEqual(newPoll.wasPublishedRecently(), True)
Exemple #20
0
    def test_was_published_recently_with_future_poll(self):
        """
        was_published_recently() should return False for polls whose
        pub_date is in the future
        """
        future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30))
        self.assertEqual(future_poll.was_published_recently(), False)
        
        def test_was_published_recently_with_old_poll(self):
            """
            was_published_recently() should return False for polls whose pub_date
            is older than 1 day
            """
            old_poll = Poll(pub_date=timezone.now() - datetime.timedelta(days=30))
            self.assertEqual(old_poll.was_published_recently(), False)

        def test_was_published_recently_with_recent_poll(self):
            """
            was_published_recently() should return True for polls whose pub_date
            is within the last day
            """
            recent_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
            self.assertEqual(recent_poll.was_published_recently(), True)
            
        def create_poll(question, days):
            """
            Creates a poll with the given `question` published the given number of
            `days` offset to now (negative for polls published in the past,
            positive for polls that have yet to be published).
            """
            return Poll.objects.create(question=question,
                pub_date=timezone.now() + datetime.timedelta(days=days))
Exemple #21
0
 def test_was_published_recently_with_past_poll(self):
     """
     was_published_recently() should return False for polls whose
     pub_date is prior to yesterday
     """
     past_poll = Poll(pub_date=timezone.now() - datetime.timedelta(days=2))
     self.assertEqual(past_poll.was_published_recently(), False)
Exemple #22
0
 def test_was_published_recently_with_new_poll(self):
     """
     was_published_recently() should return True for polls whose
     pub_date is less than one day old
     """
     new_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
     self.assertEqual(new_poll.was_published_recently(), True)
    def test_view_can_handle_votes_via_POST(self):
        # set up a poll with choices
        poll1 = Poll(question='6 times 7', pub_date=timezone.now())
        poll1.save()
        choice1 = Choice(poll=poll1, choice='42', votes=1)
        choice1.save()
        choice2 = Choice(poll=poll1, choice='The Ultimate Answer', votes=3)
        choice2.save()

        # set up our POST data - keys and values are strings
        post_data = {'vote': str(choice2.id)}

        # make our request to the view
        poll_url = '/poll/%d/' % (poll1.id, )
        response = self.client.post(poll_url, data=post_data)

        # retrieve the updated choice from the database
        choice_in_db = Choice.objects.get(pk=choice2.id)

        # check it's votes have gone up by 1
        self.assertEquals(choice_in_db.votes, 4)

        # always redirect after a POST - even if, in this case, we go back
        # to the same page.
        self.assertRedirects(response, poll_url)
Exemple #24
0
 def test_was_published_recently_with_new_poll(self):
     """
     was_published_recently() should return True for polls whose
     pub_date is less than one day old
     """
     new_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
     self.assertEqual(new_poll.was_published_recently(), True)
Exemple #25
0
    def test_was_published_recently_with_future_poll(self):
        """
        was_published_recently() should return False for polls whose
        pub_date is in the future
        """
        future_poll = Poll(pub_date=timezone.now() +
                           datetime.timedelta(days=30))
        #for i in dir(future_poll):
        #	print(i)
        self.assertEqual(future_poll.was_published_recently(), False)

        def test_was_published_recently_with_old_poll(self):
            """
	    was_published_recently() should return False for polls whose pub_date
	    is older than 1 day
	    """
            old_poll = Poll(pub_date=timezone.now() -
                            datetime.timedelta(days=30))
            self.assertEqual(old_poll.was_published_recently(), False)

        def test_was_published_recently_with_recent_poll(self):
            """
	    was_published_recently() should return True for polls whose pub_date
	    is within the last day
	    """
            recent_poll = Poll(pub_date=timezone.now() -
                               datetime.timedelta(hours=1))
            self.assertEqual(recent_poll.was_published_recently(), True)
Exemple #26
0
 def test_was_published_recently_with_recent_poll(self):
     """
     was_published_recently() should return True for polls whose
     pub_date is not more than 1 day earlier
     """
     recent_poll = Poll(pub_date=timezone.now()-timezone.timedelta(hours=5))
     self.assertEqual(recent_poll.was_published_recently(), True)
Exemple #27
0
 def test_was_published_recently_with_current_poll(self):
     """
     test_was_published_recently_with_current_poll should return False for polls whose
     pub_date is in the current time
     """
     future_poll = Poll(pub_date=timezone.now())
     self.assertEqual(future_poll.was_published_recently(), True)
Exemple #28
0
	def test_was_published_recently_with_old_poll(self):
		"""
		Tests was_published_recently() with an old date
		to ensure it returns false
		"""
		old_poll = Poll(pub_date = timezone.now() - datetime.timedelta(days = 30))
		self.assertEqual(old_poll.was_published_recently(), False)
Exemple #29
0
	def test_was_published_recently_with_recent_poll(self):
		"""
		Tests was_published_recently() with a recent date
		to ensure it returns true
		"""
		recent_poll = Poll(pub_date = timezone.now() - datetime.timedelta(hours = 1))
		self.assertEqual(recent_poll.was_published_recently(), True)
Exemple #30
0
	def test_wasPublishedRecently_with_future_poll(self):
		'''
		wasPublishedRecently() should return False for polls whose
		pub_date is in the future
		'''
		future_poll = Poll(pubdate=timezone.now() + datetime.timedelta(days=30))
		self.assertEqual(future_poll.wasPublishedRecently(), False)
Exemple #31
0
	def test_was_published_recently_with_future_poll(self):
		"""
		was_published_recently should return false for polls with future
		published dates
		"""
		future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30))
		self.assertEqual(future_poll.was_published_recently(), False)
Exemple #32
0
	def test_wasPublishedRecently_with_recent_poll(self):
		'''
		wasPublishedRecently() should return True for polls which
		are recent published
		'''
		future_poll = Poll(pubdate=timezone.now() - datetime.timedelta(hours=3))
		self.assertEqual(future_poll.wasPublishedRecently(), True)
Exemple #33
0
	def test_wasPublishedRecently_with_old_poll(self):
		'''
		wasPublishedRecently() should return False for polls which
		are old
		'''
		future_poll = Poll(pubdate=timezone.now() - datetime.timedelta(hours=30))
		self.assertEqual(future_poll.wasPublishedRecently(), False)
Exemple #34
0
 def test_was_published_recently_with_old_poll(self):
     """
     was_published_recently() should return False for polls whose pub_date
     is older than 1 day
     """
     old_poll = Poll(pub_date=timezone.now() - datetime.timedelta(days=30))
     self.assertEqual(old_poll.was_published_recently(), False)
    def test_view_can_handle_votes_via_POST(self):
        # set up a poll with choices
        poll1 = Poll(question='6 times 7', pub_date=timezone.now())
        poll1.save()
        choice1 = Choice(poll=poll1, choice='42', votes=1)
        choice1.save()
        choice2 = Choice(poll=poll1, choice='The Ultimate Answer', votes=3)
        choice2.save()

        # set up our POST data - keys and values are strings
        post_data = {'vote': str(choice2.id)}

        # make our request to the view
        poll_url = '/poll/%d/' % (poll1.id,)
        response = self.client.post(poll_url, data=post_data)

        # retrieve the updated choice from the database
        choice_in_db = Choice.objects.get(pk=choice2.id)

        # check it's votes have gone up by 1
        self.assertEquals(choice_in_db.votes, 4)

        # always redirect after a POST - even if, in this case, we go back
        # to the same page.
        self.assertRedirects(response, poll_url)
Exemple #36
0
	def test_was_published_recently_with_future_poll(self):
		"""
		was_published_recently() should return False for polls whose
		pub_date is in the future
		"""
		future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30))
		self.assertEqual(future_poll.was_published_recently(), False)
Exemple #37
0
    def test_was_published_recently_with_recent_poll(self):
        """
        return True for polls 1 day
        """

        recent_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=4))
        self.assertEqual(recent_poll.was_published_recently(), True)
Exemple #38
0
	def test_was_published_recently_with_recent_poll(self):
		"""
		was_published_recently() should return True for polls whose pub_date
		is within the last day
		"""
		recent_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
		self.assertEqual(recent_poll.was_published_recently(), True)
Exemple #39
0
def seed_polls(num_entries=10, choice_min=2, choice_max=5, overwrite=False):
    """
    Seeds num_entries poll with random users as owners
    Each poll will be seeded with # choices from choice_min to choice_max
    """
    if overwrite:
        print('Overwriting polls')
        Poll.objects.all().delete()
    users = list(User.objects.all())
    count = 0
    for _ in range(num_entries):
        p = Poll(owner=random.choice(users),
                 text=fake.paragraph(),
                 pub_date=datetime.datetime.now())
        p.save()
        num_choices = random.randrange(choice_min, choice_max + 1)
        for _ in range(num_choices):
            c = Choice(poll=p, choice_text=fake.sentence()).save()
        count += 1
        percent_complete = count / num_entries * 100
        print("Adding {} new Polls: {:.2f}%".format(num_entries,
                                                    percent_complete),
              end='\r',
              flush=True)
    print()
Exemple #40
0
    def test_was_published_recently_with_recent_question(self):
        """
		was_published_recently() should return True for Poll whose pub_date is within the last day.
		"""
        time = timezone.now() - datetime.timedelta(days=1)
        old_poll = Poll(pub_date=time)
        self.assertEqual(old_poll.was_published_recently(), True)
Exemple #41
0
 def test_get_queryset(self):
     poll = Poll(owner=self.user_model,
                 statement='Just a test?',
                 flow=self.flow_model)
     poll.save()
     view = self.view(request=self.request)
     polls = Poll.objects.filter(owner=self.user_model)
     self.assertQuerysetEqual(view.get_queryset(), map(repr, polls))
Exemple #42
0
    def test_wasPublishedRecently_with_recent_poll(self):
        '''
		wasPublishedRecently() should return True for polls which
		are recent published
		'''
        future_poll = Poll(pubdate=timezone.now() -
                           datetime.timedelta(hours=3))
        self.assertEqual(future_poll.wasPublishedRecently(), True)
Exemple #43
0
 def test_was_published_recently_with_future_pub_date(self):
     """
     was_published_recently should return False
     if pub_date is in future
     """
     future = timezone.now() + datetime.timedelta(days=30)
     future_poll = Poll(pub_date=future)
     self.assertFalse(future_poll.was_published_recently())
Exemple #44
0
    def test_wasPublishedRecently_with_old_poll(self):
        '''
		wasPublishedRecently() should return False for polls which
		are old
		'''
        future_poll = Poll(pubdate=timezone.now() -
                           datetime.timedelta(hours=30))
        self.assertEqual(future_poll.wasPublishedRecently(), False)
 def test_create(self):
     poll = Poll(
         views=10,
         stars=10,
         name='some',
     )
     poll.save()
     assert Poll.objects.get(pk=poll.pk)
Exemple #46
0
 def test_was_published_recently_with_old_pub_date(self):
     """
     was_published_recently should be False if the poll
     is older than 1 day
     """
     past = timezone.now() - datetime.timedelta(days=2)
     poll = Poll(pub_date=past)
     self.assertFalse(poll.was_published_recently())
Exemple #47
0
 def test_was_published_recently_with_old_question(self):
     """
     was_publised_recently() should retuen False question whose
     qub_date is older then 1 days
     :return:
     """
     time = timezone.now() - datetime.timedelta(days=30)
     old_question = Poll(qub_date=time)
     self.assertEqual(old_question.was_published_recently(), False)
Exemple #48
0
 def test_was_published_recently_with_future_question(self):
     """
     was_published_recently() should retuen False question whose
     qub_date is the future.
     :return:
     """
     time = timezone.now() + datetime.timedelta(days=30)
     future_question = Poll(qub_date=time)
     self.assertEqual(future_question.was_published_recently(), False)
Exemple #49
0
 def setUpClass(cls):
     u = User.objects.create_user('simeon', '*****@*****.**', 'password')
     p = Poll(user=u, question="Why?", pub_date=dt.now())
     p.save()
     Choice.objects.bulk_create([
         Choice(poll=p, choice="Because", votes=0),
         Choice(poll=p, choice="Because", votes=0)
     ])
     cls.p = p
Exemple #50
0
 def test_was_published_recently_with_recent_question(self):
     """
     was_publisehed_recently() should retuen Ture question whose
     qub_date is within the last day.
     :return:
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Poll(qub_date=time)
     self.assertEqual(recent_question.was_published_recently(), True)
Exemple #51
0
    def test_was_published_recently_with_future_poll(self):
        """
        Was published recently should return false
        for polls whose pub_date is in the future
        """

        # Created a Poll instance whose pub_date field in 30 day in the future.
        future_poll = Poll(pub_date=timezone.now() +
                           datetime.timedelta(days=30))
        self.assertEqual(future_poll.was_published_recently(), False)
Exemple #52
0
 def test_was_published_recently_with_future_poll(self):
     """
     was_published_recently() should return False for polls whose pub_date
     is in the future
     """
     # example of creating a poll with a date set 30 days into the future
     # test with python manage.py test polls
     future_poll = Poll(pub_date=timezone.now() +
                        datetime.timedelta(days=30))
     self.assertEqual(future_poll.was_published_recently(), False)
Exemple #53
0
    def setup_poll1(self):
        poll = Poll(question='Which is better?', pub_date=timezone.now())
        poll.save()

        email_choice = Choice(question=poll, choice_text='Email sign-up')
        email_choice.save()

        external_choice = Choice(question=poll, choice_text='External sign-in')
        external_choice.save()

        return (poll, email_choice, external_choice)
Exemple #54
0
 def mutate(self, info, title, description, image_path):
     poll = Poll(title=title,
                 creator=info.context.user,
                 description=description,
                 image_path=image_path)
     poll.save()
     return CreatePoll(creator=poll.creator,
                       id=poll.id,
                       description=poll.description,
                       image_path=poll.image_path,
                       title=poll.title)
Exemple #55
0
def create(request):
    """Creates a new poll instance."""
    poll = Poll(question=request.POST['question'],
                pub_date=datetime.datetime.now())
    poll.save()
    choice = Choice(poll=poll, choice=request.POST['choice1'], votes=0)
    choice.save()
    choice = Choice(poll=poll, choice=request.POST['choice2'], votes=0)
    choice.save()
    choice = Choice(poll=poll, choice=request.POST['choice3'], votes=0)
    choice.save()
    return HttpResponseRedirect('/polls/%s' % poll.id)