Exemplo n.º 1
0
 def test_comment(self, is_thread_author, thread_type, is_privileged):
     context = _get_context(
         requester_id="5",
         is_requester_privileged=is_privileged,
         thread=Thread(user_id="5" if is_thread_author else "6", thread_type=thread_type)
     )
     actual = get_initializable_comment_fields(context)
     expected = {
         "abuse_flagged", "parent_id", "raw_body", "thread_id", "voted"
     }
     if (is_thread_author and thread_type == "question") or is_privileged:
         expected |= {"endorsed"}
     self.assertEqual(actual, expected)
Exemplo n.º 2
0
 def test_comment(self, is_thread_author, thread_type, is_privileged):
     context = _get_context(requester_id="5",
                            is_requester_privileged=is_privileged,
                            thread=Thread(
                                user_id="5" if is_thread_author else "6",
                                thread_type=thread_type))
     actual = get_initializable_comment_fields(context)
     expected = {
         "abuse_flagged", "parent_id", "raw_body", "thread_id", "voted"
     }
     if (is_thread_author and thread_type == "question") or is_privileged:
         expected |= {"endorsed"}
     self.assertEqual(actual, expected)
Exemplo n.º 3
0
def _check_initializable_comment_fields(data, context):  # pylint: disable=invalid-name
    """
    Checks if the given data contains a comment 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 comment which
            includes the requesting user

    Raises:
        ValidationError if the given data contains a comment field that is not
            initializable by the requesting user
    """
    _check_fields(get_initializable_comment_fields(context), data, "This field is not initializable.")
Exemplo n.º 4
0
def _check_initializable_comment_fields(data, context):  # pylint: disable=invalid-name
    """
    Checks if the given data contains a comment 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 comment which
            includes the requesting user

    Raises:
        ValidationError if the given data contains a comment field that is not
            initializable by the requesting user
    """
    _check_fields(get_initializable_comment_fields(context), data,
                  "This field is not initializable.")