def test_email_is_converted_to_lower_case(self):
        uppercase_email_id = '*****@*****.**'
        base_form = {'first_name': 'a',
                     'last_name': 'b',
                     'email': uppercase_email_id,
                     'password1': 'a', 'password2': 'a', 'organization_name': 'ad',
                     'organization_address': 'asa', 'organization_city': 'aaa', 'organization_country': 'aa',
                     'organization_zipcode': 'asd', 'organization_sector': 'Other'
        }

        form = RegistrationForm(base_form)
        with patch.object(RegistrationForm, 'clean_email') as get_clean_email:
            with patch.object(RegistrationForm, 'clean_username') as get_clean_username:
                get_clean_email.return_value = uppercase_email_id
                get_clean_username.return_value = None
                self.assertTrue(form.is_valid())
                self.assertTrue(form.cleaned_data.get('email') == '*****@*****.**')
 def test_error_when_password_and_confirm_password_do_not_match(self):
     base_form = {'first_name': 'a',
                  'last_name': 'b',
                  'email': '*****@*****.**',
                  'password1': 'a',
                  'password2': 'b',
                  'organization_name': 'ad',
                  'organization_addressline1': 'asa',
                  'organization_city': 'aaa',
                  'organization_country': 'aa',
                  'organization_zipcode': 'asd',
                  'organization_sector': 'Other'
     }
     form = RegistrationForm(base_form)
     with patch.object(RegistrationForm, 'clean_email') as get_clean_email:
         with patch.object(RegistrationForm, 'clean_username') as get_clean_username:
             get_clean_email.return_value = '*****@*****.**'
             get_clean_username.return_value = None
             self.assertFalse(form.is_valid())
             self.assertTrue(form.errors['password1'])
 def test_error_when_password_and_confirm_password_do_not_match(self):
     base_form = {
         'first_name': 'a',
         'last_name': 'b',
         'email': '*****@*****.**',
         'password1': 'a',
         'password2': 'b',
         'organization_name': 'ad',
         'organization_addressline1': 'asa',
         'organization_city': 'aaa',
         'organization_country': 'aa',
         'organization_zipcode': 'asd',
         'organization_sector': 'Other'
     }
     form = RegistrationForm(base_form)
     with patch.object(RegistrationForm, 'clean_email') as get_clean_email:
         with patch.object(RegistrationForm,
                           'clean_username') as get_clean_username:
             get_clean_email.return_value = '*****@*****.**'
             get_clean_username.return_value = None
             self.assertFalse(form.is_valid())
             self.assertTrue(form.errors['password1'])
    def test_email_is_converted_to_lower_case(self):
        uppercase_email_id = '*****@*****.**'
        base_form = {
            'first_name': 'a',
            'last_name': 'b',
            'email': uppercase_email_id,
            'password1': 'a',
            'password2': 'a',
            'organization_name': 'ad',
            'organization_address': 'asa',
            'organization_city': 'aaa',
            'organization_country': 'aa',
            'organization_zipcode': 'asd',
            'organization_sector': 'Other'
        }

        form = RegistrationForm(base_form)
        with patch.object(RegistrationForm, 'clean_email') as get_clean_email:
            with patch.object(RegistrationForm,
                              'clean_username') as get_clean_username:
                get_clean_email.return_value = uppercase_email_id
                get_clean_username.return_value = None
                self.assertTrue(form.is_valid())
                self.assertTrue(form.cleaned_data.get('email') == '*****@*****.**')