<s> import datetime <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from django . core import mail <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase <EOL> from registration import forms <EOL> from registration . models import RegistrationProfile <EOL> class RegistrationViewTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . old_activation = getattr ( settings , '<STR_LIT>' , None ) <EOL> if self . old_activation is None : <EOL> settings . ACCOUNT_ACTIVATION_DAYS = <NUM_LIT:7> <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . old_activation is None : <EOL> settings . ACCOUNT_ACTIVATION_DAYS = self . old_activation <EOL> def test_registration_view_initial ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , <EOL> '<STR_LIT>' ) <EOL> self . failUnless ( isinstance ( response . context [ '<STR_LIT>' ] , <EOL> forms . RegistrationForm ) ) <EOL> def test_registration_view_success ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> data = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRedirects ( response , <EOL> '<STR_LIT>' % reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( RegistrationProfile . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> def test_registration_view_failure ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> data = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:bar>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . failIf ( response . context [ '<STR_LIT>' ] . is_valid ( ) ) <EOL> self . assertFormError ( response , '<STR_LIT>' , field = None , <EOL> errors = u"<STR_LIT>" ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:0> ) <EOL> def test_registration_view_closed ( self ) : <EOL> """<STR_LIT>""" <EOL> old_allowed = getattr ( settings , '<STR_LIT>' , True ) <EOL> settings . REGISTRATION_OPEN = False <EOL> closed_redirect = '<STR_LIT>' % reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , closed_redirect ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> data = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRedirects ( response , closed_redirect ) <EOL> self . assertEqual ( RegistrationProfile . objects . count ( ) , <NUM_LIT:0> ) <EOL> settings . REGISTRATION_OPEN = old_allowed <EOL> def test_registration_template_name ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertTemplateUsed ( response , <EOL> '<STR_LIT>' ) <EOL> def test_registration_extra_context ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . context [ '<STR_LIT:foo>' ] , '<STR_LIT:bar>' ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_registration_disallowed_url ( self ) : <EOL> """<STR_LIT>""" <EOL> old_allowed = getattr ( settings , '<STR_LIT>' , True ) <EOL> settings . REGISTRATION_OPEN = False <EOL> closed_redirect = '<STR_LIT>' % reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , closed_redirect ) <EOL> settings . REGISTRATION_OPEN = old_allowed <EOL> def test_registration_success_url ( self ) : <EOL> """<STR_LIT>""" <EOL> success_redirect = '<STR_LIT>' % reverse ( '<STR_LIT>' ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> data = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRedirects ( response , success_redirect ) <EOL> def test_valid_activation ( self ) : <EOL> """<STR_LIT>""" <EOL> success_redirect = '<STR_LIT>' % reverse ( '<STR_LIT>' ) <EOL> self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> data = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> profile = RegistrationProfile . objects . get ( user__username = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : profile . activation_key } ) ) <EOL> self . assertRedirects ( response , success_redirect ) <EOL> self . failUnless ( User . objects . get ( username = '<STR_LIT>' ) . is_active ) <EOL> def test_invalid_activation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> data = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> expired_user = User . objects . get ( username = '<STR_LIT>' ) <EOL> expired_user . date_joined = expired_user . date_joined - datetime . timedelta ( days = settings . ACCOUNT_ACTIVATION_DAYS ) <EOL> expired_user . save ( ) <EOL> expired_profile = RegistrationProfile . objects . get ( user = expired_user ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : expired_profile . activation_key } ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] , <EOL> expired_profile . activation_key ) <EOL> self . failIf ( User . objects . get ( username = '<STR_LIT>' ) . is_active ) <EOL> def test_activation_success_url ( self ) : <EOL> """<STR_LIT>""" <EOL> success_redirect = '<STR_LIT>' % reverse ( '<STR_LIT>' ) <EOL> self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> data = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> profile = RegistrationProfile . objects . get ( user__username = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : profile . activation_key } ) ) <EOL> self . assertRedirects ( response , success_redirect ) <EOL> def test_activation_template_name ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT:foo>' } ) ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> def test_activation_extra_context ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT:foo>' } ) ) <EOL> self . assertEqual ( response . context [ '<STR_LIT:foo>' ] , '<STR_LIT:bar>' ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] , '<STR_LIT>' ) </s>
