From e02dca8228169f1fd6076cd72c075bcd2f5d9318 Mon Sep 17 00:00:00 2001 From: Daniel Greenfeld Date: Thu, 6 Aug 2015 18:54:27 -0700 Subject: [PATCH] Raising coverage of rendered project to 97%. --- .../users/tests/test_models.py | 11 ++++ .../users/tests/test_views.py | 64 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 {{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/users/tests/test_models.py create mode 100644 {{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/users/tests/test_views.py diff --git a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/users/tests/test_models.py b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/users/tests/test_models.py new file mode 100644 index 00000000..64038e79 --- /dev/null +++ b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/users/tests/test_models.py @@ -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() + ) diff --git a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/users/tests/test_views.py b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/users/tests/test_views.py new file mode 100644 index 00000000..23f30f03 --- /dev/null +++ b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/users/tests/test_views.py @@ -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 + )