Automating rollback of database migrations in your Django deployment pipeline

tl;dr: Scroll to the end of the page, and you will find two one-liners that help you record and roll back Django migrations.

Even though Django has nice built-in support for creating and maintaining database migrations, I find it surprising that one feature seems to be missing: There is no easy way to automatically roll back the migrations during a failed deployment.

I have the following workflow in mind for a typical automated, failed deployment.:

[Read More]

End-to-end email testing with testmail.app

While working on MembershipNerd I was looking for a very simple service that would let me write automated, end-to-end tests for sending emails. In particular, I wanted to create an automated test for the sign-up process. By “end-to-end test” I mean that I actually want to send an email, with a real SMTP server, verify that the email has been received by the recipient and contains the correct information.

If I simply wanted to verify that the sign-up triggers an email, then I could use the built-in email service of Django’s testing framework.. If your web framework doesn’t such a convenient way to test email, you might want to have a look at MailHog. Be aware it needs more setup though!

[Read More]

MembershipNerd Day 6: Signing up without a password

I chose to use the third-party library django-allauth to handle user-authentication because that library is mature and well-maintained, as far as I can tell. However, since the main focus of this library seems to be providing integrations for third-party oauth-providers, there is no obvious way to handle my first use case: Provide a way for users to sign-up with only an email – no password, no third-party-login, nothing else required.

In a previous project I had solved a similar problem by overriding the library’s DefaultAccountAdapter-class, which seems to be main integration-point for this kind of customization. But today I found a way that is much more light-weight and straight-forward.

[Read More]