'Get CCX schedule, modify it, save it.'

@patch('ccx.views.render_to_response', intercept_renderer)
@patch('courseware.views.views.render_to_response', intercept_renderer)
@patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True})
def test_edit_schedule(self):

    self.make_coach()
    ccx = self.make_ccx()
    ccx_course_key = CCXLocator.from_course_locator(self.course.id, unicode(ccx.id))
    self.client.login(username=self.coach.username, password='test')
    url = reverse('ccx_coach_dashboard', kwargs={'course_id': ccx_course_key})
    response = self.client.get(url)
    schedule = json.loads(response.mako_context['schedule'])
    self.assertEqual(len(schedule), 1)
    unhide(schedule[0])
    date = (datetime.datetime.now() - datetime.timedelta(days=5))
    start = date.strftime('%Y-%m-%d    %H:%M')
    due = (date + datetime.timedelta(days=3)).strftime('%Y-%m-%d    %H:%M')
    schedule[0]['start'] = start
    schedule[0]['children'][0]['start'] = start
    schedule[0]['children'][0]['due'] = due
    schedule[0]['children'][0]['children'][0]['start'] = start
    schedule[0]['children'][0]['children'][0]['due'] = due
    url = reverse('save_ccx', kwargs={'course_id': ccx_course_key})
    response = self.client.post(url, json.dumps(schedule), content_type='application/json')
    self.assertEqual(response.status_code, 200)
    schedule = json.loads(response.content)['schedule']
    self.assertEqual(schedule[0]['hidden'], False)
    self.assertEqual(schedule[0]['start'], start)
    self.assertEqual(schedule[0]['children'][0]['start'], start)
    self.assertEqual(schedule[0]['children'][0]['due'], due)
    self.assertEqual(schedule[0]['children'][0]['children'][0]['due'], due)
    self.assertEqual(schedule[0]['children'][0]['children'][0]['start'], start)
    self.assert_progress_summary(ccx_course_key, due)
