Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e1b99186
Commit
e1b99186
authored
Mar 06, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed test_permissions.py
parent
2f5ea630
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
130 deletions
+0
-130
lms/djangoapps/django_comment_client/tests/test_permissions.py
+0
-130
No files found.
lms/djangoapps/django_comment_client/tests/test_permissions.py
deleted
100644 → 0
View file @
2f5ea630
import
string
import
random
import
collections
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
import
django_comment_client.models
as
models
import
student.models
import
django_comment_client.permissions
as
permissions
###############################################################################
class
PermissionsTestCase
(
TestCase
):
def
random_str
(
self
,
length
=
15
,
chars
=
string
.
ascii_uppercase
+
string
.
digits
):
return
''
.
join
(
random
.
choice
(
chars
)
for
x
in
range
(
length
))
def
setUp
(
self
):
self
.
course_id
=
"edX/toy/2012_Fall"
self
.
moderator_role
=
models
.
Role
.
objects
.
get_or_create
(
name
=
"Moderator"
,
course_id
=
self
.
course_id
)[
0
]
self
.
student_role
=
models
.
Role
.
objects
.
get_or_create
(
name
=
"Student"
,
course_id
=
self
.
course_id
)[
0
]
self
.
student
=
User
.
objects
.
create
(
username
=
self
.
random_str
(),
password
=
"123456"
,
email
=
"john@yahoo.com"
)
self
.
moderator
=
User
.
objects
.
create
(
username
=
self
.
random_str
(),
password
=
"123456"
,
email
=
"staff@edx.org"
)
self
.
moderator
.
is_staff
=
True
self
.
moderator
.
save
()
self
.
student_enrollment
=
student
.
models
.
CourseEnrollment
.
objects
.
create
(
user
=
self
.
student
,
course_id
=
self
.
course_id
)
self
.
moderator_enrollment
=
student
.
models
.
CourseEnrollment
.
objects
.
create
(
user
=
self
.
moderator
,
course_id
=
self
.
course_id
)
#Fake json files
self
.
empty_data
=
{
"content"
:
{
}
}
self
.
open_data
=
{
"content"
:
{
"closed"
:
False
,
"user_id"
:
str
(
self
.
student
.
id
)
}
}
self
.
closed_data
=
{
"content"
:
{
"closed"
:
True
,
"user_id"
:
str
(
self
.
student
.
id
)
}
}
def
tearDown
(
self
):
self
.
student_enrollment
.
delete
()
self
.
moderator_enrollment
.
delete
()
# Do we need to have this? We shouldn't be deleting students, ever
# self.student.delete()
# self.moderator.delete()
def
testDefaultRoles
(
self
):
self
.
assertTrue
(
self
.
student_role
in
self
.
student
.
roles
.
all
())
self
.
assertTrue
(
self
.
moderator_role
in
self
.
moderator
.
roles
.
all
())
def
testPermission
(
self
):
name
=
self
.
random_str
()
self
.
moderator_role
.
add_permission
(
name
)
self
.
assertTrue
(
permissions
.
has_permission
(
self
.
moderator
,
name
,
self
.
course_id
))
# Moderators do not have student priveleges unless explicitly added
self
.
student_role
.
add_permission
(
name
)
self
.
assertTrue
(
permissions
.
has_permission
(
self
.
student
,
name
,
self
.
course_id
))
# Students don't have moderator priveleges
name2
=
self
.
random_str
()
self
.
student_role
.
add_permission
(
name2
)
self
.
assertFalse
(
permissions
.
has_permission
(
self
.
moderator
,
name2
,
self
.
course_id
))
def
testCachedPermission
(
self
):
# Cache miss returns None
# Don't really understand how this works? What's in Cache?
self
.
assertFalse
(
permissions
.
cached_has_permission
(
self
.
student
,
self
.
moderator
,
course_id
=
None
))
self
.
assertFalse
(
permissions
.
cached_has_permission
(
self
.
student
,
"update_thread"
,
course_id
=
None
))
def
testCheckCondition
(
self
):
# Checks whether something? is open, or whether the author is user
self
.
assertFalse
(
permissions
.
check_condition
(
self
.
student
,
'is_open'
,
self
.
course_id
,
self
.
empty_data
))
self
.
assertFalse
(
permissions
.
check_condition
(
self
.
student
,
'is_author'
,
self
.
course_id
,
self
.
empty_data
))
self
.
assertTrue
(
permissions
.
check_condition
(
self
.
student
,
'is_open'
,
self
.
course_id
,
self
.
open_data
))
self
.
assertTrue
(
permissions
.
check_condition
(
self
.
student
,
'is_author'
,
self
.
course_id
,
self
.
open_data
))
self
.
assertFalse
(
permissions
.
check_condition
(
self
.
student
,
'is_open'
,
self
.
course_id
,
self
.
closed_data
))
def
testCheckConditionsPermissions
(
self
):
#Function does not seem to return True
self
.
assertFalse
(
permissions
.
check_conditions_permissions
(
self
.
student
,
'is_open'
,
self
.
course_id
,
data
=
self
.
open_data
))
self
.
assertFalse
(
permissions
.
check_conditions_permissions
(
self
.
student
,
'is_open'
,
self
.
course_id
,
data
=
self
.
empty_data
))
self
.
assertFalse
(
permissions
.
check_conditions_permissions
(
self
.
student
,
[
'is_open'
,
'is_author'
],
self
.
course_id
,
data
=
self
.
open_data
))
self
.
assertFalse
(
permissions
.
check_conditions_permissions
(
self
.
student
,
[
'is_open'
,
'is_author'
],
self
.
course_id
,
data
=
self
.
open_data
,
operator
=
'and'
))
self
.
assertFalse
(
permissions
.
check_conditions_permissions
(
self
.
student
,
'update_thread'
,
self
.
course_id
,
data
=
self
.
open_data
))
def
testCheckPermissionsByView
(
self
):
# kwargs is the data entered in check_condition, which is json?
self
.
assertRaises
(
UnboundLocalError
,
permissions
.
check_permissions_by_view
,
self
.
student
,
self
.
course_id
,
self
.
empty_data
,
"nonexistant"
)
self
.
assertFalse
(
permissions
.
check_permissions_by_view
(
self
.
student
,
self
.
course_id
,
self
.
empty_data
,
'update_thread'
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment