コード例 #1
0
ファイル: tests.py プロジェクト: pham123/teracy-tutorial
 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)
コード例 #2
0
ファイル: tests.py プロジェクト: pham123/teracy-tutorial
 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)
コード例 #3
0
ファイル: tests.py プロジェクト: pham123/teracy-tutorial
 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)
コード例 #4
0
ファイル: tests.py プロジェクト: cuzen1/teracy-tutorial
    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))
コード例 #5
0
ファイル: tests.py プロジェクト: cuzen1/teracy-tutorial
        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)
コード例 #6
0
ファイル: tests.py プロジェクト: cuzen1/teracy-tutorial
        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)
コード例 #7
0
 def test_create_draft_poll(self):
     data = dict(
         title='Where do you live?',
         description='Now, we collecting location information about a visitors our site. And so, where you is?',
         status=Poll.CHOICES_STATUS.draft,
     )
     poll = Poll(**data)
     poll.full_clean()
     poll.save()
     self.assertEqual(poll.title, data['title'])
     self.assertEqual(poll.status, data['status'])
     self.assertEqual(poll.description, data['description'])
コード例 #8
0
 def test_create_closed_poll(self):
     data = dict(
         title='I you liked our website?',
         description='Us very interesting you opinion about quality our site?',
         status=Poll.CHOICES_STATUS.closed,
     )
     poll = Poll(**data)
     poll.full_clean()
     poll.save()
     self.assertEqual(poll.title, data['title'])
     self.assertEqual(poll.status, data['status'])
     self.assertEqual(poll.description, data['description'])
コード例 #9
0
 def test_create_opened_poll(self):
     data = dict(
         title='Who is who?',
         description='Us very interesting - who are you?',
         status=Poll.CHOICES_STATUS.opened,
     )
     poll = Poll(**data)
     poll.full_clean()
     poll.save()
     self.assertEqual(poll.title, data['title'])
     self.assertEqual(poll.status, data['status'])
     self.assertEqual(poll.description, data['description'])
コード例 #10
0
 def test_update_poll(self):
     data = dict(
         title='What do you think about new design of the website?',
         description='As you see, after little delay, we given you new version of our website.',
         status=Poll.CHOICES_STATUS.opened,
     )
     poll = Poll(**data)
     poll.full_clean()
     poll.save()
     self.assertEqual(poll.title, data['title'])
     self.assertEqual(poll.status, data['status'])
     self.assertEqual(poll.description, data['description'])
コード例 #11
0
def create_polls(polls):
    polls = [(p.pop('choices', []), p) for p in polls]
    Poll.objects.bulk_create([Poll(**kw) for _, kw in polls])
    return {
        poll['id']: {
            **poll, 'choices': create_choices(choices, poll['id'])
        }
        for choices, poll in polls
    }
コード例 #12
0
ファイル: tests.py プロジェクト: cuzen1/teracy-tutorial
    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))