I have a model with various fields. One of them is a CharField
field = models.CharField(max_length=100, blank=False, null=False)
Now when I create an object without this field in django tests class function 'setUpTestData', it doesnt give any error. If I add minLengthValidator to it then too it doesn't give any
models.CharField(blank=False, null=False, max_length=100, validators=[MinLengthValidator(1)])
When I print it after the object is created it gives an empty string.
I have another field:
field2 = models.DateTimeField(blank=False, null=False)
Now if I dont provide this data while creating the object, the test fails correctly.
class Bag(models.Model):
created_on = models.DateTimeField(default=timezone.now)
order_id = models.CharField(blank=False, null=False, max_length=100)
order_created_time = models.DateTimeField(blank=False, null=False)
class SalesBagTestCase(TestCase):
@classmethod
def setUpTestData(cls):
Bag.objects.create(order_created_time=datetime.now())
def test_bag(self):
bag_response = self.client.get('http://localhost:8000/bag/')
self.assertEqual(bag_response.status_code, 200)
AssertEqual is True even if I remove the order_id field in the setUpData method