def test_thread(self, is_privileged, is_cohorted): context = _get_context(requester_id="5", is_requester_privileged=is_privileged, is_cohorted=is_cohorted) actual = get_initializable_thread_fields(context) expected = { "abuse_flagged", "course_id", "following", "raw_body", "read", "title", "topic_id", "type", "voted" } if is_privileged and is_cohorted: expected |= {"group_id"} self.assertEqual(actual, expected)
def test_thread(self, is_privileged, is_cohorted): context = _get_context( requester_id="5", is_requester_privileged=is_privileged, is_cohorted=is_cohorted ) actual = get_initializable_thread_fields(context) expected = { "abuse_flagged", "course_id", "following", "raw_body", "read", "title", "topic_id", "type", "voted" } if is_privileged and is_cohorted: expected |= {"group_id"} self.assertEqual(actual, expected)
def _check_initializable_thread_fields(data, context): # pylint: disable=invalid-name """ Checks if the given data contains a thread field that is not initializable by the requesting user Arguments: data (dict): The data to compare the allowed_fields against context (dict): The context appropriate for use with the thread which includes the requesting user Raises: ValidationError if the given data contains a thread field that is not initializable by the requesting user """ _check_fields(get_initializable_thread_fields(context), data, "This field is not initializable.")