gva/gnuviechadmin/dashboard/tests/test_views.py

48 lines
1.7 KiB
Python
Raw Normal View History

2015-10-12 20:43:52 +02:00
"""
Tests for :py:mod:`dashboard.views`.
"""
2023-04-29 13:10:25 +02:00
from django import http
2015-10-12 20:43:52 +02:00
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse
2015-10-12 20:43:52 +02:00
User = get_user_model()
TEST_USER = "test"
TEST_PASSWORD = "secret"
2015-10-12 20:43:52 +02:00
class UserDashboardViewTest(TestCase):
def _create_test_user(self):
self.user = User.objects.create(username=TEST_USER)
self.user.set_password(TEST_PASSWORD)
self.user.save()
def test_user_dashboard_view_anonymous(self):
User.objects.create(username=TEST_USER)
2023-04-29 13:10:25 +02:00
response = self.client.get(reverse("customer_dashboard"))
self.assertEqual(response.status_code, 302)
self.assertRedirects(response, "/accounts/login/?next=/")
2015-10-12 20:43:52 +02:00
def test_user_dashboard_view_logged_in_ok(self):
self._create_test_user()
self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD))
2023-04-29 13:10:25 +02:00
response = self.client.get(reverse("customer_dashboard"))
2015-10-12 20:43:52 +02:00
self.assertEqual(response.status_code, 200)
def test_user_dashboard_view_logged_in_template(self):
self._create_test_user()
self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD))
response = self.client.get(
2023-04-29 13:10:25 +02:00
reverse("customer_dashboard")
)
self.assertTemplateUsed(response, "dashboard/user_dashboard.html")
2015-10-12 20:43:52 +02:00
def test_user_dashboard_view_logged_in_context_fresh(self):
self._create_test_user()
self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD))
2023-04-29 13:10:25 +02:00
response = self.client.get(reverse("customer_dashboard"))
self.assertIn("hosting_packages", response.context)
self.assertEqual(len(response.context["hosting_packages"]), 0)