<s> from __future__ import unicode_literals <EOL> from distutils . version import StrictVersion <EOL> from django import get_version <EOL> from django . test import TestCase <EOL> from registration import forms <EOL> from registration . users import UserModel <EOL> DJANGO_VERSION = StrictVersion ( get_version ( ) ) <EOL> class RegistrationFormTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_registration_form ( self ) : <EOL> """<STR_LIT>""" <EOL> UserModel ( ) . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> bad_username_error = '<STR_LIT>' <EOL> if DJANGO_VERSION >= StrictVersion ( '<STR_LIT>' ) : <EOL> bad_username_error = '<STR_LIT>' + bad_username_error <EOL> invalid_data_dicts = [ <EOL> { '<STR_LIT:data>' : { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' } , <EOL> '<STR_LIT:error>' : ( '<STR_LIT:username>' , [ bad_username_error ] ) } , <EOL> { '<STR_LIT:data>' : { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:error>' : ( '<STR_LIT:username>' , [ "<STR_LIT>" ] ) } , <EOL> { '<STR_LIT:data>' : { '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:bar>' } , <EOL> '<STR_LIT:error>' : ( '<STR_LIT>' , [ "<STR_LIT>" ] ) } , <EOL> ] <EOL> for invalid_dict in invalid_data_dicts : <EOL> form = forms . RegistrationForm ( data = invalid_dict [ '<STR_LIT:data>' ] ) <EOL> self . failIf ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors [ invalid_dict [ '<STR_LIT:error>' ] [ <NUM_LIT:0> ] ] , <EOL> invalid_dict [ '<STR_LIT:error>' ] [ <NUM_LIT:1> ] ) <EOL> form = forms . RegistrationForm ( data = { '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' } ) <EOL> self . failUnless ( form . is_valid ( ) ) <EOL> def test_registration_form_tos ( self ) : <EOL> """<STR_LIT>""" <EOL> form = forms . RegistrationFormTermsOfService ( data = { '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' } ) <EOL> self . failIf ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT>' ] , <EOL> [ "<STR_LIT>" ] ) <EOL> form = forms . RegistrationFormTermsOfService ( data = { '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . failUnless ( form . is_valid ( ) ) <EOL> def test_registration_form_unique_email ( self ) : <EOL> """<STR_LIT>""" <EOL> UserModel ( ) . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> form = forms . RegistrationFormUniqueEmail ( data = { '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' } ) <EOL> self . failIf ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT:email>' ] , <EOL> [ "<STR_LIT>" ] ) <EOL> form = forms . RegistrationFormUniqueEmail ( data = { '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' } ) <EOL> self . failUnless ( form . is_valid ( ) ) <EOL> def test_registration_form_no_free_email ( self ) : <EOL> """<STR_LIT>""" <EOL> base_data = { '<STR_LIT:username>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' } <EOL> for domain in forms . RegistrationFormNoFreeEmail . bad_domains : <EOL> invalid_data = base_data . copy ( ) <EOL> invalid_data [ '<STR_LIT:email>' ] = "<STR_LIT>" % domain <EOL> form = forms . RegistrationFormNoFreeEmail ( data = invalid_data ) <EOL> self . failIf ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors [ '<STR_LIT:email>' ] , <EOL> [ "<STR_LIT>" ] ) <EOL> base_data [ '<STR_LIT:email>' ] = '<STR_LIT>' <EOL> form = forms . RegistrationFormNoFreeEmail ( data = base_data ) <EOL> self . failUnless ( form . is_valid ( ) ) </s>
