Пример #1
0
 def test_thread(
     self,
     is_privileged,
     is_cohorted,
     allow_anonymous,
     allow_anonymous_to_peers,
 ):
     context = _get_context(
         requester_id="5",
         is_requester_privileged=is_privileged,
         is_cohorted=is_cohorted,
         allow_anonymous=allow_anonymous,
         allow_anonymous_to_peers=allow_anonymous_to_peers,
     )
     actual = get_initializable_thread_fields(context)
     expected = {
         "abuse_flagged", "course_id", "following", "raw_body", "read", "title", "topic_id", "type", "voted"
     }
     if is_privileged:
         expected |= {"closed", "pinned", "close_reason_code", "edit_reason_code"}
     if is_privileged and is_cohorted:
         expected |= {"group_id"}
     if allow_anonymous:
         expected |= {"anonymous"}
     if allow_anonymous_to_peers:
         expected |= {"anonymous_to_peers"}
     assert 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)
Пример #3
0
 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)
Пример #4
0
def _check_initializable_thread_fields(data, context):
    """
    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.")
Пример #5
0
def _check_initializable_thread_fields(data, context):
    """
    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."
    )