'Test for different methods for detail of a ccx course.
All check the validity of the ccx course id'

@ddt.data(('get', AUTH_ATTRS[0]), ('get', AUTH_ATTRS[1]), ('delete', AUTH_ATTRS[0]), ('delete', AUTH_ATTRS[1]), ('patch', AUTH_ATTRS[0]), ('patch', AUTH_ATTRS[1]))
@ddt.unpack
def test_detail_wrong_ccx(self, http_method, auth_attr):

    client_request = getattr(self.client, http_method)
    mock_class_str = 'openedx.core.lib.api.permissions.IsCourseStaffInstructor.has_object_permission'
    url = reverse('ccx_api:v0:ccx:detail', kwargs={'ccx_course_id': self.master_course_key_str})
    resp = client_request(url, {}, HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
    with mock.patch(mock_class_str, autospec=True) as mocked_perm_class:
        mocked_perm_class.return_value = True
        resp = client_request(url, {}, HTTP_AUTHORIZATION=getattr(self, auth_attr))
        self.expect_error(status.HTTP_400_BAD_REQUEST, 'course_id_not_valid_ccx_id', resp)
    url = reverse('ccx_api:v0:ccx:detail', kwargs={'ccx_course_id': 'ccx-v1:foo.0+course_bar_0+Run_0+ccx@1'})
    resp = client_request(url, {}, HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
    with mock.patch(mock_class_str, autospec=True) as mocked_perm_class:
        mocked_perm_class.return_value = True
        resp = client_request(url, {}, HTTP_AUTHORIZATION=getattr(self, auth_attr))
        self.expect_error(status.HTTP_404_NOT_FOUND, 'ccx_course_id_does_not_exist', resp)
    ccx_key_str = '{0}000000'.format(self.ccx_key_str)
    url = reverse('ccx_api:v0:ccx:detail', kwargs={'ccx_course_id': ccx_key_str})
    resp = client_request(url, {}, HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
    with mock.patch(mock_class_str, autospec=True) as mocked_perm_class:
        mocked_perm_class.return_value = True
        resp = client_request(url, {}, HTTP_AUTHORIZATION=getattr(self, auth_attr))
        self.expect_error(status.HTTP_404_NOT_FOUND, 'ccx_course_id_does_not_exist', resp)
