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
3488083e
Commit
3488083e
authored
Jan 19, 2013
by
Victor Shnayder
Committed by
Victor Shnayder
Jan 24, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a get_course_cohorts function and test
parent
90a57034
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
7 deletions
+43
-7
common/djangoapps/course_groups/models.py
+15
-2
common/djangoapps/course_groups/tests/tests.py
+28
-5
No files found.
common/djangoapps/course_groups/models.py
View file @
3488083e
...
@@ -40,9 +40,9 @@ def get_cohort(user, course_id):
...
@@ -40,9 +40,9 @@ def get_cohort(user, course_id):
Returns:
Returns:
A CourseUserGroup object if the User has a cohort, or None.
A CourseUserGroup object if the User has a cohort, or None.
"""
"""
group_type
=
CourseUserGroup
.
COHORT
try
:
try
:
group
=
CourseUserGroup
.
objects
.
get
(
course_id
=
course_id
,
group_type
=
group_type
,
group
=
CourseUserGroup
.
objects
.
get
(
course_id
=
course_id
,
group_type
=
CourseUserGroup
.
COHORT
,
users__id
=
user
.
id
)
users__id
=
user
.
id
)
except
CourseUserGroup
.
DoesNotExist
:
except
CourseUserGroup
.
DoesNotExist
:
group
=
None
group
=
None
...
@@ -52,3 +52,16 @@ def get_cohort(user, course_id):
...
@@ -52,3 +52,16 @@ def get_cohort(user, course_id):
# TODO: add auto-cohorting logic here
# TODO: add auto-cohorting logic here
return
None
return
None
def
get_course_cohorts
(
course_id
):
"""
Get a list of all the cohorts in the given course.
Arguments:
course_id: string in the format 'org/course/run'
Returns:
A list of CourseUserGroup objects. Empty if there are no cohorts.
"""
return
list
(
CourseUserGroup
.
objects
.
filter
(
course_id
=
course_id
,
group_type
=
CourseUserGroup
.
COHORT
))
common/djangoapps/course_groups/tests/tests.py
View file @
3488083e
import
django.test
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
nose.tools
import
assert_equals
from
course_groups.models
import
CourseUserGroup
,
get_cohort
from
course_groups.models
import
CourseUserGroup
,
get_cohort
,
get_course_cohorts
def
test_get_cohort
():
class
TestCohorts
(
django
.
test
.
TestCase
):
def
test_get_cohort
(
self
):
course_id
=
"a/b/c"
course_id
=
"a/b/c"
cohort
=
CourseUserGroup
.
objects
.
create
(
name
=
"TestCohort"
,
course_id
=
course_id
,
cohort
=
CourseUserGroup
.
objects
.
create
(
name
=
"TestCohort"
,
course_id
=
course_id
,
group_type
=
CourseUserGroup
.
COHORT
)
group_type
=
CourseUserGroup
.
COHORT
)
...
@@ -14,8 +16,29 @@ def test_get_cohort():
...
@@ -14,8 +16,29 @@ def test_get_cohort():
cohort
.
users
.
add
(
user
)
cohort
.
users
.
add
(
user
)
got
=
get_cohort
(
user
,
course_id
)
got
=
get_cohort
(
user
,
course_id
)
assert_e
quals
(
got
.
id
,
cohort
.
id
,
"Should find the right cohort"
)
self
.
assertE
quals
(
got
.
id
,
cohort
.
id
,
"Should find the right cohort"
)
got
=
get_cohort
(
other_user
,
course_id
)
got
=
get_cohort
(
other_user
,
course_id
)
assert_equals
(
got
,
None
,
"other_user shouldn't have a cohort"
)
self
.
assertEquals
(
got
,
None
,
"other_user shouldn't have a cohort"
)
def
test_get_course_cohorts
(
self
):
course1_id
=
"a/b/c"
course2_id
=
"e/f/g"
# add some cohorts to course 1
cohort
=
CourseUserGroup
.
objects
.
create
(
name
=
"TestCohort"
,
course_id
=
course1_id
,
group_type
=
CourseUserGroup
.
COHORT
)
cohort
=
CourseUserGroup
.
objects
.
create
(
name
=
"TestCohort2"
,
course_id
=
course1_id
,
group_type
=
CourseUserGroup
.
COHORT
)
# second course should have no cohorts
self
.
assertEqual
(
get_course_cohorts
(
course2_id
),
[])
cohorts
=
sorted
([
c
.
name
for
c
in
get_course_cohorts
(
course1_id
)])
self
.
assertEqual
(
cohorts
,
[
'TestCohort'
,
'TestCohort2'
])
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