def testGetHotlistRoleName(self):
    hotlist = features_pb2.Hotlist()
    hotlist.owner_ids.append(111L)
    hotlist.editor_ids.append(222L)
    hotlist.follower_ids.append(333L)

    self.assertEquals(None, framework_helpers.GetHotlistRoleName(
        set(), hotlist))

    self.assertEquals(
        'Owner', framework_helpers.GetHotlistRoleName({111L}, hotlist))
    self.assertEquals(
        'Editor', framework_helpers.GetHotlistRoleName({222L}, hotlist))
    self.assertEquals(
        'Follower', framework_helpers.GetHotlistRoleName({333L}, hotlist))

    self.assertEquals(
        'Owner',
        framework_helpers.GetHotlistRoleName({111L, 222L, 999L}, hotlist))
    self.assertEquals(
        'Editor',
        framework_helpers.GetHotlistRoleName({222L, 333L, 999L}, hotlist))
    self.assertEquals(
        'Follower',
        framework_helpers.GetHotlistRoleName({333L, 999L}, hotlist))
Ejemplo n.º 2
0
    def __init__(self,
                 logged_in_user_id,
                 member_id,
                 user_view,
                 hotlist,
                 effective_ids=None):
        """Initialize a MemberView with the given information.

    Args:
      logged_in_user_id: int user ID of the viewing user, or 0 for anon.
      member_id: int user ID of the hotlist member being viewed.
      user_ivew: UserView object for this member
      hotlist: Hotlist PB for the currently viewed hotlist
      effective_ids: optional set of user IDs for this user, if supplied
          we show the highest role that they have via any group membership.
    """

        self.viewing_self = ezt.boolean(logged_in_user_id == member_id)

        self.user = user_view
        member_qs_param = user_view.user_id
        self.detail_url = '/u/%s/' % member_qs_param
        self.role = framework_helpers.GetHotlistRoleName(
            effective_ids or {member_id}, hotlist)