test_models.py 6.22 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
David Haynes's avatar
David Haynes committed
7

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

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

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

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

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

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

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

35
    # full_name ----------------------------------------------------------------
36

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
65
66
67
68
    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
        """
        # MYSQL will truncate the long string, no errors
        self.assertFalse((bool)(get_registered_user.save()))

    # 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
98
99
100
101
102
    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
        """
        # MYSQL will truncate the long string, no errors
        self.assertFalse((bool)(get_registered_user.save()))

    # blank=False is purely form validation related

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

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

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

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

119
120
121
122
123
124
125
126
127
        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"
        )
128
129


130
    # registered ---------------------------------------------------------------
131

132
    # approved -----------------------------------------------------------------
133

134
    # blocked ------------------------------------------------------------------
135

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

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

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


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

155
    # owner --------------------------------------------------------------------
156

157
    # date_created -------------------------------------------------------------
158

159
    # target -------------------------------------------------------------------
160

161
    # short --------------------------------------------------------------------
162

163
    # clicks -------------------------------------------------------------------
164

165
    # qrclicks -----------------------------------------------------------------
166

167
    # socialclicks -------------------------------------------------------------
168

169
    # expires ------------------------------------------------------------------
170

171
    # __str__ ------------------------------------------------------------------
172

173
    # generate_valid_short -----------------------------------------------------