So I have a School model that has a required attribute student (from model Student). Somewhere in my serializer I do the following:
@staticmethod
def get_student_name(school):
if school.student:
return school.student.name
return "no name"
Now, a student can of course not be none or empty, ideally. But I do want to have the test if it's none to avoid errors (if there are mistakes in the database or..)
So I want to write a test to go over these checks (to have a full 100% coverage). But when I try to create a School model in my test class, I, ofcourse, get a Null constraint error
Is there a way to test this so I return "no name" for a student name if he doesn't have one instead of an error?
Aucun commentaire:
Enregistrer un commentaire