test_urls.py 4.79 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 9
# Django Imports
from django.test import TestCase
David Haynes's avatar
David Haynes committed
10
from django.urls import reverse
David Haynes's avatar
David Haynes committed
11 12 13

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

17
    def test_index_reverse(self):
David Haynes's avatar
David Haynes committed
18 19 20 21
        """
        / - Homepage url.
        """

22 23
        url = reverse('index')
        self.assertEqual(url, '/')
24

25
    def test_view_reverse_chars(self):
David Haynes's avatar
David Haynes committed
26 27 28 29
        """
        /view/<short> - View URL data.
        """

David Haynes's avatar
David Haynes committed
30 31
        url = reverse('view', args=['dhaynes'])
        self.assertEqual(url, '/view/dhaynes')
32

33
    def test_view_reverse_ints(self):
David Haynes's avatar
David Haynes committed
34 35 36 37
        """
        /view/<short> - View URL data.
        """

38 39 40
        url = reverse('view', args=['123456789'])
        self.assertEqual(url, '/view/123456789')

41
    def test_view_reverse_chars_ints(self):
David Haynes's avatar
David Haynes committed
42 43 44 45
        """
        /view/<short> - View URL data.
        """

46 47 48
        url = reverse('view', args=['dhaynes123'])
        self.assertEqual(url, '/view/dhaynes123')

49
    def test_view_reverse_full_slug(self):
David Haynes's avatar
David Haynes committed
50 51 52 53
        """
        /view/<short> - View URL data.
        """

54 55
        url = reverse('view', args=['dhaynes123_-'])
        self.assertEqual(url, '/view/dhaynes123_-')
David Haynes's avatar
David Haynes committed
56

57
    def test_about_reverse(self):
David Haynes's avatar
David Haynes committed
58 59 60 61
        """
        /about - About page.
        """

David Haynes's avatar
David Haynes committed
62 63
        url = reverse('about')
        self.assertEqual(url, '/about')
David Haynes's avatar
David Haynes committed
64

65
    def test_my_links_reverse(self):
David Haynes's avatar
David Haynes committed
66 67 68 69
        """
        /myLinks - My-Links page, view and review links.
        """

70 71 72
        url = reverse('my_links')
        self.assertEqual(url, '/myLinks')

David Haynes's avatar
David Haynes committed
73 74 75 76 77 78
    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
79
        self.assertEqual(url, '/edit/dhaynes')
David Haynes's avatar
David Haynes committed
80 81 82 83 84 85 86

    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
87
        self.assertEqual(url, '/edit/123456789')
David Haynes's avatar
David Haynes committed
88 89 90 91 92 93 94

    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
95
        self.assertEqual(url, '/edit/dhaynes123')
David Haynes's avatar
David Haynes committed
96 97 98 99 100 101 102

    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
103
        self.assertEqual(url, '/edit/dhaynes123_-')
David Haynes's avatar
David Haynes committed
104 105


106
    def test_delete_reverse_chars(self):
David Haynes's avatar
David Haynes committed
107 108 109 110
        """
        /delete/<short> - Delete a link, no content display.
        """

111 112 113
        url = reverse('delete', args=['dhaynes'])
        self.assertEqual(url, '/delete/dhaynes')

114
    def test_delete_reverse_ints(self):
David Haynes's avatar
David Haynes committed
115 116 117 118
        """
        /delete/<short> - Delete a link, no content display.
        """

119 120 121
        url = reverse('delete', args=['123456789'])
        self.assertEqual(url, '/delete/123456789')

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

127 128 129
        url = reverse('delete', args=['dhaynes123'])
        self.assertEqual(url, '/delete/dhaynes123')

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

135 136 137
        url = reverse('delete', args=['dhaynes123_-'])
        self.assertEqual(url, '/delete/dhaynes123_-')

138 139 140 141
    # 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
142 143 144 145
        """
        /useradmin - user approval interface
        """

146 147 148
        url = reverse('useradmin')
        self.assertEqual(url, '/useradmin')

149
    def test_login(self):
David Haynes's avatar
David Haynes committed
150 151 152 153
        """
        /login - login portal
        """

154 155 156
        url = reverse('go_login')
        self.assertEqual(url, '/login')

157
    def test_logout(self):
David Haynes's avatar
David Haynes committed
158 159 160 161
        """
        /logout - logout portal
        """

162 163
        url = reverse('go_logout')
        self.assertEqual(url, '/logout')
164 165

    def test_delete_chars(self):
David Haynes's avatar
David Haynes committed
166 167 168 169
        """
        /<short> - Redirect to a go link.
        """

170 171 172 173
        url = reverse('redirection', args=['dhaynes'])
        self.assertEqual(url, '/dhaynes')

    def test_delete_ints(self):
David Haynes's avatar
David Haynes committed
174 175 176 177
        """
        /<short> - Redirect to a go link.
        """

178 179 180 181
        url = reverse('redirection', args=['123456789'])
        self.assertEqual(url, '/123456789')

    def test_delete_chars_ints(self):
David Haynes's avatar
David Haynes committed
182 183 184 185
        """
        /<short> - Redirect to a go link.
        """

186 187 188 189
        url = reverse('redirection', args=['dhaynes123'])
        self.assertEqual(url, '/dhaynes123')

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

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