I am testing the creation of an object and would like to know how to do the test to make an assert in case the object could not be created. For example:
def test_expediente_sin_nombre(self):
try:
Expediente.objects.create(
apellido_paterno='Prueba 2',
apellido_materno='Prueba 1',
estado_nacimiento='Oaxaca',
fecha_nacimiento='2000-01-01'
)
self.fail("No se pudo crear")
except FooException:
pass
expediente_counts = Expediente.objects.filter(apellido_paterno='Prueba 2').count()
self.assertRaises(FooException)
In this case the file should not be created because the file is missing, if it is not created then the test passed.