'Simulate the entirety of a user\'s progress through a program.'

@mock.patch((UTILS_MODULE + '.ProgramProgressMeter.completed_course_runs'), new_callable=mock.PropertyMock)
def test_simulate_progress(self, mock_completed_course_runs, mock_get_programs):

    (first_course_run_key, second_course_run_key) = (generate_course_run_key() for __ in range(2))
    data = [ProgramFactory(courses=[CourseFactory(course_runs=[CourseRunFactory(key=first_course_run_key)]), CourseFactory(course_runs=[CourseRunFactory(key=second_course_run_key)])]), ProgramFactory()]
    mock_get_programs.return_value = data
    meter = ProgramProgressMeter(self.site, self.user)
    self._assert_progress(meter)
    self.assertEqual(meter.completed_programs, [])
    self._create_enrollments(first_course_run_key)
    meter = ProgramProgressMeter(self.site, self.user)
    (program, program_uuid) = (data[0], data[0]['uuid'])
    self._assert_progress(meter, ProgressFactory(uuid=program_uuid, in_progress=1, not_started=1))
    self.assertEqual(meter.completed_programs, [])
    self._create_enrollments(second_course_run_key)
    meter = ProgramProgressMeter(self.site, self.user)
    self._assert_progress(meter, ProgressFactory(uuid=program_uuid, in_progress=2))
    self.assertEqual(meter.completed_programs, [])
    mock_completed_course_runs.return_value = [{'course_run_id': first_course_run_key, 'type': MODES.verified}]
    meter = ProgramProgressMeter(self.site, self.user)
    self._assert_progress(meter, ProgressFactory(uuid=program_uuid, completed=1, in_progress=1))
    self.assertEqual(meter.completed_programs, [])
    mock_completed_course_runs.return_value = [{'course_run_id': first_course_run_key, 'type': MODES.verified}, {'course_run_id': second_course_run_key, 'type': MODES.honor}]
    meter = ProgramProgressMeter(self.site, self.user)
    self._assert_progress(meter, ProgressFactory(uuid=program_uuid, completed=1, in_progress=1))
    self.assertEqual(meter.completed_programs, [])
    mock_completed_course_runs.return_value = [{'course_run_id': first_course_run_key, 'type': MODES.verified}, {'course_run_id': second_course_run_key, 'type': MODES.verified}]
    meter = ProgramProgressMeter(self.site, self.user)
    self._assert_progress(meter, ProgressFactory(uuid=program_uuid, completed=2))
    self.assertEqual(meter.completed_programs, [program_uuid])
