Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
roomlist
Commits
9e4ea753
Commit
9e4ea753
authored
Oct 23, 2016
by
Eyad Hasan
Browse files
Merge branch 'amherst' of git.gmu.edu:srct/roomlist into issue83
parents
bce545ad
2d7bf092
Changes
9
Show whitespace changes
Inline
Side-by-side
roomlist/accounts/templates/detailStudent.html
View file @
9e4ea753
...
...
@@ -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 %}
...
...
roomlist/accounts/test_models.py
View file @
9e4ea753
...
...
@@ -21,62 +21,61 @@ class MajorTest(TestCase):
class
StudentTest
(
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_307
=
Room
.
objects
.
create
(
floor
=
wilson_third
,
number
=
307
)
wilson_first
=
Floor
.
objects
.
create
(
building
=
wilson
,
number
=
1
)
wilson_102
=
Room
.
objects
.
create
(
floor
=
wilson_first
,
number
=
102
)
wilson
.
save
()
wilson_third
.
save
()
wilson_313
.
save
()
wilson_307
.
save
()
wilson_first
.
save
()
wilson_102
.
save
()
harrison
=
Building
.
objects
.
create
(
name
=
'Harrison'
,
neighbourhood
=
'sh'
,
campus
=
'ff'
)
harrison_second
=
Floor
.
objects
.
create
(
building
=
harrison
,
number
=
2
)
harrison_207
=
Room
.
objects
.
create
(
floor
=
harrison_second
,
number
=
207
)
harrison
.
save
()
harrison_second
.
save
()
harrison_207
.
save
()
gmason
=
User
.
objects
.
create_user
(
username
=
'gmason'
,
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'
)
tjefferson
=
User
.
objects
.
create_user
(
username
=
'tjefferson'
,
self
.
tjefferson
=
User
.
objects
.
create_user
(
username
=
'tjefferson'
,
first_name
=
'Thomas'
,
last_name
=
'Jefferson'
,
email
=
'tjefferson@masonlive.gmu.edu'
,
password
=
'louisiana'
)
dmadison
=
User
.
objects
.
create_user
(
username
=
'dmadison'
,
self
.
dmadison
=
User
.
objects
.
create_user
(
username
=
'dmadison'
,
# note lack of first or last name!
email
=
'dmadison@masonlive.gmu.edu'
,
password
=
'white_house'
)
jtyler
=
User
.
objects
.
create_user
(
username
=
'jtyler'
,
self
.
jtyler
=
User
.
objects
.
create_user
(
username
=
'jtyler'
,
first_name
=
'John'
,
last_name
=
'Tyler'
,
email
=
'jtyler@masonlive.gmu.edu'
,
password
=
'canhaztexas'
)
hclinton
=
User
.
objects
.
create_user
(
username
=
'hclinton'
,
self
.
hclinton
=
User
.
objects
.
create_user
(
username
=
'hclinton'
,
first_name
=
'Hillary'
,
last_name
=
'Clinton'
,
email
=
'hildawg@mytotallynotsketchysite.biz'
,
password
=
''
)
spalin
=
User
.
objects
.
create_user
(
username
=
'spalin'
,
self
.
spalin
=
User
.
objects
.
create_user
(
username
=
'spalin'
,
first_name
=
'Sarah'
,
last_name
=
'Palin'
,
email
=
'grizzlymama@mccain08.com'
,
password
=
'youbetcha'
)
cfiorina
=
User
.
objects
.
create_user
(
username
=
'cfiorina'
,
self
.
cfiorina
=
User
.
objects
.
create_user
(
username
=
'cfiorina'
,
first_name
=
'Carly'
,
last_name
=
'Fiorina'
,
email
=
'carly@hp.com'
,
...
...
@@ -84,170 +83,169 @@ class StudentTest(TestCase):
# create_user includes .save()
global
george
global
dolley
global
thomas
global
sarah
global
hillary
global
john
global
carly
george
=
Student
.
objects
.
create
(
user
=
gmason
,
room
=
wilson_313
,
privacy
=
u
'floor'
)
thomas
=
Student
.
objects
.
create
(
user
=
tjefferson
,
room
=
wilson_313
,
privacy
=
u
'building'
)
dolley
=
Student
.
objects
.
create
(
user
=
dmadison
,
room
=
harrison_207
,
privacy
=
u
'floor'
)
sarah
=
Student
.
objects
.
create
(
user
=
spalin
,
room
=
wilson_307
,
privacy
=
u
'building'
)
hillary
=
Student
.
objects
.
create
(
user
=
hclinton
,
room
=
wilson_102
,
privacy
=
u
'students'
)
john
=
Student
.
objects
.
create
(
user
=
jtyler
,
room
=
wilson_313
,
privacy
=
u
'students'
)
carly
=
Student
.
objects
.
create
(
user
=
cfiorina
,
privacy
=
u
'students'
)
# note lack of room!
george
.
save
()
thomas
.
save
()
dolley
.
save
()
sarah
.
save
()
hillary
.
save
()
john
.
save
()
carly
.
save
()
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
()
def
test_recent_changes
(
self
):
self
.
assertEqual
(
george
.
recent_changes
(),
0
)
self
.
assertEqual
(
self
.
george
.
recent_changes
(),
0
)
def
test_totally_done
(
self
):
# one assert per test?
self
.
assertEqual
(
george
.
totally_done
(),
False
)
george
.
completedName
=
True
self
.
assertEqual
(
george
.
totally_done
(),
False
)
george
.
completedPrivacy
=
True
self
.
assertEqual
(
george
.
totally_done
(),
False
)
george
.
completedMajor
=
True
self
.
assertEqual
(
george
.
totally_done
(),
False
)
george
.
completedSocial
=
True
self
.
assertEqual
(
george
.
totally_done
(),
True
)
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
)
def
test_get_flag_count
(
self
):
self
.
assertEqual
(
george
.
get_flag_count
(),
0
)
self
.
assertEqual
(
self
.
george
.
get_flag_count
(),
0
)
def
test_get_first_name_or_uname
(
self
):
self
.
assertEqual
(
george
.
get_first_name_or_uname
(),
'George'
)
self
.
assertEqual
(
dolley
.
get_first_name_or_uname
(),
'dmadison'
)
self
.
assertEqual
(
self
.
george
.
get_first_name_or_uname
(),
'George'
)
self
.
assertEqual
(
self
.
dolley
.
get_first_name_or_uname
(),
'dmadison'
)
def
test_get_last_name_or_uname
(
self
):
self
.
assertEqual
(
george
.
get_last_name_or_uname
(),
'Mason'
)
self
.
assertEqual
(
dolley
.
get_last_name_or_uname
(),
'dmadison'
)
self
.
assertEqual
(
self
.
george
.
get_last_name_or_uname
(),
'Mason'
)
self
.
assertEqual
(
self
.
dolley
.
get_last_name_or_uname
(),
'dmadison'
)
def
test_get_full_name_or_uname
(
self
):
self
.
assertEqual
(
george
.
get_full_name_or_uname
(),
'George Mason'
)
self
.
assertEqual
(
dolley
.
get_full_name_or_uname
(),
'dmadison'
)
self
.
assertEqual
(
self
.
george
.
get_full_name_or_uname
(),
'George Mason'
)
self
.
assertEqual
(
self
.
dolley
.
get_full_name_or_uname
(),
'dmadison'
)
def
test_qset_floor
(
self
):
students
=
Student
.
objects
.
all
().
floor
()
self
.
assertEqual
(
len
(
students
),
2
)
self
.
assertTrue
(
george
in
students
)
self
.
assertTrue
(
dolley
in
students
)
self
.
assertTrue
(
self
.
george
in
students
)
self
.
assertTrue
(
self
.
dolley
in
students
)
def
test_qset_building
(
self
):
students
=
Student
.
objects
.
all
().
building
()
self
.
assertEqual
(
len
(
students
),
2
)
self
.
assertTrue
(
thomas
in
students
)
self
.
assertTrue
(
sarah
in
students
)
self
.
assertTrue
(
self
.
thomas
in
students
)
self
.
assertTrue
(
self
.
sarah
in
students
)
def
test_qset_students
(
self
):
students
=
Student
.
objects
.
all
().
students
()
self
.
assertEqual
(
len
(
students
),
3
)
self
.
assertTrue
(
hillary
in
students
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
carly
in
students
)
self
.
assertTrue
(
self
.
hillary
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
self
.
assertTrue
(
self
.
carly
in
students
)
def
test_qset_building_students
(
self
):
students
=
Student
.
objects
.
all
().
building_students
()
self
.
assertEqual
(
len
(
students
),
5
)
self
.
assertTrue
(
thomas
in
students
)
self
.
assertTrue
(
sarah
in
students
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
hillary
in
students
)
self
.
assertTrue
(
carly
in
students
)
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
)
def
test_qset_floor_building_students
(
self
):
students
=
Student
.
objects
.
all
().
floor_building_students
()
self
.
assertEqual
(
len
(
students
),
7
)
self
.
assertTrue
(
george
in
students
)
self
.
assertTrue
(
dolley
in
students
)
self
.
assertTrue
(
thomas
in
students
)
self
.
assertTrue
(
sarah
in
students
)
self
.
assertTrue
(
hillary
in
students
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
carly
in
students
)
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
)
def
test_visible_room_same_room
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
george
,
housing
=
wilson_313
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
george
,
housing
=
self
.
wilson_313
)
self
.
assertEqual
(
len
(
students
),
3
)
self
.
assertTrue
(
george
in
students
)
# george's privacy is floor
self
.
assertTrue
(
thomas
in
students
)
# thomas's privacy is building
self
.
assertTrue
(
john
in
students
)
# john's privacy is students
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
def
test_visible_room_same_floor
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
sarah
,
housing
=
wilson_313
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
sarah
,
housing
=
self
.
wilson_313
)
self
.
assertEqual
(
len
(
students
),
3
)
self
.
assertTrue
(
george
in
students
)
self
.
assertTrue
(
thomas
in
students
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
self
.
george
in
students
)
self
.
assertTrue
(
self
.
thomas
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
def
test_visible_room_different_floor_same_building
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
hillary
,
housing
=
wilson_313
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
hillary
,
housing
=
self
.
wilson_313
)
self
.
assertEqual
(
len
(
students
),
2
)
self
.
assertTrue
(
thomas
in
students
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
self
.
thomas
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
def
test_visible_room_different_building
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
dolley
,
housing
=
wilson_313
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
dolley
,
housing
=
self
.
wilson_313
)
self
.
assertEqual
(
len
(
students
),
1
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
def
test_visible_floor_same_floor
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
sarah
,
housing
=
wilson_third
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
sarah
,
housing
=
self
.
wilson_third
)
self
.
assertEqual
(
len
(
students
),
4
)
self
.
assertTrue
(
george
in
students
)
self
.
assertTrue
(
thomas
in
students
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
sarah
in
students
)
self
.
assertTrue
(
self
.
george
in
students
)
self
.
assertTrue
(
self
.
thomas
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
self
.
assertTrue
(
self
.
sarah
in
students
)
def
test_visible_floor_different_floor_same_building
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
hillary
,
housing
=
wilson_third
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
hillary
,
housing
=
self
.
wilson_third
)
self
.
assertEqual
(
len
(
students
),
3
)
self
.
assertTrue
(
thomas
in
students
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
sarah
in
students
)
self
.
assertTrue
(
self
.
thomas
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
self
.
assertTrue
(
self
.
sarah
in
students
)
def
test_visible_floor_different_building
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
dolley
,
housing
=
wilson_third
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
dolley
,
housing
=
self
.
wilson_third
)
self
.
assertEqual
(
len
(
students
),
1
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
def
test_visible_building_same_building
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
hillary
,
housing
=
wilson
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
hillary
,
housing
=
self
.
wilson
)
self
.
assertEqual
(
len
(
students
),
4
)
self
.
assertTrue
(
thomas
in
students
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
sarah
in
students
)
self
.
assertTrue
(
hillary
in
students
)
self
.
assertTrue
(
self
.
thomas
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
self
.
assertTrue
(
self
.
sarah
in
students
)
self
.
assertTrue
(
self
.
hillary
in
students
)
def
test_visible_building_different_building
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
dolley
,
housing
=
wilson
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
dolley
,
housing
=
self
.
wilson
)
self
.
assertEqual
(
len
(
students
),
2
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
hillary
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
self
.
assertTrue
(
self
.
hillary
in
students
)
def
test_visible_none_room
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
carly
,
housing
=
wilson_313
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
carly
,
housing
=
self
.
wilson_313
)
self
.
assertEqual
(
len
(
students
),
1
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
def
test_visible_none_floor
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
carly
,
housing
=
wilson_third
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
carly
,
housing
=
self
.
wilson_third
)
self
.
assertEqual
(
len
(
students
),
1
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
def
test_visible_none_building
(
self
):
students
=
Student
.
objects
.
visible
(
student
=
carly
,
housing
=
wilson
)
students
=
Student
.
objects
.
visible
(
student
=
self
.
carly
,
housing
=
self
.
wilson
)
self
.
assertEqual
(
len
(
students
),
2
)
self
.
assertTrue
(
john
in
students
)
self
.
assertTrue
(
hillary
in
students
)
self
.
assertTrue
(
self
.
john
in
students
)
self
.
assertTrue
(
self
.
hillary
in
students
)
roomlist/accounts/test_views.py
0 → 100644
View file @
9e4ea753
# 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
)
roomlist/accounts/urls.py
View file @
9e4ea753
...
...
@@ -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'
),
)
roomlist/accounts/views.py
View file @
9e4ea753
...
...
@@ -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
:
r
eturn
HttpResponseForbidden
()
r
aise
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
)