Exemplo n.º 1
0
 def test_password_not_required_with_external_auth(self):
     Config.objects.set_config(
         'external_auth_url', 'http://auth.example.com')
     form = NewUserCreationForm()
     params = {
         'email': factory.make_email(),
         'username': factory.make_name('user')}
     form = NewUserCreationForm(params)
     user = form.save()
     self.assertFalse(user.has_usable_password())
Exemplo n.º 2
0
 def test_email_is_required(self):
     password = factory.make_name('password')
     params = {
         'email': '',
         'username': factory.make_name('user'),
         'password1': password,
         'password2': password,
     }
     form = NewUserCreationForm(params)
     self.assertFalse(form.is_valid())
     self.assertEqual({'email': ['This field is required.']}, form._errors)
Exemplo n.º 3
0
 def test_saves_to_db_by_default(self):
     password = factory.make_name('password')
     params = {
         'email': '*****@*****.**' % factory.make_string(),
         'username': factory.make_name('user'),
         'password1': password,
         'password2': password,
     }
     form = NewUserCreationForm(params)
     form.save()
     self.assertIsNotNone(User.objects.get(username=params['username']))
Exemplo n.º 4
0
 def test_email_is_required(self):
     password = factory.make_name("password")
     params = {
         "email": "",
         "username": factory.make_name("user"),
         "password1": password,
         "password2": password,
     }
     form = NewUserCreationForm(params)
     self.assertFalse(form.is_valid())
     self.assertEqual({"email": ["This field is required."]}, form._errors)
Exemplo n.º 5
0
 def test_saves_to_db_by_default(self):
     password = factory.make_name("password")
     params = {
         "email": "*****@*****.**" % factory.make_string(),
         "username": factory.make_name("user"),
         "password1": password,
         "password2": password,
     }
     form = NewUserCreationForm(params)
     form.save()
     self.assertIsNotNone(User.objects.get(username=params["username"]))
Exemplo n.º 6
0
 def test_password_not_required_with_external_auth(self):
     Config.objects.set_config("external_auth_url",
                               "http://auth.example.com")
     form = NewUserCreationForm()
     params = {
         "email": factory.make_email(),
         "username": factory.make_name("user"),
     }
     form = NewUserCreationForm(params)
     user = form.save()
     self.assertFalse(user.has_usable_password())
Exemplo n.º 7
0
 def test_saves_to_db_by_default(self):
     password = factory.make_name('password')
     params = {
         'email': '*****@*****.**' % factory.getRandomString(),
         'username': factory.make_name('user'),
         'password1': password,
         'password2': password,
     }
     form = NewUserCreationForm(params)
     form.save()
     self.assertIsNotNone(User.objects.get(username=params['username']))
Exemplo n.º 8
0
 def test_does_not_save_to_db_if_commit_is_False(self):
     password = factory.make_name('password')
     params = {
         'email': '*****@*****.**' % factory.make_string(),
         'username': factory.make_name('user'),
         'password1': password,
         'password2': password,
     }
     form = NewUserCreationForm(params)
     form.save(commit=False)
     self.assertItemsEqual([],
                           User.objects.filter(username=params['username']))
Exemplo n.º 9
0
 def test_does_not_save_to_db_if_commit_is_False(self):
     password = factory.make_name("password")
     params = {
         "email": "*****@*****.**" % factory.make_string(),
         "username": factory.make_name("user"),
         "password1": password,
         "password2": password,
     }
     form = NewUserCreationForm(params)
     form.save(commit=False)
     self.assertItemsEqual([],
                           User.objects.filter(username=params["username"]))
Exemplo n.º 10
0
 def test_does_not_save_to_db_if_commit_is_False(self):
     password = factory.make_name('password')
     params = {
         'email': '*****@*****.**' % factory.getRandomString(),
         'username': factory.make_name('user'),
         'password1': password,
         'password2': password,
     }
     form = NewUserCreationForm(params)
     form.save(commit=False)
     self.assertItemsEqual(
         [], User.objects.filter(username=params['username']))
Exemplo n.º 11
0
    def test_fields_order(self):
        form = NewUserCreationForm()

        self.assertEqual([
            'username', 'last_name', 'email', 'password1', 'password2',
            'is_superuser'
        ], list(form.fields))
Exemplo n.º 12
0
 def test_NewUserCreationForm_fails_validation_if_email_taken(self):
     email = '*****@*****.**' % factory.make_string()
     username = factory.make_string()
     password = factory.make_string()
     factory.make_User(email=email)
     form = NewUserCreationForm({
         'email': email,
         'username': username,
         'password1': password,
         'password2': password,
     })
     self.assertFormFailsValidationBecauseEmailNotUnique(form)
Exemplo n.º 13
0
 def test_NewUserCreationForm_fails_validation_if_email_taken(self):
     email = "*****@*****.**" % factory.make_string()
     username = factory.make_string()
     password = factory.make_string()
     factory.make_User(email=email)
     form = NewUserCreationForm({
         "email": email,
         "username": username,
         "password1": password,
         "password2": password,
     })
     self.assertFormFailsValidationBecauseEmailNotUnique(form)
Exemplo n.º 14
0
    def test_fields_order(self):
        form = NewUserCreationForm()

        self.assertEqual(
            [
                "username",
                "last_name",
                "email",
                "password1",
                "password2",
                "is_superuser",
            ],
            list(form.fields),
        )