def test_registration_form_is_valid(self, mock_user_number_over_limit): mock_user_number_over_limit.return_value = False user_info = { 'email': '%s@%s.com' % (randstring(10), randstring(10)), 'userid': randstring(40), 'password1': 'password', 'password2': 'password', } f = RegistrationForm(data=user_info) self.assertTrue(f.is_valid())
def test_registration_form_email_invalid_for_user_exist( self, mock_user_number_over_limit): mock_user_number_over_limit.return_value = False user_info = { # invalid email 'email': USERNAME, 'userid': randstring(40), 'password1': 'password', 'password2': 'password', } f = RegistrationForm(data=user_info) assert 'User %s already exists.' % USERNAME in str(f['email'].errors)
def test_registration_form_email_invalid_for_exceed_limit( self, mock_user_number_over_limit): mock_user_number_over_limit.return_value = True user_info = { 'email': '%s@%s.com' % (randstring(10), randstring(10)), 'userid': randstring(40), 'password1': 'password', 'password2': 'password', } f = RegistrationForm(data=user_info) assert 'The number of users exceeds the limit.' in str( f['email'].errors)
def test_registration_form_email_invalid(self, mock_user_number_over_limit): mock_user_number_over_limit.return_value = False user_info = { # invalid email without `@` 'email': '%s%s.com' % (randstring(10), randstring(10)), 'userid': randstring(40), 'password1': 'password', 'password2': 'password', } f = RegistrationForm(data=user_info) assert 'Enter a valid email address.' in str(f['email'].errors)
def test_registration_form_userid_invalid(self, mock_user_number_over_limit): mock_user_number_over_limit.return_value = False user_info = { 'email': '%s@%s.com' % (randstring(10), randstring(10)), # invalid userid length < 40 'userid': randstring(10), 'password1': 'password', 'password2': 'password', } f = RegistrationForm(data=user_info) assert 'Invalid user id.' in str(f['userid'].errors)
def test_registration_form_password_invalid(self, mock_user_number_over_limit): mock_user_number_over_limit.return_value = False user_info = { 'email': '%s@%s.com' % (randstring(10), randstring(10)), 'userid': randstring(40), # invalid password 'password1': 'password1', 'password2': 'password2', } f = RegistrationForm(data=user_info) # to escape `'` assert escape("The two password fields didn't match.") in str( f['password2'].errors)