diff --git a/docs/tests.md b/docs/tests.md new file mode 100644 index 0000000000..0e467ff58f --- /dev/null +++ b/docs/tests.md @@ -0,0 +1,14 @@ +# Tests + +## Backend Tests + +We use pytest in combination with pytest-django and factoryboy to write backend +tests. + +### Notes + +#### Testing Emails + +The django email backend does not guarantee a deterministic order of the mails, +so checking against an index will result in flaky tests. If you want to assert +that a mail was sent use one of the helper functions in `tests/helpers.py`. diff --git a/tests/helpers.py b/tests/helpers.py new file mode 100644 index 0000000000..77e0859329 --- /dev/null +++ b/tests/helpers.py @@ -0,0 +1,7 @@ +from django.core import mail + + +def get_emails_for_address(email_address): + """Return all mails send to email_address""" + index = list(filter(lambda mails: mails.to[0] == email_address, mail.outbox)) + return index