예제 #1
0
 def _test_current_user_for_user(self, user: BaseUser,
                                 expected_type: ThesisUserType):
     self.login_as(user)
     response = self.client.get(reverse("theses:current_user"))
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     data = response.data
     self.assertEqual(data["type"], expected_type.value)
     self.assertEqual(data["person"]["id"], user.pk)
     self.assertEqual(data["person"]["name"], user.get_full_name())
예제 #2
0
def get_theses_user_full_name(user: BaseUser):
    """Returns the full name of the user for use by the theses system.

    If the user is an Employee, `get_full_name_with_academic_title` will be used;
    otherwise, `get_full_name` will be used.

    Accepts a BaseUser instance because this is only called by the person serializer,
    and doing it this way is faster (no need to look up the employee/student instance
    via FK)
    """
    if isinstance(user, Employee):
        return user.get_full_name_with_academic_title()
    return user.get_full_name()