Extract registration test helper

Change-Id: I4ae51094a70677aec158b6d6b02c09a85f5f4ed3
Simplify and combine logic

This reduces the dictionary lookups making the code easier to read
and more reliable.

Change-Id: Ibcafb8d089744d24569b5c0cdff98c469eb0d937
Handle unicode emails when generating verify codes

Previously ny actual unicode characters in the email would throw an
exception here. Encode them as bytes since all we really care about
is getting something unique back.

There is no danger of this affecting existing codes as they're only
generated when new requests are made -- later validation is done
against the database only.

Change-Id: I1022d1565985063fa55b41c121882d2ab3dc386b
Test tidyups from pyflakes

Remove many redundant imports and a duplicate test function.
Rename another function where the names clashed but the content was
different.

Change-Id: I21e5bf7b0a77d176dda251d730d7ecb370422fd1
Detect and reject registrations of invalid emails

We can't support accents etc when sending emails, so reject them
up front.

Change-Id: Ibdddad520dec032ae71a218dcff78dbf6c42d791