test_urls.py 5.31 KB
Newer Older
David Haynes's avatar
David Haynes committed
1 2 3
"""
settings/test_urls.py

David Haynes's avatar
David Haynes committed
4 5
Test that all the URLs route properly.

David Haynes's avatar
David Haynes committed
6 7 8
References:
    - https://stackoverflow.com/questions/18987051/how-do-i-unit-test-django-urls
"""
David Haynes's avatar
David Haynes committed
9 10
# Django Imports
from django.test import TestCase
David Haynes's avatar
David Haynes committed
11
from django.urls import reverse
David Haynes's avatar
David Haynes committed
12 13

class UrlsTest(TestCase):
14
    def test_index_reverse(self):
David Haynes's avatar
David Haynes committed
15 16 17
        """
        / - Homepage url.
        """
18 19
        url = reverse('index')
        self.assertEqual(url, '/')
20

21
    def test_view_reverse_chars(self):
David Haynes's avatar
David Haynes committed
22 23 24
        """
        /view/<short> - View URL data.
        """
David Haynes's avatar
David Haynes committed
25 26
        url = reverse('view', args=['dhaynes'])
        self.assertEqual(url, '/view/dhaynes')
27

28
    def test_view_reverse_ints(self):
David Haynes's avatar
David Haynes committed
29 30 31
        """
        /view/<short> - View URL data.
        """
32 33 34
        url = reverse('view', args=['123456789'])
        self.assertEqual(url, '/view/123456789')

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

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

49
    def test_about_reverse(self):
David Haynes's avatar
David Haynes committed
50 51 52
        """
        /about - About page.
        """
David Haynes's avatar
David Haynes committed
53 54
        url = reverse('about')
        self.assertEqual(url, '/about')
David Haynes's avatar
David Haynes committed
55

56
    def test_signup_reverse(self):
David Haynes's avatar
David Haynes committed
57 58 59
        """
        /signup - Signup page for access.
        """
David Haynes's avatar
David Haynes committed
60 61
        url = reverse('signup')
        self.assertEqual(url, '/signup')
62

David Haynes's avatar
David Haynes committed
63 64 65 66 67 68 69
    def test_new(self):
        """
        /new - Create a new Go Link
        """
        url = reverse("new_link")
        self.assertEqual(url, '/new')

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

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

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

    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
96
        self.assertEqual(url, '/edit/dhaynes123')
David Haynes's avatar
David Haynes committed
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
    def test_delete_reverse_chars(self):
David Haynes's avatar
David Haynes committed
106 107 108
        """
        /delete/<short> - Delete a link, no content display.
        """
109 110 111
        url = reverse('delete', args=['dhaynes'])
        self.assertEqual(url, '/delete/dhaynes')

112
    def test_delete_reverse_ints(self):
David Haynes's avatar
David Haynes committed
113 114 115
        """
        /delete/<short> - Delete a link, no content display.
        """
116 117 118
        url = reverse('delete', args=['123456789'])
        self.assertEqual(url, '/delete/123456789')

119
    def test_delete_reverse_chars_ints(self):
David Haynes's avatar
David Haynes committed
120
        """
121
        /delete/<short> - Delete a link, no content display.
David Haynes's avatar
David Haynes committed
122
        """
123 124 125
        url = reverse('delete', args=['dhaynes123'])
        self.assertEqual(url, '/delete/dhaynes123')

126
    def test_delete_reverse_full_slug(self):
David Haynes's avatar
David Haynes committed
127 128 129
        """
        /delete/<short> - Delete a link, no content display.
        """
130 131 132
        url = reverse('delete', args=['dhaynes123_-'])
        self.assertEqual(url, '/delete/dhaynes123_-')

133
    def test_registered_reverse(self):
David Haynes's avatar
David Haynes committed
134 135 136
        """
        /registered - registration complete page
        """
137 138
        url = reverse('registered')
        self.assertEqual(url, '/registered')
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
142 143

    def test_useradmin(self):
David Haynes's avatar
David Haynes committed
144
        """
145
        /manage - user approval interface
David Haynes's avatar
David Haynes committed
146
        """
David Haynes's avatar
David Haynes committed
147
        url = reverse('useradmin')
David Haynes's avatar
David Haynes committed
148
        self.assertEqual(url, '/manage')
149

150
    def test_login(self):
David Haynes's avatar
David Haynes committed
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
        """
        /logout - logout portal
        """
161 162
        url = reverse('go_logout')
        self.assertEqual(url, '/logout')
163

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
    # def test_delete_chars(self):
    #     """
    #     /<short> - Redirect to a go link.
    #     """
    #     url = reverse('redirection', args=['dhaynes'])
    #     self.assertEqual(url, '/dhaynes')

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

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

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