I tried to test forms.py
in Django which has LeadForm
class.
Here, is the models.py
class Lead(TimestampedModel):
"""leads for LIVE courses"""
course = models.ForeignKey(
LiveCourse, related_name="leads", on_delete=models.PROTECT
)
notes = models.TextField(blank=True, null=True)
Here, is the code I used to test.
@pytest.fixture
def valid_course(db):
return Course.objects.create(name='Design')
@pytest.fixture
def valid_lead_data(valid_course):
return {
'full_name': 'john',
'phone_number': '1234567890',
'email': '[email protected]',
'course': valid_course.id,
'g-recaptcha-response': 'PASSED',
}
The above code shows AssertionError
that the course is not in one of the available choices.
Thanks in advance.
LiveCourse
while your fixture is creating aCourse
object.