add unit tests for dashboard app
This commit is contained in:
parent
660ffa9de9
commit
084dd5ba8d
2 changed files with 76 additions and 0 deletions
4
gnuviechadmin/dashboard/tests/__init__.py
Normal file
4
gnuviechadmin/dashboard/tests/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
"""
|
||||||
|
Tests for :py:mod:`dashboard`.
|
||||||
|
|
||||||
|
"""
|
72
gnuviechadmin/dashboard/tests/test_views.py
Normal file
72
gnuviechadmin/dashboard/tests/test_views.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
"""
|
||||||
|
Tests for :py:mod:`dashboard.views`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
from dashboard.views import (
|
||||||
|
IndexView,
|
||||||
|
UserDashboardView,
|
||||||
|
)
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
TEST_USER = 'test'
|
||||||
|
TEST_PASSWORD = 'secret'
|
||||||
|
|
||||||
|
|
||||||
|
class IndexViewTest(TestCase):
|
||||||
|
|
||||||
|
def test_index_view(self):
|
||||||
|
response = self.client.get(reverse('dashboard'))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTemplateUsed(response, 'dashboard/index.html')
|
||||||
|
|
||||||
|
|
||||||
|
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_no_user(self):
|
||||||
|
response = self.client.get(reverse(
|
||||||
|
'customer_dashboard', kwargs={'slug': TEST_USER}))
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
def test_user_dashboard_view_anonymous(self):
|
||||||
|
User.objects.create(username=TEST_USER)
|
||||||
|
response = self.client.get(reverse(
|
||||||
|
'customer_dashboard', kwargs={'slug': TEST_USER}))
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
def test_user_dashboard_view_logged_in_ok(self):
|
||||||
|
self._create_test_user()
|
||||||
|
self.assertTrue(
|
||||||
|
self.client.login(username=TEST_USER, password=TEST_PASSWORD))
|
||||||
|
response = self.client.get(reverse(
|
||||||
|
'customer_dashboard', kwargs={'slug': TEST_USER}))
|
||||||
|
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(reverse(
|
||||||
|
'customer_dashboard', kwargs={'slug': TEST_USER}))
|
||||||
|
self.assertTemplateUsed(response, 'dashboard/user_dashboard.html')
|
||||||
|
|
||||||
|
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))
|
||||||
|
response = self.client.get(reverse(
|
||||||
|
'customer_dashboard', kwargs={'slug': TEST_USER}))
|
||||||
|
self.assertIn('dashboard_user', response.context)
|
||||||
|
self.assertEqual(self.user, response.context['dashboard_user'])
|
||||||
|
self.assertIn('hosting_packages', response.context)
|
||||||
|
self.assertEqual(len(response.context['hosting_packages']), 0)
|
Loading…
Reference in a new issue