'Specific test for successful patch of the course modules'

@ddt.data(*AUTH_ATTRS)
def test_patch_detail_modules(self, auth_attr):

    data = {'course_modules': self.master_course_chapters[0:1]}
    resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
    ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id)
    self.assertItemsEqual(ccx_from_db.structure, data['course_modules'])
    data = {'course_modules': []}
    resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
    ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id)
    self.assertItemsEqual(ccx_from_db.structure, [])
    data = {'course_modules': self.master_course_chapters}
    resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
    ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id)
    self.assertItemsEqual(ccx_from_db.structure, self.master_course_chapters)
    data = {'course_modules': None}
    resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
    ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id)
    self.assertEqual(ccx_from_db.structure, None)
    chapters = self.master_course_chapters[0:1]
    data = {'course_modules': (chapters * 3)}
    resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
    ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id)
    self.assertItemsEqual(ccx_from_db.structure, chapters)
