I'm new to Django and I'm nor sure what I'm doing wrong. I'm trying to run tests for my form "UserProfileForm" and the test fails all time and I don't know why. Can anyone help?
this is my forms.py
from .models import UserProfile
from dobwidget import DateOfBirthWidget
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = [
'profile_img',
'subscribe',
'bio',
'dob',
'telephone',
'contact_by_phone',
'contact_by_email'
]
widgets = {
'dob': DateOfBirthWidget(),
}
this is my models.py
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_img = models.ImageField(upload_to='images', default="images/default_profile.png")
subscribe = models.BooleanField(blank=True, default=False)
bio = models.TextField(blank=True)
dob = models.DateField(max_length=8, null=True, blank=True)
telephone = models.CharField(max_length=20, null=True, blank=True)
contact_by_phone = models.BooleanField(blank=True, default=False)
contact_by_email = models.BooleanField(blank=True, default=False)
def __str__(self):
return self.user.username
And this is the test that I'm trying to run
from django.test import TestCase
from .forms import UserProfileForm
class TestUserProfileForm(TestCase):
def test_can_create_a_profile(self):
valid_data = {
'profile_img':"images/perfil.jpg",
'subscribe':False,
'bio':'asdjklsad asdkj;s',
'dob':'2019-03-03',
'telephone' : '12324',
'contact_by_phone' : True,
'contact_by_email' : True,
}
form = UserProfileForm(data=valid_data)
self.assertTrue(form.is_valid())