'Test set/update credit requirement status'

@ddt.data(*CourseMode.CREDIT_ELIGIBLE_MODES)
def test_set_credit_requirement_status(self, mode):

    username = self.user.username
    credit_course = self.add_credit_course()
    self.enroll(self.user, self.course_key, mode)
    self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key))
    self.assertTrue(CourseEnrollment.enrollment_mode_for_user(self.user, self.course_key), (mode, True))
    self._set_credit_course_requirements()
    self.assert_grade_requirement_status(None, 0)
    credit_request = CreditRequest.objects.create(course=credit_course, provider=CreditProvider.objects.first(), username=username)
    api.set_credit_requirement_status(self.user, self.course_key, 'grade', 'grade')
    self.assert_grade_requirement_status(None, 0)
    credit_request.delete()
    api.set_credit_requirement_status(self.user, self.course_key, 'grade', 'grade', status='failed')
    self.assert_grade_requirement_status('failed', 0)
    api.set_credit_requirement_status(self.user, self.course_key, 'grade', 'grade')
    self.assert_grade_requirement_status('satisfied', 0)
    req_status = api.get_credit_requirement_status(self.course_key, username)
    self.assertEqual(req_status[0]['status'], 'satisfied')
    self.assertEqual(req_status[0]['order'], 0)
    self.assertEqual(req_status[1]['status'], None)
    self.assertEqual(req_status[1]['order'], 1)
    api.set_credit_requirement_status(self.user, self.course_key, 'grade', 'other_grade', status='declined')
    req_status = api.get_credit_requirement_status(self.course_key, username, namespace='grade', name='other_grade')
    self.assertEqual(req_status[0]['status'], 'declined')
