I think the naming here is a little confusing.  Intuitively, I'd think that a function called `add_unit` could be called multiple times to create several units; this implementation won't allow that.

Maybe something like `setup_one_unit` would be clearer: the function's job is to do everything necessary to ensure that the user is viewing a single unit, including creating the course, logging the user in, etc.

This should have a docstring as well.