Example #1
0
    def testGetHostForUser(self):
        """Tests if a host entity for the user entity is returned.
    """
        #create an entity group. The entity at index i in the list is the parent of
        #the entity at index i+1.
        user_entities = []
        user_entities.append(seeder_logic.seed(User))
        for i in range(4):
            properties = {'parent': user_entities[i].key()}
            entity = seeder_logic.seed(User, properties)
            user_entities.append(entity)

        #create a Host entity with parent as an entity in user_entities
        properties = {'parent': user_entities[4]}
        host = seeder_logic.seed(Host, properties)

        #root entity
        expected = host.key()
        user_entity = user_entities[0]
        self.assertEqual(
            host_logic.getHostForUser(user_entity).key(), expected)

        #all entities in the ancestral path
        expected = host.key()
        for entity in user_entities:
            self.assertEqual(host_logic.getHostForUser(entity).key(), expected)

        #an entity not in the same entity group
        expected = None
        entity = seeder_logic.seed(User)
        self.assertEqual(host_logic.getHostForUser(entity), expected)
Example #2
0
  def hostFromKwargs(self):
    """Set the host entity for the given user in the kwargs.
    """
    self.data.host_user_key = None

    key_name = self.data.kwargs.get('link_id', '')
    if not key_name:
      self.host()
      if self.data.is_host:
        return
      else:
        raise NotFound(DEF_NO_LINK_ID)

    user_key = db.Key.from_path('User', key_name)

    if not user_key:
      raise NotFound(DEF_NO_USER % key_name)

    self.data.host_user_key = user_key
    self.data.host = host_logic.getHostForUser(user_key)
Example #3
0
  def host(self):
    assert isSet(self.data.user)

    self.data.host = host_logic.getHostForUser(self.data.user)
    if self.data.host or self.data.user.host_for:
      self.data.is_host = True