mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-01-25 00:34:18 +03:00
Raising coverage of rendered project to 97%.
This commit is contained in:
parent
74509ac5cb
commit
e02dca8228
|
@ -0,0 +1,11 @@
|
||||||
|
from test_plus.test import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestUser(TestCase):
|
||||||
|
|
||||||
|
def test__str__(self):
|
||||||
|
user = self.make_user()
|
||||||
|
self.assertEqual(
|
||||||
|
user.username,
|
||||||
|
"testuser" # This is the default username for self.make_user()
|
||||||
|
)
|
|
@ -0,0 +1,64 @@
|
||||||
|
from django.test import RequestFactory
|
||||||
|
|
||||||
|
from test_plus.test import TestCase
|
||||||
|
|
||||||
|
from ..views import (
|
||||||
|
UserRedirectView,
|
||||||
|
UserUpdateView
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseUserTestCase(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.user = self.make_user()
|
||||||
|
self.factory = RequestFactory()
|
||||||
|
|
||||||
|
|
||||||
|
class TestUserRedirectView(BaseUserTestCase):
|
||||||
|
|
||||||
|
def test_get_redirect_url(self):
|
||||||
|
# Instantiate the view directly. Never do this outside a test!
|
||||||
|
view = UserRedirectView()
|
||||||
|
# Generate a fake request
|
||||||
|
request = self.factory.get('/fake-url')
|
||||||
|
# Attach the user to the request
|
||||||
|
request.user = self.user
|
||||||
|
# Attach the request to the view
|
||||||
|
view.request = request
|
||||||
|
# Expect: '/users/testuser/', as that is the default username for
|
||||||
|
# self.make_user()
|
||||||
|
self.assertEqual(
|
||||||
|
view.get_redirect_url(),
|
||||||
|
'/users/testuser/'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestUserUpdateView(BaseUserTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
# call BaseUserTestCase.setUp()
|
||||||
|
super(TestUserUpdateView, self).setUp()
|
||||||
|
# Instantiate the view directly. Never do this outside a test!
|
||||||
|
self.view = UserUpdateView()
|
||||||
|
# Generate a fake request
|
||||||
|
request = self.factory.get('/fake-url')
|
||||||
|
# Attach the user to the request
|
||||||
|
request.user = self.user
|
||||||
|
# Attach the request to the view
|
||||||
|
self.view.request = request
|
||||||
|
|
||||||
|
def test_get_success_url(self):
|
||||||
|
# Expect: '/users/testuser/', as that is the default username for
|
||||||
|
# self.make_user()
|
||||||
|
self.assertEqual(
|
||||||
|
self.view.get_success_url(),
|
||||||
|
'/users/testuser/'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_get_object(self):
|
||||||
|
# Expect: self.user, as that is the request's user object
|
||||||
|
self.assertEqual(
|
||||||
|
self.view.get_object(),
|
||||||
|
self.user
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user