コード例 #1
0
 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)
コード例 #2
0
ファイル: tests.py プロジェクト: vectorate/ds
    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)
コード例 #3
0
 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)
コード例 #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)
コード例 #5
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 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)
コード例 #6
0
    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)
コード例 #7
0
ファイル: views.py プロジェクト: mramu111/mysite
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)
コード例 #8
0
ファイル: views.py プロジェクト: randytarampi/awesomeTechEval
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,)))
コード例 #9
0
ファイル: tests.py プロジェクト: marciojss/tutodjango
 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)
コード例 #10
0
ファイル: tests.py プロジェクト: marciojss/tutodjango
  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)
コード例 #11
0
ファイル: tests.py プロジェクト: dlutxx/mob
 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)
コード例 #12
0
ファイル: tests.py プロジェクト: marciojss/tutodjango
 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)
コード例 #13
0
ファイル: tests.py プロジェクト: dyon/TDDjango
    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)
コード例 #14
0
    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)
コード例 #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)
コード例 #16
0
ファイル: tests.py プロジェクト: abhijeetmote/poll_django
 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)
コード例 #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)
コード例 #18
0
ファイル: seeder.py プロジェクト: zippyy/PollMe---Django-2.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()
コード例 #19
0
ファイル: tests.py プロジェクト: MattySheikh/polls
	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)
コード例 #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))
コード例 #21
0
ファイル: tests.py プロジェクト: gnufede/djanto
 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)
コード例 #22
0
ファイル: tests.py プロジェクト: cliffkimani/django_polls
 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)
コード例 #23
0
    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)
コード例 #24
0
ファイル: tests.py プロジェクト: surf3s/paleocore
 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)
コード例 #25
0
ファイル: tests.py プロジェクト: vectorate/ds
    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)
コード例 #26
0
ファイル: tests.py プロジェクト: jacol12345/ISWD_sem9
 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)
コード例 #27
0
ファイル: tests.py プロジェクト: linshu123/local_django
 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)
コード例 #28
0
ファイル: tests.py プロジェクト: celic/mysite
	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)
コード例 #29
0
ファイル: tests.py プロジェクト: celic/mysite
	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)
コード例 #30
0
ファイル: tests.py プロジェクト: sourabhv/Django-PollApp
	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)
コード例 #31
0
ファイル: tests.py プロジェクト: aschokking/django-tutorial
	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)
コード例 #32
0
ファイル: tests.py プロジェクト: sourabhv/Django-PollApp
	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)
コード例 #33
0
ファイル: tests.py プロジェクト: sourabhv/Django-PollApp
	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)
コード例 #34
0
ファイル: tests.py プロジェクト: abhijeetmote/poll_django
 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)
コード例 #35
0
    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)
コード例 #36
0
ファイル: tests.py プロジェクト: lucascgomes/SR
	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)
コード例 #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)
コード例 #38
0
ファイル: tests.py プロジェクト: lucascgomes/SR
	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)
コード例 #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()
コード例 #40
0
ファイル: tests.py プロジェクト: sjl421/django-ccsds
    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)
コード例 #41
0
ファイル: test_views.py プロジェクト: IINamelessII/YesOrNo
 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))
コード例 #42
0
ファイル: tests.py プロジェクト: sourabhv/Django-PollApp
    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)
コード例 #43
0
ファイル: tests.py プロジェクト: bepec/django-tutorial
 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())
コード例 #44
0
ファイル: tests.py プロジェクト: sourabhv/Django-PollApp
    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)
コード例 #45
0
 def test_create(self):
     poll = Poll(
         views=10,
         stars=10,
         name='some',
     )
     poll.save()
     assert Poll.objects.get(pk=poll.pk)
コード例 #46
0
ファイル: tests.py プロジェクト: bepec/django-tutorial
 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())
コード例 #47
0
ファイル: tests.py プロジェクト: fanandactuaility/mysite
 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)
コード例 #48
0
ファイル: tests.py プロジェクト: fanandactuaility/mysite
 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)
コード例 #49
0
ファイル: tests.py プロジェクト: saisai/django-project
 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
コード例 #50
0
ファイル: tests.py プロジェクト: fanandactuaility/mysite
 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)
コード例 #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)
コード例 #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)
コード例 #53
0
ファイル: tests.py プロジェクト: py-yyc/oauth_meetup
    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)
コード例 #54
0
ファイル: schema.py プロジェクト: Laymalay/PollPool
 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)
コード例 #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)