'Verify that program structures are flattened correctly.'

@ddt.data([ProgramFactory(courses=[CourseFactory(course_runs=[CourseRunFactory(key=course_run_key)])]), ProgramFactory(courses=[CourseFactory(course_runs=[CourseRunFactory(key=alternate_course_run_key)])])], [ProgramFactory(courses=[CourseFactory(course_runs=[CourseRunFactory(key=course_run_key)]), CourseFactory(course_runs=[CourseRunFactory(key=alternate_course_run_key)])])], [ProgramFactory(courses=[CourseFactory(course_runs=[CourseRunFactory(key=course_run_key), CourseRunFactory(key=alternate_course_run_key)])])])
def test_handle_flatten(self, data, mock_task, mock_get_programs):

    mock_get_programs.return_value = data
    GeneratedCertificateFactory(user=self.alice, course_id=self.course_run_key, mode=MODES.verified, status=CertificateStatuses.downloadable)
    GeneratedCertificateFactory(user=self.bob, course_id=self.alternate_course_run_key, mode=MODES.verified, status=CertificateStatuses.downloadable)
    call_command('backpopulate_program_credentials', commit=True)
    calls = [mock.call(self.alice.username), mock.call(self.bob.username)]
    mock_task.assert_has_calls(calls, any_order=True)
