'Test correctness of the endorsed_by field.
The endorser should be anonymous iff the thread is anonymous to the
requester, and the endorser is not a privileged user.
endorser_role_name is the name of the endorser\'s role.
thread_anonymous is the value of the anonymous field in the thread.'

@ddt.data(*itertools.product([FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_STUDENT], [True, False]))
@ddt.unpack
def test_endorsed_by(self, endorser_role_name, thread_anonymous):

    self.create_role(endorser_role_name, [self.endorser])
    serialized = self.serialize(self.make_cs_content(with_endorsement=True), thread_data={'anonymous': thread_anonymous})
    actual_endorser_anonymous = (serialized['endorsed_by'] is None)
    expected_endorser_anonymous = ((endorser_role_name == FORUM_ROLE_STUDENT) and thread_anonymous)
    self.assertEqual(actual_endorser_anonymous, expected_endorser_anonymous)
