mardi 23 juin 2020

AssertionError: False is not true when testing ModelForm in Django

I am trying to test order form and I got the error False is not true when testing a ModelForm. The output is pretty hard to debug and find the answer, Since the pattern I've used is same for all of the other forms I already tested but with Ok outcome.

Here is the code:

test_form.py

from django.test import TestCase
from checkout.forms import MakePaymentForm, OrderForm
from django import forms

def test_order_form_form(self):
        #test if the form is valid
        form = OrderForm(data={
            'full_name':'john test testing',
            'phone_number': '12345678',
            'country':'Brazil',
            'postcode': '98u887y776',
            'town_or_cit':'Guarulhos',
            'street_address1':'Av Jetulio Vargas',
            'street_address2':'Mooca',
            'county':'Praca da republica'
        })
        print(form.errors)
        self.assertTrue(form.is_valid())

forms.py

from django import forms
from .models import Order

lass OrderForm(forms.ModelForm):

    class Meta:
        model = Order
        fields = (
            'full_name', 'phone_number', 'country', 'postcode',
            'town_or_city', 'street_address1', 'street_address2',
            'county'
        )

models.py

class Order(models.Model):
    full_name = models.CharField(max_length=50, blank=False)
    phone_number = models.CharField(max_length=20, blank=False)
    country = models.CharField(max_length=40, blank=False)
    postcode = models.CharField(max_length=20, blank=True)
    town_or_city = models.CharField(max_length=40, blank=False)
    street_address1 = models.CharField(max_length=40, blank=False)
    #street_address2 not required so customers can leave it blank
    street_address2 = models.CharField(max_length=40, blank=True)
    county = models.CharField(max_length=40, blank=False)
    date = models.DateField()

    def __str__(self):
        """The {0}-{1}-{2} is the order in which the id(0), date(1) and full_name(2) will be displayed """
        return "{0}-{1}-{2}".format(self.id, self.date, self.full_name)

Aucun commentaire:

Enregistrer un commentaire