'Test for various post requests with wrong input data'

@ddt.data(({}, {'max_students_allowed': 'missing_field_max_students_allowed', 'display_name': 'missing_field_display_name', 'coach_email': 'missing_field_coach_email'}, 'auth'), ({}, {'max_students_allowed': 'missing_field_max_students_allowed', 'display_name': 'missing_field_display_name', 'coach_email': 'missing_field_coach_email'}, 'auth_header_oauth2_provider'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title'}, {'coach_email': 'missing_field_coach_email'}, 'auth'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title'}, {'coach_email': 'missing_field_coach_email'}, 'auth_header_oauth2_provider'), ({'max_students_allowed': None, 'display_name': None, 'coach_email': None}, {'max_students_allowed': 'null_field_max_students_allowed', 'display_name': 'null_field_display_name', 'coach_email': 'null_field_coach_email'}, 'auth'), ({'max_students_allowed': None, 'display_name': None, 'coach_email': None}, {'max_students_allowed': 'null_field_max_students_allowed', 'display_name': 'null_field_display_name', 'coach_email': 'null_field_coach_email'}, 'auth_header_oauth2_provider'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title', 'coach_email': 'this    is    not    an    email@test.com'}, {'coach_email': 'invalid_coach_email'}, 'auth'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title', 'coach_email': 'this    is    not    an    email@test.com'}, {'coach_email': 'invalid_coach_email'}, 'auth_header_oauth2_provider'), ({'max_students_allowed': 10, 'display_name': '', 'coach_email': 'email@test.com'}, {'display_name': 'invalid_display_name'}, 'auth'), ({'max_students_allowed': 10, 'display_name': '', 'coach_email': 'email@test.com'}, {'display_name': 'invalid_display_name'}, 'auth_header_oauth2_provider'), ({'max_students_allowed': 'a', 'display_name': 'CCX    Title', 'coach_email': 'email@test.com'}, {'max_students_allowed': 'invalid_max_students_allowed'}, 'auth'), ({'max_students_allowed': 'a', 'display_name': 'CCX    Title', 'coach_email': 'email@test.com'}, {'max_students_allowed': 'invalid_max_students_allowed'}, 'auth_header_oauth2_provider'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title', 'coach_email': 'email@test.com', 'course_modules': {'foo': 'bar'}}, {'course_modules': 'invalid_course_module_list'}, 'auth'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title', 'coach_email': 'email@test.com', 'course_modules': {'foo': 'bar'}}, {'course_modules': 'invalid_course_module_list'}, 'auth_header_oauth2_provider'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title', 'coach_email': 'email@test.com', 'course_modules': 'block-v1:org.0+course_0+Run_0+type@chapter+block@chapter_1'}, {'course_modules': 'invalid_course_module_list'}, 'auth'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title', 'coach_email': 'email@test.com', 'course_modules': 'block-v1:org.0+course_0+Run_0+type@chapter+block@chapter_1'}, {'course_modules': 'invalid_course_module_list'}, 'auth_header_oauth2_provider'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title', 'coach_email': 'email@test.com', 'course_modules': ['foo', 'bar']}, {'course_modules': 'invalid_course_module_keys'}, 'auth'), ({'max_students_allowed': 10, 'display_name': 'CCX    Title', 'coach_email': 'email@test.com', 'course_modules': ['foo', 'bar']}, {'course_modules': 'invalid_course_module_keys'}, 'auth_header_oauth2_provider'))
@ddt.unpack
def test_post_list_wrong_input_data(self, data, expected_errors, auth_attr):

    data['master_course_id'] = self.master_course_key_str
    resp = self.client.post(self.list_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr))
    self.expect_error_fields(expected_errors, resp)
