def test_should_raise_error_password_contain_space_at_the_end_or_at_the_beginning(
            self):
        base_form = {
            'first_name': 'a',
            'last_name': 'b',
            'email': '*****@*****.**',
            'password1': ' pwd1 ',
            'password2': ' pwd1 ',
            'mobile_phone': '1234567',
            'organization_name': 'ad',
            'organization_city': 'aaa',
            'organization_country': 'aa',
            'organization_sector': 'Other',
            'invoice_period': 'pay_monthly'
        }
        form = MinimalRegistrationForm(base_form)

        with patch.object(MinimalRegistrationForm,
                          'clean_mobile_phone') as get_mobile_phone:
            with patch.object(MinimalRegistrationForm,
                              'clean_username') as get_clean_username:
                error_message = 'Test message'
                get_clean_username.return_value = None
                get_mobile_phone.side_effect = ValidationError(error_message)
                self.assertFalse(form.is_valid())
                self.assertEqual([error_message], form.errors['mobile_phone'])
Exemplo n.º 2
0
 def test_should_convert_email_to_lowercase(self):
     base_form = {'first_name': 'a',
                  'last_name': 'b',
                  'email': '*****@*****.**',
                  'password1': 'pwd123!',
                  'password2': 'pwd123!',
                  'mobile_phone':'1234567',
                  'organization_name': 'ad',
                  'organization_city': 'aaa',
                  'organization_country': 'aa',
                  'organization_sector': 'Other',
                  'invoice_period':'pay_monthly'
     }
     form = MinimalRegistrationForm(base_form)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data["email"], "*****@*****.**")