<s> import fudge <EOL> import mock <EOL> from nose . tools import eq_ <EOL> from django . conf import settings <EOL> from olympia . amo . tests import TestCase <EOL> from olympia . users . models import BlacklistedName <EOL> from olympia . users . utils import EmailResetCode , autocreate_username <EOL> class TestEmailResetCode ( TestCase ) : <EOL> def test_parse ( self ) : <EOL> id = <NUM_LIT:1> <EOL> mail = '<STR_LIT>' <EOL> token , hash = EmailResetCode . create ( id , mail ) <EOL> r_id , r_mail = EmailResetCode . parse ( token , hash ) <EOL> eq_ ( id , r_id ) <EOL> eq_ ( mail , r_mail ) <EOL> self . assertRaises ( ValueError , EmailResetCode . parse , token , hash [ : - <NUM_LIT:5> ] ) <EOL> self . assertRaises ( ValueError , EmailResetCode . parse , token [ <NUM_LIT:5> : ] , hash ) <EOL> class TestAutoCreateUsername ( TestCase ) : <EOL> def test_invalid_characters ( self ) : <EOL> eq_ ( autocreate_username ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> def test_empty_username_is_a_random_hash ( self ) : <EOL> un = autocreate_username ( '<STR_LIT>' ) <EOL> assert len ( un ) and not un . startswith ( '<STR_LIT>' ) , '<STR_LIT>' % un <EOL> def test_blacklisted ( self ) : <EOL> BlacklistedName . objects . create ( name = '<STR_LIT>' ) <EOL> un = autocreate_username ( '<STR_LIT>' ) <EOL> assert un != '<STR_LIT>' , '<STR_LIT>' % un <EOL> def test_too_long ( self ) : <EOL> un = autocreate_username ( '<STR_LIT:f>' + '<STR_LIT:u>' * <NUM_LIT:255> ) <EOL> assert not un . startswith ( '<STR_LIT>' ) , '<STR_LIT>' % un <EOL> @ mock . patch . object ( settings , '<STR_LIT>' , <NUM_LIT:3> ) <EOL> @ fudge . patch ( '<STR_LIT>' ) <EOL> def test_too_many_tries ( self , filter ) : <EOL> filter = ( filter . is_callable ( ) . returns_fake ( ) . provides ( '<STR_LIT:count>' ) <EOL> . returns ( <NUM_LIT:1> ) ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> filter = filter . next_call ( ) . returns ( <NUM_LIT:1> ) <EOL> filter = filter . next_call ( ) . returns ( <NUM_LIT:0> ) <EOL> un = autocreate_username ( '<STR_LIT>' ) <EOL> assert not un . startswith ( '<STR_LIT>' ) , '<STR_LIT>' % un <EOL> @ fudge . patch ( '<STR_LIT>' ) <EOL> def test_duplicate_username_counter ( self , filter ) : <EOL> filter = ( filter . expects_call ( ) . returns_fake ( ) . expects ( '<STR_LIT:count>' ) <EOL> . returns ( <NUM_LIT:1> ) <EOL> . next_call ( ) <EOL> . returns ( <NUM_LIT:1> ) <EOL> . next_call ( ) <EOL> . returns ( <NUM_LIT:0> ) ) <EOL> eq_ ( autocreate_username ( '<STR_LIT>' ) , '<STR_LIT>' ) </s>
