I'm new to testing in Django and I was wondering how to write tests for signals.
I went over the documentation but I couldn't find anything helpful.
Let's say a have a simple pre_save
signal for Reservation
model and I want to change some attribute before saving it to the database.
My code looks like this:
@receiver(pre_save, sender=Reservation)
def set_destination_type(sender, instance, *args, **kwargs):
points = ['New York', 'Rome', 'Paris']
if instance.destination in points:
instance.international = True
instance.international = False
How would I approach this? Do I just create a reservation and assert that correct value was set? Do I test this function in isolation? I really don't know how to start.
Thanks!
Aucun commentaire:
Enregistrer un commentaire