Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enroll the coach in the CCX on creation #10251

Merged
merged 1 commit into from
Oct 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lms/djangoapps/ccx/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import pytz
import ddt
import urlparse
from mock import patch, MagicMock
from nose.plugins.attrib import attr

Expand All @@ -14,12 +15,13 @@
from courseware.tests.factories import StudentModuleFactory
from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tabs import get_course_tab_list
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse, resolve
from django.utils.timezone import UTC
from django.test.utils import override_settings
from django.test import RequestFactory
from edxmako.shortcuts import render_to_response
from request_cache.middleware import RequestCache
from opaque_keys.edx.keys import CourseKey
from student.roles import CourseCcxCoachRole
from student.models import (
CourseEnrollment,
Expand Down Expand Up @@ -200,7 +202,7 @@ def test_no_ccx_created(self):
self.make_coach()
url = reverse(
'ccx_coach_dashboard',
kwargs={'course_id': self.course.id.to_deprecated_string()})
kwargs={'course_id': unicode(self.course.id)})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTrue(re.search(
Expand All @@ -212,15 +214,26 @@ def test_create_ccx(self):
Create CCX. Follow redirect to coach dashboard, confirm we see
the coach dashboard for the new CCX.
"""

self.make_coach()
url = reverse(
'create_ccx',
kwargs={'course_id': self.course.id.to_deprecated_string()})
kwargs={'course_id': unicode(self.course.id)})

response = self.client.post(url, {'name': 'New CCX'})
self.assertEqual(response.status_code, 302)
url = response.get('location') # pylint: disable=no-member
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

# Get the ccx_key
path = urlparse.urlparse(url).path
resolver = resolve(path)
ccx_key = resolver.kwargs['course_id']

course_key = CourseKey.from_string(ccx_key)

self.assertTrue(CourseEnrollment.is_enrolled(self.coach, course_key))
self.assertTrue(re.search('id="ccx-schedule"', response.content))

@SharedModuleStoreTestCase.modifies_courseware
Expand Down
14 changes: 12 additions & 2 deletions lms/djangoapps/ccx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
unenroll_email,
get_email_params,
)

from .models import CustomCourseForEdX
from .overrides import (
get_override_for_ccx,
Expand All @@ -56,7 +55,6 @@
bulk_delete_ccx_override_fields,
)


log = logging.getLogger(__name__)
TODAY = datetime.datetime.today # for patching in tests

Expand Down Expand Up @@ -183,7 +181,19 @@ def create_ccx(request, course, ccx=None):
override_field_for_ccx(ccx, vertical, hidden, True)

ccx_id = CCXLocator.from_course_locator(course.id, ccx.id) # pylint: disable=no-member

url = reverse('ccx_coach_dashboard', kwargs={'course_id': ccx_id})

# Enroll the coach in the course
email_params = get_email_params(course, auto_enroll=True, course_key=ccx_id, display_name=ccx.display_name)
enroll_email(
course_id=ccx_id,
student_email=request.user.email,
auto_enroll=True,
email_students=True,
email_params=email_params,
)

return redirect(url)


Expand Down