test_models.py 2.51 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
24
25
# standard library imports
from __future__ import absolute_import, print_function
# core django imports
from django.test import TestCase
from django.contrib.auth.models import User
# imports from your apps
from accounts.models import Student
from housing.models import Building, Floor, Room


class BuildingTest(TestCase):

    def setUp(self):
        global wilson
        global wilson_third
        global wilson_313

        wilson = Building.objects.create(name='Wilson', neighbourhood='sh', campus='ff')
        wilson_third = Floor.objects.create(building=wilson, number=3)
        wilson_313 = Room.objects.create(floor=wilson_third, number=313)

        wilson.save()
        wilson_third.save()
        wilson_313.save()

26
27
28
29
30
31
32
33
34
35
36
37
        harrison = Building.objects.create(name='Harrison', neighbourhood='sh', campus='ff')
        harrison_third = Floor.objects.create(building=harrison, number=3)
        harrison_313 = Room.objects.create(floor=harrison_third, number=313)

        global harrison
        global harrison_third
        global harrison_313

        harrison.save()
        harrison_third.save()
        harrison_313.save()

38
39
40
41
42
43
44
45
46
47
48
49
50
51
        gmason = User.objects.create_user(username='gmason',
                                          first_name='George',
                                          last_name='Mason',
                                          email='gmason@masonlive.gmu.edu',
                                          password='eagle_bank')

        global george

        george = Student.objects.create(user=gmason, room=wilson_313)

        george.save()

    def test_building_contains_room(self):
        self.assertTrue(wilson_313 in wilson)
52
        self.assertFalse(harrison_313 in wilson)
53
54
55

    def test_building_contains_floor(self):
        self.assertTrue(wilson_third in wilson)
56
        self.assertFalse(harrison_third in wilson)
57
58
59

    def test_building_contains_student(self):
        self.assertTrue(george in wilson)
60
        self.assertFalse(george in harrison)
61
62
63
64
65
66


class FloorTest(TestCase):

    def test_floor_contains_room(self):
        self.assertTrue(wilson_313 in wilson_third)
67
        self.assertFalse(harrison_313 in wilson_third)
68
69
70

    def test_floor_contains_student(self):
        self.assertTrue(george in wilson_third)
71
        self.assertFalse(george in harrison_third)
72
73
74
75
76
77


class RoomTest(TestCase):

    def test_room_contains_student(self):
        self.assertTrue(george in wilson_313)
78
        self.assertFalse(george in harrison_313)