Skip to content

Commit

Permalink
tests: add helper and some initial docs about testing
Browse files Browse the repository at this point in the history
  • Loading branch information
goapunk authored and m4ra committed Feb 5, 2024
1 parent f717005 commit 783af58
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog/_4567.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Added

- test helper for testing emails
- initial doc on testing
14 changes: 14 additions & 0 deletions docs/tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tests

## Backend Tests

We use pytest in combination with pytest-django and factoryboy to write backend
tests.

### Notes

#### Testing Emails

Emails are not guaranteed to be sent in a deterministic order, 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`.
7 changes: 7 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.core import mail


def get_emails_for_address(email_address):
"""Return all mails send to email_address"""
mails = list(filter(lambda mails: mails.to[0] == email_address, mail.outbox))
return mails

0 comments on commit 783af58

Please sign in to comment.