In my polls/tests.py file I am getting a warning saying create_question not defined. This baffles me because just a few lines above this error message I have created the function create_question(). Please help. From what I have learned from @KenWhitesell the problem could be a stray comma in my code. So where could the problem be??? In Visual Studio Coce the amber/yellow squiggly error/warning is on line 59. The warning says create_question not defined. Here is my code
import datetime
from django.test import TestCase
from django.utils import timezone
from django.urls import reverse
from .models import Question
# Create your tests here.
class QuestionModelTests(TestCase):
def test_was_published_recently_with_future_question(self):
### was)published_recently() returns False for questions whose pub_dte is in the future ###
time = timezone.now() + datetime.timedelta(days=30)
future_question = Question(pub_dte=time)
self.assertIs(future_question.was_published_recently(), False)
def test_was_published_recently_with_old_question(self):
### was_published_recently() returns False
# for questions whose pub_dte is older thsn 1 day ###
time = timezone.now() - datetime.timedelta(days=1,seconds=1)
old_question = Question(pub_dte=time)
self.assertIs(old_question.was_published_recently(), False)
def test_was_published_recently_with_recent_question(self):
### was_published_recently() returns True
# for questions whose pub_dte is within the last day ###
time = timezone.now() - datetime.timedelta(hours=23, minutes=59, seconds=59)
recent_question = Question(pub_dte=time)
self.assertIs(recent_question.was_published_recently(), True)
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 or questions
published in the past, positive for questions
that have yet to be published),"""
time = timezone.now() + datetime.timedelta(days=days)
return Question.objects.create(question_text=question_text, pub_dte=time)
class QuestionIndexViewTests(TestCase):
def test_no_question(self):
""" If no questions exist, an appropriate message is displayed. """
response = self.client.get(reverse("polls:index.html"))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "No polls are available.")
self.assertQuerySetEqual(response.context["latest_question_list"], [])
def test_past_question(self):
""" Questions with a pub_dte in the past are displayed
on the index page."""
question = create_question(question_text="Past question.", days=-30)
response = self.client.get(reverse("polls:index"))
self.assertQuerySetEqual(response.context["latest_question_list"], [question],)@