test_models.py 6.15 KB
Newer Older
1
2
3
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division

David Haynes's avatar
David Haynes committed
4
# Django Imports
David Haynes's avatar
David Haynes committed
5
from django.test import TestCase
6
from django.contrib.auth.models import User
7
from django.db.utils import DataError
David Haynes's avatar
David Haynes committed
8

David Haynes's avatar
David Haynes committed
9
10
# App Imports
from go.models import URL, RegisteredUser
David Haynes's avatar
David Haynes committed
11

David Haynes's avatar
David Haynes committed
12
class RegisteredUserTest(TestCase):
13
14
15
    """
        Test cases for the RegisteredUser Model
    """
David Haynes's avatar
David Haynes committed
16

17
    def setUp(self):
18
19
20
21
22
        """
            Set up any variables such as dummy objects that will be utilised in
            testing methods
        """

23
        User.objects.create(username='dhaynes', password='password')
24
25

    # user ---------------------------------------------------------------------
26
27
28
29
30
31

    def test_registereduser_creation(self):
        """
            check if RegisteredUsers are actually made
        """

32
33
34
        get_user = User.objects.get(username='dhaynes')
        get_registered_user = RegisteredUser.objects.get(user=get_user)
        self.assertTrue(get_registered_user)
35

36
    # full_name ----------------------------------------------------------------
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    def test_full_name(self):
        """
            check if full_name char field functions as intentioned
        """

        get_user = User.objects.get(username='dhaynes')
        get_registered_user = RegisteredUser.objects.get(user=get_user)
        get_registered_user.full_name = "David Haynes"
        get_registered_user.save()

        self.assertEqual(get_registered_user.full_name, "David Haynes")

    def test_full_name_length(self):
        """
            check if full_name char field functions as intentioned
        """

        get_user = User.objects.get(username='dhaynes')
        get_registered_user = RegisteredUser.objects.get(user=get_user)
        get_registered_user.full_name = """
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        """
65
        self.assertRaises(DataError, get_registered_user.save())
66
67
68

    # blank=False is purely form validation related

69
    # organization -------------------------------------------------------------
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    def test_organization(self):
        """
            check if organization char field functions as intentioned
        """

        get_user = User.objects.get(username='dhaynes')
        get_registered_user = RegisteredUser.objects.get(user=get_user)
        get_registered_user.organization = "SRCT"
        get_registered_user.save()

        self.assertEqual(get_registered_user.organization, "SRCT")

    def test_organization_length(self):
        """
            check if organization char field functions as intentioned
        """

        get_user = User.objects.get(username='dhaynes')
        get_registered_user = RegisteredUser.objects.get(user=get_user)
        get_registered_user.organization = """
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
        """
98
        self.assertRaises(DataError, get_registered_user.save())
99
100
101

    # blank=False is purely form validation related

102
    # description --------------------------------------------------------------
David Haynes's avatar
David Haynes committed
103

104
105
106
107
108
    def test_description_blank(self):
        """
            - add in description (blank)
        """

109
110
111
        get_user = User.objects.get(username='dhaynes')
        get_registered_user = RegisteredUser.objects.get(user=get_user)
        self.assertEqual(get_registered_user.description, "")
112
113
114

    def test_description_text(self):
        """
115
            - add in description (text)
116
117
        """

118
119
120
121
122
123
124
125
126
        get_user = User.objects.get(username='dhaynes')
        get_registered_user = RegisteredUser.objects.get(user=get_user)
        get_registered_user.description = "We're going to build a big beautiful testcase"
        get_registered_user.save()

        self.assertEqual(
            get_registered_user.description,
            "We're going to build a big beautiful testcase"
        )
127
128


129
    # registered ---------------------------------------------------------------
130

131
    # approved -----------------------------------------------------------------
132

133
    # blocked ------------------------------------------------------------------
134

135
    # __str__ ------------------------------------------------------------------
136
137
138
139
140

    def test_check_str(self):
        """
            check printing
        """
141

142
143
        get_user = User.objects.get(username='dhaynes')
        get_registered_user = RegisteredUser.objects.get(user=get_user)
144
        expected = '<Registered User: dhaynes - Approval Status: False>'
145
        actual = str(get_registered_user)
146
147
148
149
        self.assertEqual(expected, actual)


class URLTest(TestCase):
150
    """
151
        Test cases for the URL Model
152
    """
153

154
    # owner --------------------------------------------------------------------
155

156
    # date_created -------------------------------------------------------------
157

158
    # target -------------------------------------------------------------------
159

160
    # short --------------------------------------------------------------------
161

162
    # clicks -------------------------------------------------------------------
163

164
    # qrclicks -----------------------------------------------------------------
165

166
    # socialclicks -------------------------------------------------------------
167

168
    # expires ------------------------------------------------------------------
169

170
    # __str__ ------------------------------------------------------------------
171

172
    # generate_valid_short -----------------------------------------------------