aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/users/tests/test_views.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-01-19 15:57:06 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-01-19 15:57:06 +0000
commit9d76a3c52b8310726ec09e0262813f0438c21df6 (patch)
tree4acf47dce6c3aa75f8ad7c5cb56fe6486c2d64a7 /ctrack/users/tests/test_views.py
init commit - from cookiecutter
Diffstat (limited to 'ctrack/users/tests/test_views.py')
-rw-r--r--ctrack/users/tests/test_views.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/ctrack/users/tests/test_views.py b/ctrack/users/tests/test_views.py
new file mode 100644
index 0000000..3e7fbf7
--- /dev/null
+++ b/ctrack/users/tests/test_views.py
@@ -0,0 +1,46 @@
+import pytest
+from django.test import RequestFactory
+
+from ctrack.users.models import User
+from ctrack.users.views import UserRedirectView, UserUpdateView
+
+pytestmark = pytest.mark.django_db
+
+
+class TestUserUpdateView:
+ """
+ TODO:
+ extracting view initialization code as class-scoped fixture
+ would be great if only pytest-django supported non-function-scoped
+ fixture db access -- this is a work-in-progress for now:
+ https://github.com/pytest-dev/pytest-django/pull/258
+ """
+
+ def test_get_success_url(self, user: User, request_factory: RequestFactory):
+ view = UserUpdateView()
+ request = request_factory.get("/fake-url/")
+ request.user = user
+
+ view.request = request
+
+ assert view.get_success_url() == f"/users/{user.username}/"
+
+ def test_get_object(self, user: User, request_factory: RequestFactory):
+ view = UserUpdateView()
+ request = request_factory.get("/fake-url/")
+ request.user = user
+
+ view.request = request
+
+ assert view.get_object() == user
+
+
+class TestUserRedirectView:
+ def test_get_redirect_url(self, user: User, request_factory: RequestFactory):
+ view = UserRedirectView()
+ request = request_factory.get("/fake-url")
+ request.user = user
+
+ view.request = request
+
+ assert view.get_redirect_url() == f"/users/{user.username}/"