def test_can_create_noncolliding_nicknames(self): # Given the same email address, generate_nick doesn't recreate the # same nick once that nick is used. self.factory.makePerson(name='bar') nick = generate_nick('*****@*****.**') self.assertEqual('bar-3', nick) # If we used the previously created nick and get another bar@ email # address, another new nick is generated. self.factory.makePerson(name=nick) nick = generate_nick('*****@*****.**') self.assertEqual('5-bar', nick)
def test_handles_symbols(self): # If an email starts with symbols, generate_nick still creates a # valid nick that doesn't start with symbols. parts = ['---bar', 'foo.bar', 'foo-bar', 'foo+bar'] nicks = [generate_nick("*****@*****.**" % part) for part in parts] self.assertEqual(['bar', 'foo-bar', 'foo-bar', 'foo+bar'], nicks)
def test_enforces_minimum_length(self): # Nicks must be a minimum length. generate_nick enforces this by # adding random suffixes to the required length. self.assertIs(None, getUtility(IPersonSet).getByName('i')) nick = generate_nick('*****@*****.**') self.assertEqual('i-b', nick)
def test_uses_email_address(self): # generate_nick uses the first part of the email address to create # the nick. nick = generate_nick('*****@*****.**') self.assertEqual('bar', nick)