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
1f049410
Commit
1f049410
authored
Jan 29, 2013
by
Jay Zoldak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for django comment client utils
parent
e7450874
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
0 deletions
+90
-0
lms/djangoapps/django_comment_client/tests/test_utils.py
+89
-0
lms/djangoapps/django_comment_client/utils.py
+1
-0
No files found.
lms/djangoapps/django_comment_client/tests/test_utils.py
0 → 100644
View file @
1f049410
import
string
import
random
import
collections
from
django.test
import
TestCase
import
factory
from
django.contrib.auth.models
import
User
from
student.models
import
UserProfile
,
CourseEnrollment
from
django_comment_client.models
import
Role
,
Permission
import
django_comment_client.models
as
models
import
django_comment_client.utils
as
utils
import
xmodule.modulestore.django
as
django
class
UserFactory
(
factory
.
Factory
):
FACTORY_FOR
=
User
username
=
'robot'
password
=
'123456'
email
=
'robot@edx.org'
is_active
=
True
is_staff
=
False
class
CourseEnrollmentFactory
(
factory
.
Factory
):
FACTORY_FOR
=
CourseEnrollment
user
=
factory
.
SubFactory
(
UserFactory
)
course_id
=
'edX/toy/2012_Fall'
class
RoleFactory
(
factory
.
Factory
):
FACTORY_FOR
=
Role
name
=
'Student'
course_id
=
'edX/toy/2012_Fall'
class
PermissionFactory
(
factory
.
Factory
):
FACTORY_FOR
=
Permission
name
=
'create_comment'
class
DictionaryTestCase
(
TestCase
):
def
test_extract
(
self
):
d
=
{
'cats'
:
'meow'
,
'dogs'
:
'woof'
}
k
=
[
'cats'
,
'dogs'
,
'hamsters'
]
expected
=
{
'cats'
:
'meow'
,
'dogs'
:
'woof'
,
'hamsters'
:
None
}
self
.
assertEqual
(
utils
.
extract
(
d
,
k
),
expected
)
def
test_strip_none
(
self
):
d
=
{
'cats'
:
'meow'
,
'dogs'
:
'woof'
,
'hamsters'
:
None
}
expected
=
{
'cats'
:
'meow'
,
'dogs'
:
'woof'
}
self
.
assertEqual
(
utils
.
strip_none
(
d
),
expected
)
def
test_strip_blank
(
self
):
d
=
{
'cats'
:
'meow'
,
'dogs'
:
'woof'
,
'hamsters'
:
' '
,
'yetis'
:
''
}
expected
=
{
'cats'
:
'meow'
,
'dogs'
:
'woof'
}
self
.
assertEqual
(
utils
.
strip_blank
(
d
),
expected
)
def
test_merge_dict
(
self
):
d1
=
{
'cats'
:
'meow'
,
'dogs'
:
'woof'
}
d2
=
{
'lions'
:
'roar'
,
'ducks'
:
'quack'
}
expected
=
{
'cats'
:
'meow'
,
'dogs'
:
'woof'
,
'lions'
:
'roar'
,
'ducks'
:
'quack'
}
self
.
assertEqual
(
utils
.
merge_dict
(
d1
,
d2
),
expected
)
class
AccessUtilsTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
course_id
=
'edX/toy/2012_Fall'
self
.
student_role
=
RoleFactory
(
name
=
'Student'
,
course_id
=
self
.
course_id
)
self
.
moderator_role
=
RoleFactory
(
name
=
'Moderator'
,
course_id
=
self
.
course_id
)
self
.
student1
=
UserFactory
(
username
=
'student'
,
email
=
'student@edx.org'
)
self
.
student1_enrollment
=
CourseEnrollmentFactory
(
user
=
self
.
student1
)
self
.
student_role
.
users
.
add
(
self
.
student1
)
self
.
student2
=
UserFactory
(
username
=
'student2'
,
email
=
'student2@edx.org'
)
self
.
student2_enrollment
=
CourseEnrollmentFactory
(
user
=
self
.
student2
)
self
.
moderator
=
UserFactory
(
username
=
'moderator'
,
email
=
'staff@edx.org'
,
is_staff
=
True
)
self
.
moderator_enrollment
=
CourseEnrollmentFactory
(
user
=
self
.
moderator
)
self
.
moderator_role
.
users
.
add
(
self
.
moderator
)
def
test_get_role_ids
(
self
):
ret
=
utils
.
get_role_ids
(
self
.
course_id
)
expected
=
{
u'Moderator'
:
[
3
],
u'Student'
:
[
1
,
2
],
'Staff'
:
[
3
]}
self
.
assertEqual
(
ret
,
expected
)
def
test_has_forum_access
(
self
):
ret
=
utils
.
has_forum_access
(
'student'
,
self
.
course_id
,
'Student'
)
self
.
assertTrue
(
ret
)
ret
=
utils
.
has_forum_access
(
'not_a_student'
,
self
.
course_id
,
'Student'
)
self
.
assertFalse
(
ret
)
ret
=
utils
.
has_forum_access
(
'student'
,
self
.
course_id
,
'NotARole'
)
self
.
assertFalse
(
ret
)
lms/djangoapps/django_comment_client/utils.py
View file @
1f049410
...
...
@@ -35,6 +35,7 @@ def strip_blank(dic):
return
isinstance
(
v
,
str
)
and
len
(
v
.
strip
())
==
0
return
dict
([(
k
,
v
)
for
k
,
v
in
dic
.
iteritems
()
if
not
_is_blank
(
v
)])
# TODO should we be checking if d1 and d2 have the same keys with different values?
def
merge_dict
(
dic1
,
dic2
):
return
dict
(
dic1
.
items
()
+
dic2
.
items
())
...
...
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