Module polls.tests

Functions

def create_question(question_text, days)

Create a question with the given 'question_text' and published the given number of 'days' offset to now (negative for questions published in the past, positive for questions that have yet to be published).

Classes

class QuestionDetailViewTests (methodName='runTest')

Similar to TransactionTestCase, but use transaction.atomic() to achieve test isolation.

In most situations, TestCase should be preferred to TransactionTestCase as it allows faster execution. However, there are some situations where using TransactionTestCase might be necessary (e.g. testing some transactional behavior).

On database backends with no transaction support, TestCase behaves as TransactionTestCase.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Ancestors

  • django.test.testcases.TestCase
  • django.test.testcases.TransactionTestCase
  • django.test.testcases.SimpleTestCase
  • unittest.case.TestCase

Methods

def test_future_question(self)

The detail view of question with a pub_date in the future returns a 404 not found.

def test_past_question(self)

The detail view of question with a pub_date in the past displays the question text.

class QuestionIndexViewTests (methodName='runTest')

Similar to TransactionTestCase, but use transaction.atomic() to achieve test isolation.

In most situations, TestCase should be preferred to TransactionTestCase as it allows faster execution. However, there are some situations where using TransactionTestCase might be necessary (e.g. testing some transactional behavior).

On database backends with no transaction support, TestCase behaves as TransactionTestCase.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Ancestors

  • django.test.testcases.TestCase
  • django.test.testcases.TransactionTestCase
  • django.test.testcases.SimpleTestCase
  • unittest.case.TestCase

Methods

def test_future_question(self)

Question with a pub_date in the future aren't displayed on the index page.

def test_future_question_and_past_question(self)

Even if both past and future questions exist, only past questions are displayed.

def test_no_questions(self)

If no question exist, an appropriate message is displayed.

def test_past_question(self)

Questions with the pub_date in the past are displayed on the index page.

def test_two_past_questions(self)

The question index page may display multiple questions.

class QuestionModelTests (methodName='runTest')

Similar to TransactionTestCase, but use transaction.atomic() to achieve test isolation.

In most situations, TestCase should be preferred to TransactionTestCase as it allows faster execution. However, there are some situations where using TransactionTestCase might be necessary (e.g. testing some transactional behavior).

On database backends with no transaction support, TestCase behaves as TransactionTestCase.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Ancestors

  • django.test.testcases.TestCase
  • django.test.testcases.TransactionTestCase
  • django.test.testcases.SimpleTestCase
  • unittest.case.TestCase

Methods

def test_was_published_recently_with_future_question(self)

was_published_recently() returns False for questions whose pub_date is in the future.

def test_was_published_recently_with_old_question(self)

was_published_recently() returns False for questions whose pub_date is older than 1 day.

def test_was_published_recently_with_recent_question(self)

was_published_recently() returns True for questions whose pub_date is within the last day.