test_views.py 4.71 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# standard library imports
from __future__ import absolute_import, print_function
# core django imports
from django.test import TestCase
from django.test import Client
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
# imports from your apps
from .models import Student, Major, Confirmation
from housing.models import Room, Floor
from housing.test_views import RoomlistViewTest


class ListMajorsTest(RoomlistViewTest):

    def test_list_majors_ok(self):
        client = Client()
        response = client.get(reverse('list_majors'))
        self.assertEqual(response.status_code, 200)


class DetailMajorTest(RoomlistViewTest):

    def setUp(self):
        major = Major.objects.create(name='Government and International Politics, BA')
        major.save()
        return super(DetailMajorTest, self).setUp()

    def test_list_majors_ok(self):
        client = self.client_login()
        response = client.get(reverse('detail_major',
                                      kwargs={'slug': 'government-and-international-politics-ba'}))
        self.assertEqual(response.status_code, 200)


class DetailStudentTest(RoomlistViewTest):

    def test_detail_student_ok(self):
        client = self.client_login()
        response = client.get(reverse('detail_student',
                                      kwargs={'slug': 'gmason'}))
        self.assertEqual(response.status_code, 200)


class UpdateStudentTest(RoomlistViewTest):

    def test_update_student_ok(self):
        client = self.client_login()
        response = client.get(reverse('update_student',
                                      kwargs={'slug': 'gmason'}))
        self.assertEqual(response.status_code, 200)


class DeleteStudentTest(RoomlistViewTest):

    def test_delete_student_ok(self):
        client = self.client_login()
        response = client.get(reverse('delete_student',
                                      kwargs={'slug': 'gmason'}))
        self.assertEqual(response.status_code, 200)


class RemoveSocialConfirmationTest(RoomlistViewTest):

    def test_remove_social_redirect(self):
        client = self.client_login()
        response = client.get(reverse('remove_social',
                                      kwargs={'slug': 'gmason'}))
        # student does not have any social media acounts set
        self.assertEqual(response.status_code, 302)


class ConfirmationViewTest(RoomlistViewTest):

    def setUp(self):
        # 'extending' the method
        setUp = super(ConfirmationViewTest, self).setUp()

        wilson_third = Floor.objects.get(building__name='Wilson', number='3')
        wilson_307 = Room.objects.create(floor=wilson_third, number='307')
        tjefferson = User.objects.create_user(username='tjefferson',
                                              first_name='Thomas',
                                              last_name='Jefferson',
                                              email='tjefferson@masonlive.gmu.edu',
                                              password='louisiana')
        thomas = Student.objects.create(user=tjefferson, room=wilson_307)


class CreateConfirmationTest(ConfirmationViewTest):

    def test_create_confirmation_self(self):
        client = self.client_login()
        response = client.get(reverse('createConfirmation',
                                      kwargs={'confirmer_slug': 'gmason',
                                              'student_slug': 'gmason'}))
        self.assertEqual(response.status_code, 404)

    def test_create_confirmation_same_floor(self):
        client = self.client_login()
        response = client.get(reverse('createConfirmation',
                                      kwargs={'confirmer_slug': 'tjefferson',
                                              'student_slug': 'gmason'}))
        self.assertEqual(response.status_code, 200)


class DeleteConfirmationTest(ConfirmationViewTest):

    def setUp(self):
        setUp = super(DeleteConfirmationTest, self).setUp()

        thomas = Student.objects.get(user__username='tjefferson')
        george = Student.objects.get(user__username='gmason')
        confirmation = Confirmation.objects.create(confirmer=george, student=thomas)
        confirmation.save()

    def test_delete_confirmation_ok(self):
        client = self.client_login()
        response = client.get(reverse('deleteConfirmation',
                                      kwargs={'confirmer_slug': 'gmason',
                                              'student_slug': 'tjefferson'}))
        self.assertEqual(response.status_code, 200)
Daniel W Bond's avatar
Daniel W Bond committed
122
123
124
125
126
127
128
129


class SearchViewTest(RoomlistViewTest):

    def test_search_ok(self):
        client = self.client_login()
        response = client.get(reverse('search'))
        self.assertEqual(response.status_code, 200)