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

@patch('ccx.views.render_to_response', intercept_renderer)
@patch('ccx.views.TODAY')
def test_edit_schedule(self, today):

    today.return_value = datetime.datetime(2014, 11, 25, tzinfo=pytz.UTC)
    self.make_coach()
    ccx = self.make_ccx()
    url = reverse('ccx_coach_dashboard', kwargs={'course_id': CCXLocator.from_course_locator(self.course.id, ccx.id)})
    response = self.client.get(url)
    schedule = json.loads(response.mako_context['schedule'])
    self.assertEqual(len(schedule), 2)
    self.assertEqual(schedule[0]['hidden'], False)
    self.assertEqual(schedule[0]['start'], self.chapters[0].start.strftime('%Y-%m-%d    %H:%M'))
    self.assertEqual(schedule[0]['children'][0]['start'], self.sequentials[0].start.strftime('%Y-%m-%d    %H:%M'))
    if self.sequentials[0].due:
        expected_due = self.sequentials[0].due.strftime('%Y-%m-%d    %H:%M')
    else:
        expected_due = None
    self.assertEqual(schedule[0]['children'][0]['due'], expected_due)
    url = reverse('save_ccx', kwargs={'course_id': CCXLocator.from_course_locator(self.course.id, ccx.id)})
    unhide(schedule[0])
    schedule[0]['start'] = u'2014-11-20    00:00'
    schedule[0]['children'][0]['due'] = u'2014-12-25    00:00'
    schedule[0]['children'][0]['children'][0]['start'] = u'2014-12-20    00:00'
    schedule[0]['children'][0]['children'][0]['due'] = u'2014-12-25    00:00'
    response = self.client.post(url, json.dumps(schedule), content_type='application/json')
    schedule = json.loads(response.content)['schedule']
    self.assertEqual(schedule[0]['hidden'], False)
    self.assertEqual(schedule[0]['start'], u'2014-11-20    00:00')
    self.assertEqual(schedule[0]['children'][0]['due'], u'2014-12-25    00:00')
    self.assertEqual(schedule[0]['children'][0]['children'][0]['due'], u'2014-12-25    00:00')
    self.assertEqual(schedule[0]['children'][0]['children'][0]['start'], u'2014-12-20    00:00')
    ccx = CustomCourseForEdX.objects.get()
    course_start = get_override_for_ccx(ccx, self.course, 'start')
    self.assertEqual(str(course_start)[:(-9)], self.chapters[0].start.strftime('%Y-%m-%d    %H:%M'))
    policy = get_override_for_ccx(ccx, self.course, 'grading_policy', self.course.grading_policy)
    self.assertEqual(policy['GRADER'][0]['type'], 'Homework')
    self.assertEqual(policy['GRADER'][0]['min_count'], 8)
    self.assertEqual(policy['GRADER'][1]['type'], 'Lab')
    self.assertEqual(policy['GRADER'][1]['min_count'], 0)
    self.assertEqual(policy['GRADER'][2]['type'], 'Midterm    Exam')
    self.assertEqual(policy['GRADER'][2]['min_count'], 0)
    self.assertEqual(policy['GRADER'][3]['type'], 'Final    Exam')
    self.assertEqual(policy['GRADER'][3]['min_count'], 0)
