<s> import re <EOL> from django . contrib . auth import get_user_model <EOL> from django . core import mail <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase <EOL> from django . test . utils import override_settings <EOL> from users . forms import RegistrationForm , RegistrationFormHoneypot <EOL> class RegisterViewTest ( TestCase ) : <EOL> user_data = { <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> @ override_settings ( USERS_REGISTRATION_OPEN = True ) <EOL> def test_registration_allowed ( self ) : <EOL> resp = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , resp . status_code ) <EOL> @ override_settings ( USERS_REGISTRATION_OPEN = False ) <EOL> def test_registration_closed ( self ) : <EOL> resp = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( resp , reverse ( '<STR_LIT>' ) ) <EOL> @ override_settings ( USERS_SPAM_PROTECTION = False ) <EOL> def test_registration_form ( self ) : <EOL> resp = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , resp . status_code ) <EOL> self . failUnless ( isinstance ( resp . context [ '<STR_LIT>' ] , RegistrationForm ) ) <EOL> @ override_settings ( USERS_SPAM_PROTECTION = True ) <EOL> def test_registration_form_with_honeypot ( self ) : <EOL> resp = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT:200> , resp . status_code ) <EOL> self . failUnless ( isinstance ( resp . context [ '<STR_LIT>' ] , RegistrationFormHoneypot ) ) <EOL> def test_registration ( self ) : <EOL> resp = self . client . post ( reverse ( '<STR_LIT>' ) , self . user_data ) <EOL> self . assertRedirects ( resp , reverse ( '<STR_LIT>' ) ) <EOL> def test_registration_created_new_user ( self ) : <EOL> resp = self . client . post ( reverse ( '<STR_LIT>' ) , self . user_data ) <EOL> self . assertEqual ( get_user_model ( ) . objects . all ( ) . count ( ) , <NUM_LIT:1> ) <EOL> @ override_settings ( LOGIN_REDIRECT_URL = reverse ( '<STR_LIT>' ) ) <EOL> def test_authenticated_users_are_redirected ( self ) : <EOL> user = get_user_model ( ) . objects . create_user ( <EOL> self . user_data [ '<STR_LIT:email>' ] , self . user_data [ '<STR_LIT>' ] , is_active = True ) <EOL> login = self . client . login ( <EOL> username = self . user_data [ '<STR_LIT:email>' ] , <EOL> password = self . user_data [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( login , True ) <EOL> resp = self . client . post ( reverse ( '<STR_LIT>' ) , self . user_data ) <EOL> self . assertRedirects ( resp , reverse ( '<STR_LIT>' ) ) <EOL> @ override_settings ( USERS_VERIFY_EMAIL = True ) <EOL> def test_registered_user_is_not_active ( self ) : <EOL> resp = self . client . post ( reverse ( '<STR_LIT>' ) , self . user_data ) <EOL> new_user = get_user_model ( ) . objects . get ( email = self . user_data [ '<STR_LIT:email>' ] ) <EOL> self . failIf ( new_user . is_active ) <EOL> @ override_settings ( USERS_VERIFY_EMAIL = True ) <EOL> def test_activation_email_was_sent ( self ) : <EOL> resp = self . client . post ( reverse ( '<STR_LIT>' ) , self . user_data ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> class ActivationViewTest ( TestCase ) : <EOL> user_data = { <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> @ override_settings ( USERS_VERIFY_EMAIL = True ) <EOL> def test_activation_view ( self ) : <EOL> self . client . post ( reverse ( '<STR_LIT>' ) , self . user_data ) <EOL> activation_email = mail . outbox [ <NUM_LIT:0> ] <EOL> urlmatch = re . search ( r'<STR_LIT>' , activation_email . body ) <EOL> self . assertTrue ( urlmatch is not None , '<STR_LIT>' ) <EOL> resp = self . client . get ( urlmatch . groups ( ) [ <NUM_LIT:0> ] ) <EOL> self . assertRedirects ( resp , reverse ( '<STR_LIT>' ) ) <EOL> new_user = get_user_model ( ) . objects . get ( email = self . user_data [ '<STR_LIT:email>' ] ) <EOL> self . assertTrue ( new_user . is_active ) <EOL> @ override_settings ( USERS_VERIFY_EMAIL = True ) <EOL> def test_activation_view_fails_as_expected ( self ) : <EOL> url = reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> resp = self . client . get ( url ) <EOL> self . assertEqual ( <NUM_LIT:200> , resp . status_code ) <EOL> self . failUnless ( resp . context [ '<STR_LIT:title>' ] , '<STR_LIT>' ) </s>
