I am writing a unit test for a model method of ModelA which queries for the most recent related ModelB and validates it based on the current time. Ideally for this test I would just like to create one ModelA and a few ModelBs make some assertions and be done.
My issue is that both ModelA and ModelB have foreign keys that point to other models which in turn have foreign keys that point to even more models. Is there a way in the scope of my test to ignore the IntegrityError
that is thrown by not assigning these other foreign keys?
My models.py looks something like this
class ModelA(models.Model):
modelc = models.ForeignKey('ModelC')
...
def method1(self):
most_recent_modelb = ModelB.objects.filter(modela = self).latest('created')
#some other stuff
class ModelB(models.Model):
modela = models.ForeignKey('ModelA')
modelz = models.ForeignKey('ModelZ')
class ModelC(models.Model):
modeld = models.ForeignKey('ModelD')