test_urls.py 5.42 KB
Newer Older
David Haynes's avatar
David Haynes committed
1 2 3 4 5 6 7
"""
settings/test_urls.py

References:
    - https://stackoverflow.com/questions/18987051/how-do-i-unit-test-django-urls
"""

David Haynes's avatar
David Haynes committed
8
# Future Imports
David Haynes's avatar
David Haynes committed
9 10
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
David Haynes's avatar
David Haynes committed
11 12 13

# Django Imports
from django.test import TestCase
David Haynes's avatar
David Haynes committed
14
from django.urls import reverse
David Haynes's avatar
David Haynes committed
15 16 17

class UrlsTest(TestCase):
    """
David Haynes's avatar
David Haynes committed
18
    Test cases for the urls
David Haynes's avatar
David Haynes committed
19
    """
David Haynes's avatar
David Haynes committed
20

21
    def test_index_reverse(self):
David Haynes's avatar
David Haynes committed
22 23 24 25
        """
        / - Homepage url.
        """

26 27
        url = reverse('index')
        self.assertEqual(url, '/')
28

29
    def test_view_reverse_chars(self):
David Haynes's avatar
David Haynes committed
30 31 32 33
        """
        /view/<short> - View URL data.
        """

David Haynes's avatar
David Haynes committed
34 35
        url = reverse('view', args=['dhaynes'])
        self.assertEqual(url, '/view/dhaynes')
36

37
    def test_view_reverse_ints(self):
David Haynes's avatar
David Haynes committed
38 39 40 41
        """
        /view/<short> - View URL data.
        """

42 43 44
        url = reverse('view', args=['123456789'])
        self.assertEqual(url, '/view/123456789')

45
    def test_view_reverse_chars_ints(self):
David Haynes's avatar
David Haynes committed
46 47 48 49
        """
        /view/<short> - View URL data.
        """

50 51 52
        url = reverse('view', args=['dhaynes123'])
        self.assertEqual(url, '/view/dhaynes123')

53
    def test_view_reverse_full_slug(self):
David Haynes's avatar
David Haynes committed
54 55 56 57
        """
        /view/<short> - View URL data.
        """

58 59
        url = reverse('view', args=['dhaynes123_-'])
        self.assertEqual(url, '/view/dhaynes123_-')
David Haynes's avatar
David Haynes committed
60

61
    def test_about_reverse(self):
David Haynes's avatar
David Haynes committed
62 63 64 65
        """
        /about - About page.
        """

David Haynes's avatar
David Haynes committed
66 67
        url = reverse('about')
        self.assertEqual(url, '/about')
David Haynes's avatar
David Haynes committed
68

69
    def test_signup_reverse(self):
David Haynes's avatar
David Haynes committed
70 71 72 73
        """
        /signup - Signup page for access.
        """

David Haynes's avatar
David Haynes committed
74 75
        url = reverse('signup')
        self.assertEqual(url, '/signup')
76

David Haynes's avatar
David Haynes committed
77 78 79 80 81 82 83
    def test_new(self):
        """
        /new - Create a new Go Link
        """
        url = reverse("new_link")
        self.assertEqual(url, '/new')

84
    def test_my_links_reverse(self):
David Haynes's avatar
David Haynes committed
85
        """
David Haynes's avatar
David Haynes committed
86
        /my - My-Links page, view and review links.
David Haynes's avatar
David Haynes committed
87 88
        """

89
        url = reverse('my_links')
David Haynes's avatar
David Haynes committed
90
        self.assertEqual(url, '/my')
91

David Haynes's avatar
David Haynes committed
92 93 94 95 96 97
    def test_edit_reverse_chars(self):
        """
        /edit/<short> - Delete a link, no content display.
        """

        url = reverse('edit', args=['dhaynes'])
David Haynes's avatar
David Haynes committed
98
        self.assertEqual(url, '/edit/dhaynes')
David Haynes's avatar
David Haynes committed
99 100 101 102 103 104 105

    def test_edit_reverse_ints(self):
        """
        /edit/<short> - Delete a link, no content display.
        """

        url = reverse('edit', args=['123456789'])
David Haynes's avatar
David Haynes committed
106
        self.assertEqual(url, '/edit/123456789')
David Haynes's avatar
David Haynes committed
107 108 109 110 111 112 113

    def test_edit_reverse_chars_ints(self):
        """
        /edit/<short> - Delete a link, no content display.
        """

        url = reverse('edit', args=['dhaynes123'])
David Haynes's avatar
David Haynes committed
114
        self.assertEqual(url, '/edit/dhaynes123')
David Haynes's avatar
David Haynes committed
115 116 117 118 119 120 121

    def test_edit_reverse_full_slug(self):
        """
        /edit/<short> - Delete a link, no content display.
        """

        url = reverse('edit', args=['dhaynes123_-'])
David Haynes's avatar
David Haynes committed
122
        self.assertEqual(url, '/edit/dhaynes123_-')
David Haynes's avatar
David Haynes committed
123

124
    def test_delete_reverse_chars(self):
David Haynes's avatar
David Haynes committed
125 126 127 128
        """
        /delete/<short> - Delete a link, no content display.
        """

129 130 131
        url = reverse('delete', args=['dhaynes'])
        self.assertEqual(url, '/delete/dhaynes')

132
    def test_delete_reverse_ints(self):
David Haynes's avatar
David Haynes committed
133 134 135 136
        """
        /delete/<short> - Delete a link, no content display.
        """

137 138 139
        url = reverse('delete', args=['123456789'])
        self.assertEqual(url, '/delete/123456789')

140
    def test_delete_reverse_chars_ints(self):
David Haynes's avatar
David Haynes committed
141 142 143 144
        """
            /delete/<short> - Delete a link, no content display.
        """

145 146 147
        url = reverse('delete', args=['dhaynes123'])
        self.assertEqual(url, '/delete/dhaynes123')

148
    def test_delete_reverse_full_slug(self):
David Haynes's avatar
David Haynes committed
149 150 151 152
        """
        /delete/<short> - Delete a link, no content display.
        """

153 154 155
        url = reverse('delete', args=['dhaynes123_-'])
        self.assertEqual(url, '/delete/dhaynes123_-')

156
    def test_registered_reverse(self):
David Haynes's avatar
David Haynes committed
157 158 159 160
        """
        /registered - registration complete page
        """

161 162
        url = reverse('registered')
        self.assertEqual(url, '/registered')
163 164 165 166 167

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

    def test_useradmin(self):
David Haynes's avatar
David Haynes committed
168 169 170 171
        """
        /useradmin - user approval interface
        """

172 173 174
        url = reverse('useradmin')
        self.assertEqual(url, '/useradmin')

175
    def test_login(self):
David Haynes's avatar
David Haynes committed
176 177 178 179
        """
        /login - login portal
        """

180 181 182
        url = reverse('go_login')
        self.assertEqual(url, '/login')

183
    def test_logout(self):
David Haynes's avatar
David Haynes committed
184 185 186 187
        """
        /logout - logout portal
        """

188 189
        url = reverse('go_logout')
        self.assertEqual(url, '/logout')
190 191

    def test_delete_chars(self):
David Haynes's avatar
David Haynes committed
192 193 194 195
        """
        /<short> - Redirect to a go link.
        """

196 197 198 199
        url = reverse('redirection', args=['dhaynes'])
        self.assertEqual(url, '/dhaynes')

    def test_delete_ints(self):
David Haynes's avatar
David Haynes committed
200 201 202 203
        """
        /<short> - Redirect to a go link.
        """

204 205 206 207
        url = reverse('redirection', args=['123456789'])
        self.assertEqual(url, '/123456789')

    def test_delete_chars_ints(self):
David Haynes's avatar
David Haynes committed
208 209 210 211
        """
        /<short> - Redirect to a go link.
        """

212 213 214 215
        url = reverse('redirection', args=['dhaynes123'])
        self.assertEqual(url, '/dhaynes123')

    def test_delete_full_slug(self):
David Haynes's avatar
David Haynes committed
216 217 218 219
        """
        /<short> - Redirect to a go link.
        """

220 221
        url = reverse('redirection', args=['dhaynes123_-'])
        self.assertEqual(url, '/dhaynes123_-')