def register(self, store, email, display_name=None): """See `IUser`.""" # First, see if the address already exists address = store.query(Address).filter_by(email=email).first() if address is None: if display_name is None: display_name = '' address = Address(email=email, display_name=display_name) address.preferences = Preferences() # Link the address to the user if it is not already linked. if address.user is not None: raise AddressAlreadyLinkedError(address) address.user = self return address
def create_address(self, store, email, display_name=None): """See `IUserManager`.""" addresses = store.query(Address).filter(Address.email == email.lower()) if addresses.count() == 1: found = addresses[0] raise ExistingAddressError(found.original_email) assert addresses.count() == 0, 'Unexpected results' if display_name is None: display_name = '' # It's okay not to lower case the 'email' argument because the # constructor will do the right thing. address = Address(email, display_name) address.preferences = Preferences() store.add(address) return address
def test_invalid_email_string_raises_exception(self): with self.assertRaises(InvalidEmailAddressError): Address('not_a_valid_email_string', '')