dimanche 8 juillet 2018

test_forms with django give AssertionError

I am trying to write test for my forms with my Django project. I try to test following BookForm: forms.py

class BookForm(ModelForm):
class Meta:
    model = Book
    fields = ['title', 'author', 'summary', 'tag', 'genre', 'language', 'book_format', 'read_date']
    #labels = 
    widgets = {
        'author': AddAnotherWidgetWrapper(
            forms.Select,
            reverse_lazy('author_form'),),
        'tag': AddAnotherWidgetWrapper(
            forms.SelectMultiple,
            reverse_lazy('author_form'),),            

    }       
    permission_required = 'libraryapp.can_edit'

def __init__(self, *args, **kwargs):
    self.request = kwargs.pop('request', None)
    # print(self.request.user)
    super(BookForm, self).__init__(*args, **kwargs)

My test_forms.py looks like that:

class BookFormTest(TestCase):

def test_read_date_in_the_past(self):
    print('BookForm TEST Lounched')
    title = 'TestBookPast'
    author = 'TestAuthorPast'
    date = datetime.date.today() + datetime.timedelta(days=2)
    form_data = {'title': title, 'author': author, 'read_date': date}
    form = BookForm(data=form_data)        
    self.assertTrue(form.is_valid())

I have no idea why it is not working. Maybe I forgot about something really important? I always get AssertionError:

    self.assertTrue(form.is_valid())
AssertionError: False is not true

Aucun commentaire:

Enregistrer un commentaire