test_models.py 6.2 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
        """
David Haynes's avatar
David Haynes committed
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
        """
David Haynes's avatar
David Haynes committed
98
99
100
101
102
103

        try:
            get_registered_user.save()
        except DataError as ex:
            print(ex)

104
105
106

    # blank=False is purely form validation related

107
    # description --------------------------------------------------------------
David Haynes's avatar
David Haynes committed
108

109
110
111
112
113
    def test_description_blank(self):
        """
            - add in description (blank)
        """

114
115
116
        get_user = User.objects.get(username='dhaynes')
        get_registered_user = RegisteredUser.objects.get(user=get_user)
        self.assertEqual(get_registered_user.description, "")
117
118
119

    def test_description_text(self):
        """
120
            - add in description (text)
121
122
        """

123
124
125
126
127
128
129
130
131
        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"
        )
132
133


134
    # registered ---------------------------------------------------------------
135

136
    # approved -----------------------------------------------------------------
137

138
    # blocked ------------------------------------------------------------------
139

140
    # __str__ ------------------------------------------------------------------
141
142
143
144
145

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

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


class URLTest(TestCase):
155
    """
156
        Test cases for the URL Model
157
    """
158

159
    # owner --------------------------------------------------------------------
160

161
    # date_created -------------------------------------------------------------
162

163
    # target -------------------------------------------------------------------
164

165
    # short --------------------------------------------------------------------
166

167
    # clicks -------------------------------------------------------------------
168

169
    # qrclicks -----------------------------------------------------------------
170

171
    # socialclicks -------------------------------------------------------------
172

173
    # expires ------------------------------------------------------------------
174

175
    # __str__ ------------------------------------------------------------------
176

177
    # generate_valid_short -----------------------------------------------------