Exemplo n.º 1
0
    def testUpdateUserCapsEntity(self):
        """Test that capital email address will be denormalized on update.
    """
        email = "*****@*****.**"
        account = users.User(email=email)
        name = 'Updated User'
        properties = {
            'account': account,
            'link_id': self.entity.link_id,
            'name': name,
        }
        user_logic.updateOrCreateFromFields(properties)
        entity = user_logic.getFromKeyName(self.entity.link_id)

        denormalized = accounts.denormalizeAccount(entity.account)
        self.failUnlessEqual(account.email().lower(), denormalized.email())
Exemplo n.º 2
0
  def testUpdateUserCapsEntity(self):
    """Test that capital email address will be denormalized on update.
    """
    email = "*****@*****.**"
    account = users.User(email=email)
    name = 'Updated User'
    properties = {
        'account': account,
        'link_id': self.entity.link_id,
        'name': name,
        }
    user_logic.updateOrCreateFromFields(properties)
    entity = user_logic.getFromKeyName(self.entity.link_id)

    denormalized = accounts.denormalizeAccount(entity.account)
    self.failUnlessEqual(account.email().lower(), denormalized.email())
Exemplo n.º 3
0
    def testUpdateUserNormalEntity(self):
        """Test that a user can be updated.
    """
        email = "*****@*****.**"
        account = users.User(email=email)
        name = 'Updated User'
        properties = {
            'account': account,
            'link_id': self.entity.link_id,
            'name': name,
        }
        user_logic.updateOrCreateFromFields(properties)
        entity = user_logic.getFromKeyName(self.entity.link_id)

        self.failUnlessEqual(account.email().lower(), email.lower())
        self.failUnlessEqual(account, entity.account)
        self.failUnlessEqual(name, entity.name)
Exemplo n.º 4
0
  def testUpdateUserNormalEntity(self):
    """Test that a user can be updated.
    """
    email = "*****@*****.**"
    account = users.User(email=email)
    name = 'Updated User'
    properties = {
        'account': account,
        'link_id': self.entity.link_id,
        'name': name,
        }
    user_logic.updateOrCreateFromFields(properties)
    entity = user_logic.getFromKeyName(self.entity.link_id)

    self.failUnlessEqual(account.email().lower(), email.lower())
    self.failUnlessEqual(account, entity.account)
    self.failUnlessEqual(name, entity.name)
Exemplo n.º 5
0
    def testUpdateUserInvalidUpdate(self):
        """Test that the ToS fields can't be changed once the user agreed ToS.
    """
        email = "*****@*****.**"
        account = users.User(email=email)
        name = 'Updated User'
        agreed_to_tos = False
        properties = {
            'account': account,
            'link_id': self.entity.link_id,
            'name': name,
            'agreed_to_tos': agreed_to_tos,
        }
        user_logic.updateOrCreateFromFields(properties)
        entity = user_logic.getFromKeyName(self.entity.link_id)

        self.failUnlessEqual(account.email().lower(), email.lower())
        self.failUnlessEqual(account, entity.account)
        self.failUnlessEqual(name, entity.name)
        self.failIfEqual(agreed_to_tos, entity.agreed_to_tos)
Exemplo n.º 6
0
  def testUpdateUserInvalidUpdate(self):
    """Test that the ToS fields can't be changed once the user agreed ToS.
    """
    email = "*****@*****.**"
    account = users.User(email=email)
    name = 'Updated User'
    agreed_to_tos = False
    properties = {
        'account': account,
        'link_id': self.entity.link_id,
        'name': name,
        'agreed_to_tos': agreed_to_tos,
        }
    user_logic.updateOrCreateFromFields(properties)
    entity = user_logic.getFromKeyName(self.entity.link_id)

    self.failUnlessEqual(account.email().lower(), email.lower())
    self.failUnlessEqual(account, entity.account)
    self.failUnlessEqual(name, entity.name)
    self.failIfEqual(agreed_to_tos, entity.agreed_to_tos)
Exemplo n.º 7
0
def addUniqueUserIds(job_entity):
    """Job that will add unique user id to a User.

  Args:
    job_entity: a Job entity with key_data set to [user_key]
  """

    from soc.cron.job import FatalJobError

    user_keyname = job_entity.key_data[0].name()
    user_entity = user_logic.getFromKeyName(user_keyname)

    if not user_entity:
        raise FatalJobError('The User with keyname %s does not exist!' %
                            (user_keyname))

    # add unique user id
    account, user_id = emailToAccountAndUserId(user_entity.account.email())
    user_entity.account = account
    user_entity.user_id = user_id
    user_entity.put()

    # we are done here
    return
Exemplo n.º 8
0
def addUniqueUserIds(job_entity):
  """Job that will add unique user id to a User.

  Args:
    job_entity: a Job entity with key_data set to [user_key]
  """

  from soc.cron.job import FatalJobError

  user_keyname = job_entity.key_data[0].name()
  user_entity = user_logic.getFromKeyName(user_keyname)

  if not user_entity:
    raise FatalJobError('The User with keyname %s does not exist!' % (
        user_keyname))

  # add unique user id
  account, user_id = emailToAccountAndUserId(user_entity.account.email())
  user_entity.account = account
  user_entity.user_id = user_id
  user_entity.put()
  
  # we are done here
  return
Exemplo n.º 9
0
def AddToFeedTask(request, *args, **kwargs):
  """ Creates a FeedItem entity pairing an event for a sender entity
  and one receiver entity
  
  Params:
    feed_item_key - key_name used for feed item 
    sender_key - key for the entity sending the event
    receivers - entities assigned to get item in their feed
    update_type - create, update, delete, etc.
    payload - optional payload message for this feed item
    user_key - key_name of user who made the update 
  """
  params = request.POST
  """
  if not params.get('user_key'):
    return error_handler.logErrorAndReturnOK(
        'no user specified for AddToFeedTask')
  """
  feed_item_key = params.get('feed_item_key')
  user_key = params.get('user_key', None)
  if user_key:
    acting_user = user_logic.getFromKeyName(user_key)
  else:
    acting_user = None
  sender_key = params.get('sender_key')
  if not sender_key:
    return error_handler.logErrorAndReturnOK(
        'no sender_key specified for AddToFeedTask')  
  receivers = [db.Key(key) for key in params.get(
               'receivers', '').split(',')]
  if not receivers:
    return error_handler.logErrorAndReturnOK(
        'no receivers specified for AddToFeedTask')

  update_type = params.get('update_type')
  if not update_type:
    return error_handler.logErrorAndReturnOK(
        'no update_type specified for AddToFeedTask')  
        
  # optional params
  payload = params.get('payload')
  
  # save item to datastore
  feed_item_properties = dict( 
  sender= db.Key(sender_key),
  receivers = receivers,
  update_type = update_type
  )
  
  if payload: 
    feed_item_properties['payload'] = payload

  if acting_user: 
    feed_item_properties['user'] = acting_user
    
  new_feed_item = news_feed_logic.updateOrCreateFromKeyName(
  feed_item_properties, feed_item_key)


  sender = db.get(sender_key)
  sendFeedItemEmailNotifications(sender, acting_user,
                                 update_type, payload, **kwargs)

  # send update ping for each receiver's feed
  receiver_entities = db.get(receivers)
  for receiver in receiver_entities:
    sendHubNotification(receiver)                  
  # task completed, return OK
  return http.HttpResponse('OK')