test_models.py 11.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# standard library imports
from __future__ import absolute_import, print_function
# core django imports
from django.test import Client, TestCase
from django.contrib.auth.models import User
# imports from your apps
from accounts.models import Student, Major
from housing.models import Building, Floor, Room


class MajorTest(TestCase):

    def setUp(self):
        Major.objects.create(name='Government and International Politics, BA')

    def test_major_first_letter(self):
        govt = Major.objects.get(name='Government and International Politics, BA')
        self.assertEqual(govt.first_letter(), 'G')


class StudentTest(TestCase):

    def setUp(self):
24
25
26
27
28
29
30
31
32
33
34
35
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82

        self.wilson = Building.objects.create(name='Wilson', neighbourhood='sh',
                                              campus='ff')
        self.wilson_third = Floor.objects.create(building=self.wilson, number=3)
        self.wilson_313 = Room.objects.create(floor=self.wilson_third, number=313)
        self.wilson_307 = Room.objects.create(floor=self.wilson_third, number=307)
        self.wilson_first = Floor.objects.create(building=self.wilson, number=1)
        self.wilson_102 = Room.objects.create(floor=self.wilson_first, number=102)

        self.wilson.save()
        self.wilson_third.save()
        self.wilson_313.save()
        self.wilson_307.save()
        self.wilson_first.save()
        self.wilson_102.save()

        self.harrison = Building.objects.create(name='Harrison', neighbourhood='sh',
                                                campus='ff')
        self.harrison_second = Floor.objects.create(building=self.harrison, number=2)
        self.harrison_207 = Room.objects.create(floor=self.harrison_second, number=207)

        self.harrison.save()
        self.harrison_second.save()
        self.harrison_207.save()

        self.gmason = User.objects.create_user(username='gmason',
                                              first_name='George',
                                              last_name='Mason',
                                              email='gmason@masonlive.gmu.edu',
                                              password='eagle_bank')
        self.tjefferson = User.objects.create_user(username='tjefferson',
                                                   first_name='Thomas',
                                                   last_name='Jefferson',
                                                   email='tjefferson@masonlive.gmu.edu',
                                                   password='louisiana')
        self.dmadison = User.objects.create_user(username='dmadison',
                                                 # note lack of first or last name!
                                                 email='dmadison@masonlive.gmu.edu',
                                                 password='white_house')
        self.jtyler = User.objects.create_user(username='jtyler',
                                               first_name='John',
                                               last_name='Tyler',
                                               email='jtyler@masonlive.gmu.edu',
                                               password='canhaztexas')
        self.hclinton = User.objects.create_user(username='hclinton',
                                                 first_name='Hillary',
                                                 last_name='Clinton',
                                                 email='hildawg@mytotallynotsketchysite.biz',
                                                 password='')
        self.spalin = User.objects.create_user(username='spalin',
                                               first_name='Sarah',
                                               last_name='Palin',
                                               email='grizzlymama@mccain08.com',
                                               password='youbetcha')
        self.cfiorina = User.objects.create_user(username='cfiorina',
                                                 first_name='Carly',
                                                 last_name='Fiorina',
                                                 email='carly@hp.com',
                                                 password='lookatthisface')
83
84
85

        # create_user includes .save()

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
        self.george = Student.objects.create(user=self.gmason, room=self.wilson_313,
                                             privacy=u'floor')
        self.thomas = Student.objects.create(user=self.tjefferson, room=self.wilson_313,
                                             privacy=u'building')
        self.dolley = Student.objects.create(user=self.dmadison, room=self.harrison_207,
                                             privacy=u'floor')
        self.sarah = Student.objects.create(user=self.spalin, room=self.wilson_307,
                                            privacy=u'building')
        self.hillary = Student.objects.create(user=self.hclinton, room=self.wilson_102,
                                              privacy=u'students')
        self.john = Student.objects.create(user=self.jtyler, room=self.wilson_313,
                                           privacy=u'students')
        self.carly = Student.objects.create(user=self.cfiorina,
                                            privacy=u'students')  # note lack of room!

        self.george.save()
        self.thomas.save()
        self.dolley.save()
        self.sarah.save()
        self.hillary.save()
        self.john.save()
        self.carly.save()
108
109

    def test_recent_changes(self):
110
        self.assertEqual(self.george.recent_changes(), 0)
111
112
113

    def test_totally_done(self):
        # one assert per test?
114
115
116
117
118
119
120
121
122
        self.assertEqual(self.george.totally_done(), False)
        self.george.completedName = True
        self.assertEqual(self.george.totally_done(), False)
        self.george.completedPrivacy = True
        self.assertEqual(self.george.totally_done(), False)
        self.george.completedMajor = True
        self.assertEqual(self.george.totally_done(), False)
        self.george.completedSocial = True
        self.assertEqual(self.george.totally_done(), True)
123
124

    def test_get_flag_count(self):
125
        self.assertEqual(self.george.get_flag_count(), 0)
126
127

    def test_get_first_name_or_uname(self):
128
129
        self.assertEqual(self.george.get_first_name_or_uname(), 'George')
        self.assertEqual(self.dolley.get_first_name_or_uname(), 'dmadison')
130
131

    def test_get_last_name_or_uname(self):
132
133
        self.assertEqual(self.george.get_last_name_or_uname(), 'Mason')
        self.assertEqual(self.dolley.get_last_name_or_uname(), 'dmadison')
134
135

    def test_get_full_name_or_uname(self):
136
137
        self.assertEqual(self.george.get_full_name_or_uname(), 'George Mason')
        self.assertEqual(self.dolley.get_full_name_or_uname(), 'dmadison')
138
139
140
141

    def test_qset_floor(self):
        students = Student.objects.all().floor()
        self.assertEqual(len(students), 2)
142
143
        self.assertTrue(self.george in students)
        self.assertTrue(self.dolley in students)
144
145
146
147

    def test_qset_building(self):
        students = Student.objects.all().building()
        self.assertEqual(len(students), 2)
148
149
        self.assertTrue(self.thomas in students)
        self.assertTrue(self.sarah in students)
150
151
152
153

    def test_qset_students(self):
        students = Student.objects.all().students()
        self.assertEqual(len(students), 3)
154
155
156
        self.assertTrue(self.hillary in students)
        self.assertTrue(self.john in students)
        self.assertTrue(self.carly in students)
157
158
159
160

    def test_qset_building_students(self):
        students = Student.objects.all().building_students()
        self.assertEqual(len(students), 5)
161
162
163
164
165
        self.assertTrue(self.thomas in students)
        self.assertTrue(self.sarah in students)
        self.assertTrue(self.john in students)
        self.assertTrue(self.hillary in students)
        self.assertTrue(self.carly in students)
166
167
168
169

    def test_qset_floor_building_students(self):
        students = Student.objects.all().floor_building_students()
        self.assertEqual(len(students), 7)
170
171
172
173
174
175
176
        self.assertTrue(self.george in students)
        self.assertTrue(self.dolley in students)
        self.assertTrue(self.thomas in students)
        self.assertTrue(self.sarah in students)
        self.assertTrue(self.hillary in students)
        self.assertTrue(self.john in students)
        self.assertTrue(self.carly in students)
177
178

    def test_visible_room_same_room(self):
179
        students = Student.objects.visible(student=self.george, housing=self.wilson_313)
180
        self.assertEqual(len(students), 3)
181
182
183
        self.assertTrue(self.george in students)  # george's privacy is floor
        self.assertTrue(self.thomas in students)  # thomas's privacy is building
        self.assertTrue(self.john in students)  # john's privacy is students
184
185

    def test_visible_room_same_floor(self):
186
        students = Student.objects.visible(student=self.sarah, housing=self.wilson_313)
187
        self.assertEqual(len(students), 3)
188
189
190
        self.assertTrue(self.george in students)
        self.assertTrue(self.thomas in students)
        self.assertTrue(self.john in students)
191
192

    def test_visible_room_different_floor_same_building(self):
193
        students = Student.objects.visible(student=self.hillary, housing=self.wilson_313)
194
        self.assertEqual(len(students), 2)
195
196
        self.assertTrue(self.thomas in students)
        self.assertTrue(self.john in students)
197
198

    def test_visible_room_different_building(self):
199
        students = Student.objects.visible(student=self.dolley, housing=self.wilson_313)
200
        self.assertEqual(len(students), 1)
201
        self.assertTrue(self.john in students)
202
203

    def test_visible_floor_same_floor(self):
204
        students = Student.objects.visible(student=self.sarah, housing=self.wilson_third)
205
        self.assertEqual(len(students), 4)
206
207
208
209
        self.assertTrue(self.george in students)
        self.assertTrue(self.thomas in students)
        self.assertTrue(self.john in students)
        self.assertTrue(self.sarah in students)
210
211

    def test_visible_floor_different_floor_same_building(self):
212
        students = Student.objects.visible(student=self.hillary, housing=self.wilson_third)
213
        self.assertEqual(len(students), 3)
214
215
216
        self.assertTrue(self.thomas in students)
        self.assertTrue(self.john in students)
        self.assertTrue(self.sarah in students)
217
218

    def test_visible_floor_different_building(self):
219
        students = Student.objects.visible(student=self.dolley, housing=self.wilson_third)
220
        self.assertEqual(len(students), 1)
221
        self.assertTrue(self.john in students)
222
223

    def test_visible_building_same_building(self):
224
        students = Student.objects.visible(student=self.hillary, housing=self.wilson)
225
        self.assertEqual(len(students), 4)
226
227
228
229
        self.assertTrue(self.thomas in students)
        self.assertTrue(self.john in students)
        self.assertTrue(self.sarah in students)
        self.assertTrue(self.hillary in students)
230
231

    def test_visible_building_different_building(self):
232
        students = Student.objects.visible(student=self.dolley, housing=self.wilson)
233
        self.assertEqual(len(students), 2)
234
235
        self.assertTrue(self.john in students)
        self.assertTrue(self.hillary in students)
236
237

    def test_visible_none_room(self):
238
        students = Student.objects.visible(student=self.carly, housing=self.wilson_313)
239
        self.assertEqual(len(students), 1)
240
        self.assertTrue(self.john in students)
241
242

    def test_visible_none_floor(self):
243
        students = Student.objects.visible(student=self.carly, housing=self.wilson_third)
244
        self.assertEqual(len(students), 1)
245
        self.assertTrue(self.john in students)
246
247

    def test_visible_none_building(self):
248
        students = Student.objects.visible(student=self.carly, housing=self.wilson)
249
        self.assertEqual(len(students), 2)
250
251
        self.assertTrue(self.john in students)
        self.assertTrue(self.hillary in students)