Add a test for the user creation view
This commit is contained in:
parent
5759cd47bb
commit
27fc356045
1 changed files with 33 additions and 2 deletions
|
@ -1,3 +1,34 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase, Client
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
|
class TestUserCreation(TestCase):
|
||||||
|
def test_create_view(self):
|
||||||
|
"""Create a user using the user creation form"""
|
||||||
|
user_data = {
|
||||||
|
"username": "MrsFoobar",
|
||||||
|
"first_name": "Baz",
|
||||||
|
"last_name": "Foobar",
|
||||||
|
"email": "baz@foobar.net",
|
||||||
|
}
|
||||||
|
|
||||||
|
data = user_data.copy()
|
||||||
|
data["password1"] = "4zwY5jdI"
|
||||||
|
data["password2"] = "4zwY5jdI"
|
||||||
|
data["key"] = settings.CREATE_USER_KEY
|
||||||
|
|
||||||
|
client = Client()
|
||||||
|
resp = client.post("/user/create/", data)
|
||||||
|
|
||||||
|
# The user redirection means successful form validation
|
||||||
|
self.assertRedirects(resp, "/")
|
||||||
|
|
||||||
|
# The user should know exist
|
||||||
|
user = (
|
||||||
|
User.objects
|
||||||
|
.filter(username=data["username"])
|
||||||
|
.values(*user_data.keys())
|
||||||
|
[0]
|
||||||
|
)
|
||||||
|
self.assertEqual(user_data, user)
|
||||||
|
|
Loading…
Reference in a new issue