Unverified Commit b412052b authored by David Haynes's avatar David Haynes
Browse files

Finish first pass on index tests

- To be honest I'm pretty dissapointed by the support for integration
test for views
- There are some things you can do with like RequestFactory but I have
not found a way to test the way we handle Users that works well
- For now, just ping that the page renders -- maybe in the future work
on improving test_views
parent 5a8aa75b
Pipeline #1149 failed with stage
in 1 minute and 2 seconds
......@@ -10,41 +10,68 @@ from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Django Imports
from django.test import TestCase
from django.test import TestCase, Client
from django.contrib.auth.models import User
# App Imports
from go.views import (index, view, my_links, delete, signup, redirection,
useradmin)
from go.models import URL, RegisteredUser
class IndexTest(TestCase):
"""
Test cases for the index view
"""
def test_django_test(self):
def test_index_get_anon(self):
"""
Default test case, does not actually test anything
Test that the index view loads (200 OK) for anons
"""
self.assertEqual("Hello World!", "Hello World!")
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
class ViewTest(TestCase):
def test_index_get_auth(self):
"""
Test that the index view loads (200 OK) for authed users
"""
client = Client()
client.login(username='dhaynes', password='password')
response = client.get('/')
self.assertEqual(response.status_code, 200)
class NewLinkTest(TestCase):
"""
Test cases for the "view" view
Test cases for the new_link view
"""
def test_django_test(self):
def test_new_link_get_anon(self):
"""
Default test case, does not actually test anything
Test that the index view redirects anons to login with cas on an EXTERNAL
CAS link, so 302 REDIRECT.
"""
self.assertEqual("Hello World!", "Hello World!")
response = self.client.get('/newLink')
self.assertEqual(response.status_code, 302)
class MyLinksTest(TestCase):
"""
Test cases for the my_links view
"""
def test_new_link_get_anon(self):
"""
Test that the index view redirects anons to login with cas on an EXTERNAL
CAS link, so 302 REDIRECT.
"""
response = self.client.get('/myLinks')
self.assertEqual(response.status_code, 302)
class PostTest(TestCase):
"""
Test cases for the post() helper function
"""
def test_django_test(self):
"""
Default test case, does not actually test anything
......@@ -52,35 +79,101 @@ class MyLinksTest(TestCase):
self.assertEqual("Hello World!", "Hello World!")
class ViewTest(TestCase):
"""
Test cases for the "view" view
"""
def setUp(self):
"""
Set up any variables such as dummy objects that will be utilised in
testing methods
"""
# Setup a blank URL object with an owner
User.objects.create(username='dhaynes', password='password')
get_user = User.objects.get(username='dhaynes')
get_registered_user = RegisteredUser.objects.get(user=get_user)
URL.objects.create(owner=get_registered_user, short='test')
def test_view_get_anon(self):
"""
Test that the view Go link view loads (200 OK) for anon users
"""
response = self.client.get('/view/test')
self.assertEqual(response.status_code, 200)
class DeleteTest(TestCase):
"""
Test cases for the delete view
"""
def test_django_test(self):
def setUp(self):
"""
Default test case, does not actually test anything
Set up any variables such as dummy objects that will be utilised in
testing methods
"""
self.assertEqual("Hello World!", "Hello World!")
# Setup a blank URL object with an owner
User.objects.create(username='dhaynes', password='password')
get_user = User.objects.get(username='dhaynes')
get_registered_user = RegisteredUser.objects.get(user=get_user)
URL.objects.create(owner=get_registered_user, short='test')
def test_delete_get_anon(self):
"""
Test that the delete view redirects anons to login with cas on an EXTERNAL
CAS link, so 302 REDIRECT.
"""
response = self.client.get('/delete/test')
self.assertEqual(response.status_code, 302)
class SignupTest(TestCase):
"""
Test cases for the signup view
"""
def test_django_test(self):
def test_signup_get_anon(self):
"""
Default test case, does not actually test anything
Test that the signup view redirects anons to login with cas on an EXTERNAL
CAS link, so 302 REDIRECT.
"""
self.assertEqual("Hello World!", "Hello World!")
response = self.client.get('/signup')
self.assertEqual(response.status_code, 302)
class RedirectionTest(TestCase):
"""
Test cases for the redirection view
"""
def setUp(self):
"""
Set up any variables such as dummy objects that will be utilised in
testing methods
"""
# Setup a blank URL object with an owner
User.objects.create(username='dhaynes', password='password')
get_user = User.objects.get(username='dhaynes')
get_registered_user = RegisteredUser.objects.get(user=get_user)
URL.objects.create(owner=get_registered_user, short='test', target='https://srct.gmu.edu')
def test_redirect_get_anon(self):
"""
Test that redirection works as intentioned on anon users.
"""
response = self.client.get('/test')
self.assertEqual(response.status_code, 302)
class StaffMemberRequiredTest(TestCase):
"""
Test cases for the staff_member_required() helper function
"""
def test_django_test(self):
"""
Default test case, does not actually test anything
......@@ -93,9 +186,11 @@ class UserAdminTest(TestCase):
Test cases for the useradmin view
"""
def test_django_test(self):
def test_useradmin_get_anon(self):
"""
Default test case, does not actually test anything
Test that the useradmin view redirects anons to login with cas on an EXTERNAL
CAS link, so 302 REDIRECT.
"""
self.assertEqual("Hello World!", "Hello World!")
response = self.client.get('/useradmin')
self.assertEqual(response.status_code, 302)
......@@ -192,29 +192,6 @@ def view(request, short):
'domain': domain,
})
@login_required
def my_links(request):
"""
This view displays all the information about all of your URLs. You
obviously need to be logged in to view your URLs.
"""
# Do not display this page to unapproved users
if not request.user.registereduser.approved:
return render(request, 'not_registered.html')
# Get the current domain info
domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST')) + "/"
# Grab a list of all the URL's that are currently owned by the user
urls = URL.objects.filter(owner=request.user.registereduser)
# Render my_links.html passing the list of URL's and Domain to the template
return render(request, 'my_links.html', {
'urls': urls,
'domain': domain,
})
@login_required
def delete(request, short):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment