test_urls.py 4.19 KB
Newer Older
David Haynes's avatar
David Haynes committed
1
2
3
4
5
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division

# Django Imports
from django.test import TestCase
6
from django.urls import reverse, resolve
David Haynes's avatar
David Haynes committed
7
8
9
10

# App Imports
from .urls import *

11
12
# https://stackoverflow.com/questions/18987051/how-do-i-unit-test-django-urls

David Haynes's avatar
David Haynes committed
13
14
15
16
17
18
"""
    Test cases for the urls
"""
class UrlsTest(TestCase):

    """
19
        / - Homepage url.
David Haynes's avatar
David Haynes committed
20
    """
21
    def test_index_reverse(self):
22
23
        url = reverse('index')
        self.assertEqual(url, '/')
24

David Haynes's avatar
David Haynes committed
25
    """
David Haynes's avatar
David Haynes committed
26
        /view/<short> - View URL data.
David Haynes's avatar
David Haynes committed
27
    """
28
    def test_view_reverse_chars(self):
David Haynes's avatar
David Haynes committed
29
30
        url = reverse('view', args=['dhaynes'])
        self.assertEqual(url, '/view/dhaynes')
31
32

    """
David Haynes's avatar
David Haynes committed
33
        /view/<short> - View URL data.
34
    """
35
    def test_view_reverse_ints(self):
36
37
38
39
        url = reverse('view', args=['123456789'])
        self.assertEqual(url, '/view/123456789')

    """
David Haynes's avatar
David Haynes committed
40
        /view/<short> - View URL data.
41
    """
42
    def test_view_reverse_chars_ints(self):
43
44
45
46
        url = reverse('view', args=['dhaynes123'])
        self.assertEqual(url, '/view/dhaynes123')

    """
David Haynes's avatar
David Haynes committed
47
        /view/<short> - View URL data.
48
    """
49
    def test_view_reverse_full_slug(self):
50
51
        url = reverse('view', args=['dhaynes123_-'])
        self.assertEqual(url, '/view/dhaynes123_-')
David Haynes's avatar
David Haynes committed
52
53
54
55

    """
        /about - About page.
    """
56
    def test_about_reverse(self):
David Haynes's avatar
David Haynes committed
57
58
        url = reverse('about')
        self.assertEqual(url, '/about')
David Haynes's avatar
David Haynes committed
59
60
61
62

    """
        /signup - Signup page for access.
    """
63
    def test_signup_reverse(self):
David Haynes's avatar
David Haynes committed
64
65
        url = reverse('signup')
        self.assertEqual(url, '/signup')
66
67
68
69

    """
        /myLinks - My-Links page, view and review links.
    """
70
    def test_my_links_reverse(self):
71
72
73
74
75
76
        url = reverse('my_links')
        self.assertEqual(url, '/myLinks')

    """
        /delete/<short> - Delete a link, no content display.
    """
77
    def test_delete_reverse_chars(self):
78
79
80
81
82
83
        url = reverse('delete', args=['dhaynes'])
        self.assertEqual(url, '/delete/dhaynes')

    """
        /delete/<short> - Delete a link, no content display.
    """
84
    def test_delete_reverse_ints(self):
85
86
87
88
89
90
        url = reverse('delete', args=['123456789'])
        self.assertEqual(url, '/delete/123456789')

    """
        /delete/<short> - Delete a link, no content display.
    """
91
    def test_delete_reverse_chars_ints(self):
92
93
94
95
96
97
        url = reverse('delete', args=['dhaynes123'])
        self.assertEqual(url, '/delete/dhaynes123')

    """
        /delete/<short> - Delete a link, no content display.
    """
98
    def test_delete_reverse_full_slug(self):
99
100
101
102
103
104
        url = reverse('delete', args=['dhaynes123_-'])
        self.assertEqual(url, '/delete/dhaynes123_-')

    """
        /registered - registration complete page
    """
105
    def test_registered_reverse(self):
106
107
        url = reverse('registered')
        self.assertEqual(url, '/registered')
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

    # The /admin URL is not tested as it is never resolves in source and generally
    # Django yells at you if the admin page breaks

    """
        /useradmin - user approval interface
    """
    def test_useradmin(self):
        url = reverse('useradmin')
        self.assertEqual(url, '/useradmin')

    """
        /login - login portal
    """
    def test_useradmin(self):
        url = reverse('go_login')
        self.assertEqual(url, '/login')

    """
        /logout - logout portal
    """
    def test_useradmin(self):
        url = reverse('go_logout')
        self.assertEqual(url, '/logout')
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

    """
        /<short> - Redirect to a go link.
    """
    def test_delete_chars(self):
        url = reverse('redirection', args=['dhaynes'])
        self.assertEqual(url, '/dhaynes')

    """
        /<short> - Redirect to a go link.
    """
    def test_delete_ints(self):
        url = reverse('redirection', args=['123456789'])
        self.assertEqual(url, '/123456789')

    """
        /<short> - Redirect to a go link.
    """
    def test_delete_chars_ints(self):
        url = reverse('redirection', args=['dhaynes123'])
        self.assertEqual(url, '/dhaynes123')

    """
        /<short> - Redirect to a go link.
    """
    def test_delete_full_slug(self):
        url = reverse('redirection', args=['dhaynes123_-'])
        self.assertEqual(url, '/dhaynes123_-')