Commit 9e4ea753 authored by Eyad Hasan's avatar Eyad Hasan

Merge branch 'amherst' of git.gmu.edu:srct/roomlist into issue83

parents bce545ad 2d7bf092
......@@ -25,14 +25,14 @@
<a href="{{ student.room.get_absolute_url }}">{{ student.room }}</a>
{% if same_floor %}
{% if has_flagged %}
<a href="{% url 'deleteConfirmation' student.slug my_flag.slug %}">
<a href="{% url 'deleteConfirmation' request.user.username student.user.username %}">
<small><span style="padding-left:15px" class="fa-stack fa-lg">
<i class="fa fa-flag fa-stack-1x"></i>
<i class="fa fa-ban fa-stack-2x text-danger"></i>
</span></small>
</a>
{% else %}
<a href="{% url 'createConfirmation' student.slug %}">
<a href="{% url 'createConfirmation' request.user.username student.user.username %}">
<i style="padding-left:15px" class="fa fa-flag"></i>
</a>
{% endif %}
......
This diff is collapsed.
# 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)
class SearchViewTest(RoomlistViewTest):
def test_search_ok(self):
client = self.client_login()
response = client.get(reverse('search'))
self.assertEqual(response.status_code, 200)
......@@ -38,10 +38,10 @@ urlpatterns = patterns('',
name='remove_social'),
# student confirmation pages
url(r'^student/(?P<student_slug>[\w-]+)/flag/$',
url(r'^student/(?P<confirmer_slug>[\w-]+)/flag/(?P<student_slug>[\w-]+)/$',
CreateConfirmation.as_view(), name='createConfirmation'),
# delete confirmation
url(r'^student/(?P<student_slug>[\w-]+)/flag/(?P<slug>[\w-]+)/$',
url(r'^student/(?P<confirmer_slug>[\w-]+)/flag/(?P<student_slug>[\w-]+)/remove/$',
DeleteConfirmation.as_view(), name='deleteConfirmation'),
)
......@@ -16,6 +16,7 @@ from django.conf import settings
from django.template.loader import get_template
from django.core.mail import EmailMultiAlternatives, get_connection
from django.template import Context
from django.core.exceptions import ObjectDoesNotExist
# third party imports
from braces.views import LoginRequiredMixin, FormValidMessageMixin
from cas.views import login as cas_login
......@@ -468,18 +469,19 @@ class CreateConfirmation(LoginRequiredMixin, CreateView):
def get(self, request, *args, **kwargs):
current_url = self.request.get_full_path()
# [u'', u'accounts', u'student', u'gmason', u'flag', u'']
url_uname = current_url.split('/')[3]
# [u'', u'accounts', u'student', u'gmason', u'flag', u'confirmer']
confirmer_uname = current_url.split('/')[3]
student_uname = current_url.split('/')[5]
confirmer = Student.objects.get(user=self.request.user)
student = Student.objects.get(slug=url_uname)
confirmer = Student.objects.get(user__username=confirmer_uname)
student = Student.objects.get(user__username=student_uname)
flags = Confirmation.objects.filter(confirmer=confirmer,
student=student).count()
# you can't flag yourself
if confirmer == student:
return HttpResponseForbidden()
raise Http404
# check that the confirmer is on the floor of the student
if not on_the_same_floor(student, confirmer):
......@@ -500,7 +502,7 @@ class CreateConfirmation(LoginRequiredMixin, CreateView):
# duplicated code
current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3]
url_uname = current_url.split('/')[5]
student = Student.objects.get(slug=url_uname)
......@@ -517,7 +519,7 @@ class CreateConfirmation(LoginRequiredMixin, CreateView):
# duplicated code
current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3]
url_uname = current_url.split('/')[5]
confirmer = Student.objects.get(user=self.request.user)
student = Student.objects.get(slug=url_uname)
......@@ -540,14 +542,29 @@ class DeleteConfirmation(LoginRequiredMixin, DeleteView):
login_url = 'login'
def get(self, request, *args, **kwargs):
requester = Student.objects.get(user=self.request.user)
confirmer = self.get_object().confirmer
requester = self.request.user.student
try:
confirmer = self.get_object().confirmer
except ObjectDoesNotExist:
raise Http404
if not(requester == confirmer):
return HttpResponseForbidden()
else:
return super(DeleteConfirmation, self).get(request, *args, **kwargs)
def get_object(self):
current_url = self.request.get_full_path()
# [u'', u'accounts', u'student', u'gmason', u'flag', u'confirmer', delete]
confirmer_uname = current_url.split('/')[3]
student_uname = current_url.split('/')[5]
confirmer = Student.objects.get(user__username=confirmer_uname)
student = Student.objects.get(user__username=student_uname)
confirmation = Confirmation.objects.get(confirmer=confirmer, student=student)
return confirmation
def get_success_url(self):
return reverse('detail_student',
kwargs={'slug': self.object.student.slug})
......@@ -8,71 +8,67 @@ from accounts.models import Student
from housing.models import Building, Floor, Room
class BuildingTest(TestCase):
class HousingTest(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)
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)
wilson.save()
wilson_third.save()
wilson_313.save()
self.wilson.save()
self.wilson_third.save()
self.wilson_313.save()
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)
self.harrison = Building.objects.create(name='Harrison', neighbourhood='sh',
campus='ff')
self.harrison_third = Floor.objects.create(building=self.harrison, number=3)
self.harrison_313 = Room.objects.create(floor=self.harrison_third, number=313)
global harrison
global harrison_third
global harrison_313
self.harrison.save()
self.harrison_third.save()
self.harrison_313.save()
harrison.save()
harrison_third.save()
harrison_313.save()
self.gmason = User.objects.create_user(username='gmason',
first_name='George',
last_name='Mason',
email='gmason@masonlive.gmu.edu',
password='eagle_bank')
gmason = User.objects.create_user(username='gmason',
first_name='George',
last_name='Mason',
email='gmason@masonlive.gmu.edu',
password='eagle_bank')
self.george = Student.objects.create(user=self.gmason, room=self.wilson_313)
global george
self.george.save()
george = Student.objects.create(user=gmason, room=wilson_313)
george.save()
class BuildingTest(HousingTest):
def test_building_contains_room(self):
self.assertTrue(wilson_313 in wilson)
self.assertFalse(harrison_313 in wilson)
self.assertTrue(self.wilson_313 in self.wilson)
self.assertFalse(self.harrison_313 in self.wilson)
def test_building_contains_floor(self):
self.assertTrue(wilson_third in wilson)
self.assertFalse(harrison_third in wilson)
self.assertTrue(self.wilson_third in self.wilson)
self.assertFalse(self.harrison_third in self.wilson)
def test_building_contains_student(self):
self.assertTrue(george in wilson)
self.assertFalse(george in harrison)
self.assertTrue(self.george in self.wilson)
self.assertFalse(self.george in self.harrison)
class FloorTest(TestCase):
class FloorTest(HousingTest):
def test_floor_contains_room(self):
self.assertTrue(wilson_313 in wilson_third)
self.assertFalse(harrison_313 in wilson_third)
self.assertTrue(self.wilson_313 in self.wilson_third)
self.assertFalse(self.harrison_313 in self.wilson_third)
def test_floor_contains_student(self):
self.assertTrue(george in wilson_third)
self.assertFalse(george in harrison_third)
self.assertTrue(self.george in self.wilson_third)
self.assertFalse(self.george in self.harrison_third)
class RoomTest(TestCase):
class RoomTest(HousingTest):
def test_room_contains_student(self):
self.assertTrue(george in wilson_313)
self.assertFalse(george in harrison_313)
self.assertTrue(self.george in self.wilson_313)
self.assertFalse(self.george in self.harrison_313)
......@@ -10,11 +10,11 @@ from housing.models import Building, Floor, Room
from accounts.models import Student
class HousingViewTest(TestCase):
class RoomlistViewTest(TestCase):
def setUp(self):
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_third = Floor.objects.create(building=wilson, number='3')
wilson_313 = Room.objects.create(floor=wilson_third, number='313')
wilson.save()
wilson_third.save()
......@@ -27,9 +27,16 @@ class HousingViewTest(TestCase):
password='eagle_bank')
# .create_user() includes .save()
gmason = Student.objects.create(user=user)
gmason = Student.objects.create(user=user, room=wilson_313)
gmason.save()
def client_login(self):
client = Client()
gmason = User.objects.get(username='gmason')
# this is only for testing purposes; we're using CAS for auth
client.login(username='gmason', password='eagle_bank')
return client
class ListBuildingsTest(TestCase):
......@@ -41,36 +48,29 @@ class ListBuildingsTest(TestCase):
self.assertEqual(response.status_code, 200)
class DetailBuildingTest(HousingViewTest):
class DetailBuildingTest(RoomlistViewTest):
def test_detail_building_ok(self):
client = Client()
gmason = User.objects.get(username='gmason')
# this is only for testing purposes; we're using CAS for auth
client.login(username='gmason', password='eagle_bank')
client = self.client_login()
response = client.get(reverse('detail_building',
kwargs = {'building': 'wilson'}))
self.assertEqual(response.status_code, 200)
class DetailFloorTest(HousingViewTest):
class DetailFloorTest(RoomlistViewTest):
def test_detail_floor_ok(self):
client = Client()
gmason = User.objects.get(username='gmason')
client.login(username='gmason', password='eagle_bank')
client = self.client_login()
response = client.get(reverse('detail_floor',
kwargs = {'building': 'wilson',
'floor': '3'}))
self.assertEqual(response.status_code, 200)
class DetailRoomTest(HousingViewTest):
class DetailRoomTest(RoomlistViewTest):
def test_detail_room_ok(self):
client = Client()
gmason = User.objects.get(username='gmason')
client.login(username='gmason', password='eagle_bank')
client = self.client_login()
response = client.get(reverse('detail_room',
kwargs = {'building': 'wilson',
'floor': '3',
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports
from django.test import SimpleTestCase, Client
from django.core.urlresolvers import reverse
# imports from your apps
from housing.test_views import RoomlistViewTest
class StaticLoadTest(SimpleTestCase):
def setUp(self):
self.client = Client()
def test_homepage_load(self):
response = self.client.get(reverse('homepage'))
self.assertEqual(response.status_code, 200)
def test_about_load(self):
response = self.client.get(reverse('about'))
self.assertEqual(response.status_code, 200)
def test_privacy_load(self):
response = self.client.get(reverse('privacy'))
self.assertEqual(response.status_code, 200)
class LandingTest(RoomlistViewTest):
def test_landing_ok(self):
client = self.client_login()
response = client.get(reverse('homepage'))
self.assertEqual(response.status_code, 200)
......@@ -3,8 +3,11 @@ from __future__ import absolute_import, print_function
from datetime import date
# core django imports
from django.test import TestCase
from django.core.urlresolvers import reverse
# imports from your apps
from welcome.views import get_semester
from housing.test_views import RoomlistViewTest
class GetSemesterTest(TestCase):
......@@ -22,3 +25,35 @@ class GetSemesterTest(TestCase):
created = date(month=1, day=1, year=2016) # New Years Day
semester = get_semester(created)
self.assertEqual(semester, 'Spring')
class WelcomeNameTest(RoomlistViewTest):
def test_welcome_name_ok(self):
client = self.client_login()
response = client.get(reverse('welcomeName'))
self.assertEqual(response.status_code, 200)
class WelcomePrivacyTest(RoomlistViewTest):
def test_welcome_privacy_ok(self):
client = self.client_login()
response = client.get(reverse('welcomePrivacy'))
self.assertEqual(response.status_code, 200)
class WelcomeMajorTest(RoomlistViewTest):
def test_welcome_major_ok(self):
client = self.client_login()
response = client.get(reverse('welcomeMajor'))
self.assertEqual(response.status_code, 200)
class WelcomeSocialTest(RoomlistViewTest):
def test_welcome_social_ok(self):
client = self.client_login()
response = client.get(reverse('welcomeSocial'))
self.assertEqual(response.status_code, 200)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment