Beispiel #1
0
def create_widget_for_account_by_email(widget_name, email):
  """
  Creates a new widget for the account, will return widget object if success, else it will return None
  """
  new_widget = None
  property_name = None
  if widget_name == "TrophyCase":
    new_widget = TrophyCase(key_name=email)
    property_name = "trophyWidget"
  elif widget_name == "Rank":
    new_widget = Rank(key_name=email)
    property_name = "rankWidget"
  elif widget_name == "Points":
    new_widget = Points(key_name=email)
    property_name = "pointsWidget"
  elif widget_name == "Notifier":
    new_widget = Notifier(key_name=email)
    property_name = "notifierWidget"
  elif widget_name == "Milestones":
    new_widget = Milestones(key_name=email)
    property_name = "milestoneWidget"
  elif widget_name == "Leaderboard":
    new_widget = Leaderboard(key_name=email)
    property_name = "leaderWidget"
    
  if new_widget!= None:
    memcache_db.save_entity(new_widget, email)
    update_fields = { property_name : new_widget }
    memcache_db.update_fields(email, "Accounts", update_fields)
  else:
    logging.info("Unable to create widget because widget type unknown: " + widget_name)
    
  return new_widget
Beispiel #2
0
 def create_session(self, request, email, ssid, expiration):
   """
   Encrypt parameters, set valid in DB, set cookie on client
   """
   account = memcache_db.get_entity(email, "Accounts")
   if account != None:
     update_fields = {"cookieKey" : ssid}
     memcache_db.update_fields(email, "Accounts", update_fields)
   
     email_enc = encryption.des_encrypt_str(email)
     ssid_enc = encryption.des_encrypt_str(ssid)
     exp_enc = encryption.des_encrypt_str(expiration)
     
     import base64
     import string
     email_encoded = string.rstrip(base64.encodestring(email_enc), "\n")
     ssid_encoded = string.rstrip(base64.encodestring(ssid_enc), "\n")
     exp_encoded = string.rstrip(base64.encodestring(exp_enc), "\n")
 
     # the email will be set as the key so we can use it to look up in the DB
     request.response.headers.add_header("Set-Cookie", WEB_ADMIN_PARAMS.COOKIE_EMAIL_PARAM + "=" + email_encoded)
     request.response.headers.add_header("Set-Cookie", WEB_ADMIN_PARAMS.COOKIE_KEY_PARAM + "=" + ssid_encoded)
     request.response.headers.add_header("Set-Cookie", WEB_ADMIN_PARAMS.COOKIE_EXPIRATION + "=" + exp_encoded)
     
     """ Create a new session object and return it """
     self.email = email
     self.ssid = ssid
     self.expiration = expiration
     self.account = account
   
     return self
   else:
     return None
Beispiel #3
0
def create_widget_for_account_by_email(widget_name, email):
  """
  Creates a new widget for the account, will return widget object if success, else it will return None
  """
  new_widget = None
  property_name = None
  if widget_name == "TrophyCase":
    new_widget = TrophyCase(key_name=email)
    property_name = "trophyWidget"
  elif widget_name == "Rank":
    new_widget = Rank(key_name=email)
    property_name = "rankWidget"
  elif widget_name == "Points":
    new_widget = Points(key_name=email)
    property_name = "pointsWidget"
  elif widget_name == "Notifier":
    new_widget = Notifier(key_name=email)
    property_name = "notifierWidget"
  elif widget_name == "Milestones":
    new_widget = Milestones(key_name=email)
    property_name = "milestoneWidget"
  elif widget_name == "Leaderboard":
    new_widget = Leaderboard(key_name=email)
    property_name = "leaderWidget"
    
  if new_widget!= None:
    memcache_db.save_entity(new_widget, email)
    update_fields = { property_name : new_widget }
    memcache_db.update_fields(email, "Accounts", update_fields)
  else:
    logging.info("Unable to create widget because widget type unknown: " + widget_name)
    
  return new_widget
Beispiel #4
0
 def terminate(self):
   """
   Remove cookie_key from datastore
   """
   email = self.email
   if email != None and email != "":
     account = memcache_db.get_entity(self.email, "Accounts")
     if account != None:
       update_fields = {"cookieKey" : "nada" }
       memcache_db.update_fields(email, "Accounts", update_fields)
Beispiel #5
0
def change_account_password(email, new_password):
    """ Change value in data store, also do hashing """
    values = {"password": hashlib.sha1(new_password).hexdigest()}

    try:
        memcache_db.update_fields(email, "Accounts", values)
        return True
    except:
        logging.info("Password change failed.")
        return False
Beispiel #6
0
def change_account_password(email, new_password):
  """ Change value in data store, also do hashing """
  values = {"password" : hashlib.sha1(new_password).hexdigest()}
  
  try:
    memcache_db.update_fields(email, "Accounts", values)
    return True
  except:
    logging.info("Password change failed.")
    return False
Beispiel #7
0
def update_badge_instance(badge_key, diction, incr_fields):
    # Get the old one, and if it was just now awarded set the date/time
    if "awarded" in diction and diction["awarded"] == "yes":
        try:
            badge_ref = memcache_db.get_entity(badge_instance_key, "BadgeInstance")
            if badge_ref and badge_ref.awarded == "no":
                diction["awardDate"] = datetime.date.today()
                diction["awardDateTime"] = datetime.datetime.now()
        except:
            diction["awardDate"] = datetime.date.today()
            diction["awardDateTime"] = datetime.datetime.now()
    return memcache_db.update_fields(badge_key, "BadgeInstance", fields=diction, increment_fields=incr_fields)
Beispiel #8
0
def update_widget_property(email, entity_name, property_name, property_value):
  """
  Saves desired property with new value for the specified entity type
  """
  
  """
  Check to see if the value string is a number or boolean
  """
  logging.info("Try to persist value, but first find out what it is!")
  try:
    value = long(property_value)
    update_fields = { property_name : value }
    memcache_db.update_fields(email, entity_name, update_fields)
    logging.info("Seems to be a number")
    return True
  except:
    try:
      bool_value = bool(property_value)
      if property_value == "True":
        update_fields = { property_name : True }
      else:
        update_fields = { property_name : False }
      memcache_db.update_fields(email, entity_name, update_fields)
      logging.info("Seems to be a boolean")
      return True
    except:
      try:
        update_fields = { property_name : property_value }
        memcache_db.update_fields(email, entity_name, update_fields)
        logging.info("Seems to be a string")
        return True
      except:
        return False
Beispiel #9
0
def update_widget_property(email, entity_name, property_name, property_value):
  """
  Saves desired property with new value for the specified entity type
  """
  
  """
  Check to see if the value string is a number or boolean
  """
  logging.info("Try to persist value, but first find out what it is!")
  try:
    value = long(property_value)
    update_fields = { property_name : value }
    memcache_db.update_fields(email, entity_name, update_fields)
    logging.info("Seems to be a number")
    return True
  except:
    try:
      bool_value = bool(property_value)
      if property_value == "True":
        update_fields = { property_name : True }
      else:
        update_fields = { property_name : False }
      memcache_db.update_fields(email, entity_name, update_fields)
      logging.info("Seems to be a boolean")
      return True
    except:
      try:
        update_fields = { property_name : property_value }
        memcache_db.update_fields(email, entity_name, update_fields)
        logging.info("Seems to be a string")
        return True
      except:
        return False
Beispiel #10
0
    def test1(self):
        key = "*****@*****.**"
        ent_type = "Accounts"
        trophy_case_widget = TrophyCase(key_name=key)
        points_widget = Points(key_name=key)
        rank_widget = Rank(key_name=key)
        newacc = Accounts(
            key_name=key,
            password="******",
            email=key,
            isEnabled="enabled",
            accountType="bronze",
            paymentType="free",
            cookieKey="xxx",
            apiKey="xxx",
            trophyWidget=trophy_case_widget,
            pointsWidget=points_widget,
            rankWidget=rank_widget,
        )
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, key)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.email != key:
            return "Error getting same account. Subtest 1"

        # purge from memcache and get from db
        memcache.delete(key=key, namespace=ent_type)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.email != key:
            return "Error getting same account from DB (no cache). Subtest 2"

        # Set and get new user name
        diction = {"email": "*****@*****.**"}
        ret2 = memcache_db.update_fields(key, ent_type, diction)
        ret2 = sameent.put()
        if ret != ret2:
            self.response.out.write("Error getting key name")
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.email != "*****@*****.**":
            return "Error getting same account after altering entity. Subtest 3"

        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            return "Error deleting entity. Subtest 4"

        return "Success"
Beispiel #11
0
    def test1(self):
        key = "*****@*****.**"
        ent_type = "Accounts"
        trophy_case_widget = TrophyCase(key_name=key)
        points_widget = Points(key_name=key)
        rank_widget = Rank(key_name=key)
        newacc = Accounts(key_name=key,
                          password="******",
                          email=key,
                          isEnabled="enabled",
                          accountType="bronze",
                          paymentType="free",
                          cookieKey="xxx",
                          apiKey="xxx",
                          trophyWidget=trophy_case_widget,
                          pointsWidget=points_widget,
                          rankWidget=rank_widget)
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, key)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.email != key:
            return "Error getting same account. Subtest 1"

        # purge from memcache and get from db
        memcache.delete(key=key, namespace=ent_type)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.email != key:
            return "Error getting same account from DB (no cache). Subtest 2"

        # Set and get new user name
        diction = {"email": "*****@*****.**"}
        ret2 = memcache_db.update_fields(key, ent_type, diction)
        ret2 = sameent.put()
        if ret != ret2:
            self.response.out.write("Error getting key name")
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.email != "*****@*****.**":
            return "Error getting same account after altering entity. Subtest 3"

        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            return "Error deleting entity. Subtest 4"

        return "Success"
Beispiel #12
0
def update_badge_instance(badge_key, diction, incr_fields):
    # Get the old one, and if it was just now awarded set the date/time
    if 'awarded' in diction and diction['awarded'] == "yes":
        try:
            badge_ref = memcache_db.get_entity(badge_instance_key,
                                               "BadgeInstance")
            if badge_ref and badge_ref.awarded == "no":
                diction['awardDate'] = datetime.date.today()
                diction['awardDateTime'] = datetime.datetime.now()
        except:
            diction['awardDate'] = datetime.date.today()
            diction['awardDateTime'] = datetime.datetime.now()
    return memcache_db.update_fields(badge_key,
                                     "BadgeInstance",
                                     fields=diction,
                                     increment_fields=incr_fields)
Beispiel #13
0
    def test4(self):
        account_key = "[email protected]"
        trophy_case_widget = TrophyCase(key_name=account_key)
        points_widget = Points(key_name=account_key)
        rank_widget = Rank(key_name=account_key)
        newacc = Accounts(
            key_name=account_key,
            password="******",
            email="[email protected]",
            isEnabled="enabled",
            accountType="bronze",
            paymentType="free",
            apiKey="xxx",
            cookieKey="xxx",
            trophyWidget=trophy_case_widget,
            pointsWidget=points_widget,
            rankWidget=rank_widget,
        )
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass

        # Save an account
        ret = memcache_db.save_entity(newacc, account_key)

        user_key = "testuser1"
        newuser = Users(key_name=user_key, userid=user_key, isEnabled="yes", accountRef=newacc, tags=user_key)
        try:
            memcache_db.delete_entity(newacc, user_key)
        except Exception:
            pass
        # Save a user
        ret = memcache_db.save_entity(newacc, user_key)

        # Create a Badge Type
        badge_key = "testbadge1"
        badgetype = Badges(
            key_name=badge_key,
            name="badge1",
            description=badge_key,
            altText="a really cool badge",
            setType="free",
            isEnabled="yes",
            creator=newacc,
            permissions="private",
            storageType="blob",
            blobKey="xxxx",
        )
        try:
            memcache_db.delete_entity(badgetype, badge_key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(badgetype, badge_key)

        key = "testbadgeinstance1"
        ent_type = "BadgeInstance"
        badgeinstance = BadgeInstance(
            key_name=key,
            awarded="no",
            badgeRef=badgetype,
            userRef=newuser,
            pointRequired=10,
            pointsEarned=0,
            permissions="private",
        )
        try:
            memcache_db.delete_entity(badgeinstance, key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(badgeinstance, key)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.awarded != "no":
            return "Error getting same entity. Subtest 1"

        # purge from memcache and get from db
        memcache.delete(key=key, namespace=ent_type)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.awarded != "no":
            return "Error getting same entity from DB (no cache). Subtest 2"

        # Set and get new user name
        diction = {"pointsRequired": 11, "awarded": "no"}
        inc_diction = {"pointsEarned": 5}
        ret2 = memcache_db.update_fields(key, ent_type, diction, inc_diction)
        ret2 = sameent.put()
        if ret != ret2:
            self.response.out.write("Error getting key name")
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.pointsRequired != 11 or sameent.pointsEarned != 5:
            return "Error getting same entity after altering entity. Subtest 3"

        # Cleanup
        try:
            memcache_db.delete_entity(badgeinstance, key)
        except Exception:
            return "Error deleting entity. Subtest 4"
        try:
            memcache_db.delete_entity(newacc, account_key)
        except Exception:
            return "Error deleting entity. Subtest 4"
        try:
            memcache_db.delete_entity(badgetype, badge_key)
        except Exception:
            return "Error deleting entity. Subtest 4"
        try:
            memcache_db.delete_entity(newuser, user_key)
        except Exception:
            return "Error deleting entity. Subtest 4"

        return "Success"
Beispiel #14
0
    def test3(self):
        account_key = "[email protected]"
        trophy_case_widget = TrophyCase(key_name=account_key)
        points_widget = Points(key_name=account_key)
        rank_widget = Rank(key_name=account_key)
        newacc = Accounts(key_name=account_key,
                          password="******",
                          email="[email protected]",
                          isEnabled="enabled",
                          accountType="bronze",
                          paymentType="free",
                          apiKey="xxx",
                          cookieKey="xxx",
                          trophyWidget=trophy_case_widget,
                          pointsWidget=points_widget,
                          rankWidget=rank_widget)
        try:
            memcache_db.delete_entity(newacc, account_key)
        except Exception:
            pass

        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, account_key)

        key = "testuser1"
        ent_type = "Users"
        newacc = Users(key_name=key,
                       userid=key,
                       isEnabled="yes",
                       accountRef=newacc,
                       tags=key)
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, key)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.tags != key:
            return "Error getting same entity. Subtest 1"

        # purge from memcache and get from db
        memcache.delete(key=key, namespace=ent_type)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.tags != key:
            return "Error getting same entity from DB (no cache). Subtest 2"

        # Set and get new user name
        diction = {"tags": "goodbye:hello"}
        ret2 = memcache_db.update_fields(key, ent_type, diction)
        ret2 = sameent.put()
        if ret != ret2:
            self.response.out.write("Error getting key name")
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.tags != "goodbye:hello":
            return "Error getting same entity after altering entity. Subtest 3"

        try:
            memcache_db.delete_entity(newacc, account_key)
            memcache_db.delete_entity(sameent, key)
        except Exception:
            return "Error deleting entity. Subtest 4"

        return "Success"
Beispiel #15
0
    def test4(self):
        account_key = "[email protected]"
        trophy_case_widget = TrophyCase(key_name=account_key)
        points_widget = Points(key_name=account_key)
        rank_widget = Rank(key_name=account_key)
        newacc = Accounts(key_name=account_key,
                          password="******",
                          email="[email protected]",
                          isEnabled="enabled",
                          accountType="bronze",
                          paymentType="free",
                          apiKey="xxx",
                          cookieKey="xxx",
                          trophyWidget=trophy_case_widget,
                          pointsWidget=points_widget,
                          rankWidget=rank_widget)
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass

        # Save an account
        ret = memcache_db.save_entity(newacc, account_key)

        user_key = "testuser1"
        newuser = Users(key_name=user_key,
                        userid=user_key,
                        isEnabled="yes",
                        accountRef=newacc,
                        tags=user_key)
        try:
            memcache_db.delete_entity(newacc, user_key)
        except Exception:
            pass
        # Save a user
        ret = memcache_db.save_entity(newacc, user_key)

        # Create a Badge Type
        badge_key = "testbadge1"
        badgetype = Badges(key_name=badge_key,
                           name="badge1",
                           description=badge_key,
                           altText="a really cool badge",
                           setType="free",
                           isEnabled="yes",
                           creator=newacc,
                           permissions="private",
                           storageType="blob",
                           blobKey="xxxx")
        try:
            memcache_db.delete_entity(badgetype, badge_key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(badgetype, badge_key)

        key = "testbadgeinstance1"
        ent_type = "BadgeInstance"
        badgeinstance = BadgeInstance(key_name=key,
                                      awarded="no",
                                      badgeRef=badgetype,
                                      userRef=newuser,
                                      pointRequired=10,
                                      pointsEarned=0,
                                      permissions="private")
        try:
            memcache_db.delete_entity(badgeinstance, key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(badgeinstance, key)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.awarded != "no":
            return "Error getting same entity. Subtest 1"

        # purge from memcache and get from db
        memcache.delete(key=key, namespace=ent_type)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.awarded != "no":
            return "Error getting same entity from DB (no cache). Subtest 2"

        # Set and get new user name
        diction = {"pointsRequired": 11, "awarded": "no"}
        inc_diction = {"pointsEarned": 5}
        ret2 = memcache_db.update_fields(key, ent_type, diction, inc_diction)
        ret2 = sameent.put()
        if ret != ret2:
            self.response.out.write("Error getting key name")
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.pointsRequired!= 11 \
              or sameent.pointsEarned != 5:
            return "Error getting same entity after altering entity. Subtest 3"

        # Cleanup
        try:
            memcache_db.delete_entity(badgeinstance, key)
        except Exception:
            return "Error deleting entity. Subtest 4"
        try:
            memcache_db.delete_entity(newacc, account_key)
        except Exception:
            return "Error deleting entity. Subtest 4"
        try:
            memcache_db.delete_entity(badgetype, badge_key)
        except Exception:
            return "Error deleting entity. Subtest 4"
        try:
            memcache_db.delete_entity(newuser, user_key)
        except Exception:
            return "Error deleting entity. Subtest 4"

        return "Success"
Beispiel #16
0
def add_resource_link(badge_key, url):
    diction = {'resourceLink': url}
    return memcache_db.update_fields(badge_key, "Badges", fields=diction)
Beispiel #17
0
    def test2(self):
        account_key = "raj"
        trophy_case_widget = TrophyCase(key_name=account_key)
        points_widget = Points(key_name=account_key)
        rank_widget = Rank(key_name=account_key)
        newacc = Accounts(key_name=account_key,
                          password="******",
                          email="[email protected]",
                          isEnabled="enabled",
                          accountType="bronze",
                          paymentType="free",
                          apiKey="xxx",
                          cookieKey="xxx",
                          trophyWidget=trophy_case_widget,
                          pointsWidget=points_widget,
                          rankWidget=rank_widget)
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass

        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, account_key)

        key = "testbadge1"
        ent_type = "Badges"
        newacc = Badges(key_name=key,
                        name="badge1",
                        description=key,
                        altText="a really cool badge",
                        setType="free",
                        isEnabled="yes",
                        creator=newacc,
                        permissions="private",
                        blobKey="xxxx",
                        storageType="blob")
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, key)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.description != key:
            return "Error getting same account. Subtest 1"

        # purge from memcache and get from db
        memcache.delete(key=key, namespace=ent_type)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.description != key:
            return "Error getting same account from DB (no cache). Subtest 2"

        # Set and get new user name
        diction = {"isEnabled": "no", "permissions": "public"}
        ret2 = memcache_db.update_fields(key, ent_type, diction)
        ret2 = sameent.put()
        if ret != ret2:
            self.response.out.write("Error getting key name")
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.isEnabled != "no" or sameent.permissions != "public":
            return "Error getting same account after altering entity. Subtest 3"

        try:
            memcache_db.delete_entity(sameent, key)
        except Exception:
            return "Error deleting entity. Subtest 4"

        try:
            memcache_db.delete_entity(newacc, account_key)
        except Exception:
            return "Error deleting account. Subtest 5"

        return "Success"
Beispiel #18
0
def update_user(user_key, dict, incr_fields):
  return memcache_db.update_fields(user_key, "Users", fields=dict, increment_fields=incr_fields)
Beispiel #19
0
def add_expiration(badge_key, date):
    diction = {'expiration': date}
    return memcache_db.update_fields(badge_key, "Badges", fields=diction)
Beispiel #20
0
def set_user_points(account_id, user_id, points):
  fields = {"points" : points}
  user_key = get_user_key(account_id, user_id)
  return memcache_db.update_fields(user_key, "Users", fields)
Beispiel #21
0
def set_user_points(account_id, user_id, points):
    fields = {"points": points}
    user_key = get_user_key(account_id, user_id)
    return memcache_db.update_fields(user_key, "Users", fields)
Beispiel #22
0
def add_resource_link(badge_key, url):
    diction = {"resourceLink": url}
    return memcache_db.update_fields(badge_key, "Badges", fields=diction)
Beispiel #23
0
    def test3(self):
        account_key = "[email protected]"
        trophy_case_widget = TrophyCase(key_name=account_key)
        points_widget = Points(key_name=account_key)
        rank_widget = Rank(key_name=account_key)
        newacc = Accounts(
            key_name=account_key,
            password="******",
            email="[email protected]",
            isEnabled="enabled",
            accountType="bronze",
            paymentType="free",
            apiKey="xxx",
            cookieKey="xxx",
            trophyWidget=trophy_case_widget,
            pointsWidget=points_widget,
            rankWidget=rank_widget,
        )
        try:
            memcache_db.delete_entity(newacc, account_key)
        except Exception:
            pass

        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, account_key)

        key = "testuser1"
        ent_type = "Users"
        newacc = Users(key_name=key, userid=key, isEnabled="yes", accountRef=newacc, tags=key)
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, key)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.tags != key:
            return "Error getting same entity. Subtest 1"

        # purge from memcache and get from db
        memcache.delete(key=key, namespace=ent_type)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.tags != key:
            return "Error getting same entity from DB (no cache). Subtest 2"

        # Set and get new user name
        diction = {"tags": "goodbye:hello"}
        ret2 = memcache_db.update_fields(key, ent_type, diction)
        ret2 = sameent.put()
        if ret != ret2:
            self.response.out.write("Error getting key name")
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.tags != "goodbye:hello":
            return "Error getting same entity after altering entity. Subtest 3"

        try:
            memcache_db.delete_entity(newacc, account_key)
            memcache_db.delete_entity(sameent, key)
        except Exception:
            return "Error deleting entity. Subtest 4"

        return "Success"
Beispiel #24
0
    def test2(self):
        account_key = "raj"
        trophy_case_widget = TrophyCase(key_name=account_key)
        points_widget = Points(key_name=account_key)
        rank_widget = Rank(key_name=account_key)
        newacc = Accounts(
            key_name=account_key,
            password="******",
            email="[email protected]",
            isEnabled="enabled",
            accountType="bronze",
            paymentType="free",
            apiKey="xxx",
            cookieKey="xxx",
            trophyWidget=trophy_case_widget,
            pointsWidget=points_widget,
            rankWidget=rank_widget,
        )
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass

        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, account_key)

        key = "testbadge1"
        ent_type = "Badges"
        newacc = Badges(
            key_name=key,
            name="badge1",
            description=key,
            altText="a really cool badge",
            setType="free",
            isEnabled="yes",
            creator=newacc,
            permissions="private",
            blobKey="xxxx",
            storageType="blob",
        )
        try:
            memcache_db.delete_entity(newacc, key)
        except Exception:
            pass
        # Save and get saved ent
        ret = memcache_db.save_entity(newacc, key)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.description != key:
            return "Error getting same account. Subtest 1"

        # purge from memcache and get from db
        memcache.delete(key=key, namespace=ent_type)
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.description != key:
            return "Error getting same account from DB (no cache). Subtest 2"

        # Set and get new user name
        diction = {"isEnabled": "no", "permissions": "public"}
        ret2 = memcache_db.update_fields(key, ent_type, diction)
        ret2 = sameent.put()
        if ret != ret2:
            self.response.out.write("Error getting key name")
        sameent = memcache_db.get_entity(key, ent_type)
        if sameent.isEnabled != "no" or sameent.permissions != "public":
            return "Error getting same account after altering entity. Subtest 3"

        try:
            memcache_db.delete_entity(sameent, key)
        except Exception:
            return "Error deleting entity. Subtest 4"

        try:
            memcache_db.delete_entity(newacc, account_key)
        except Exception:
            return "Error deleting account. Subtest 5"

        return "Success"
Beispiel #25
0
def add_expiration(badge_key, date):
    diction = {"expiration": date}
    return memcache_db.update_fields(badge_key, "Badges", fields=diction)
Beispiel #26
0
def update_user(user_key, dict, incr_fields):
    return memcache_db.update_fields(user_key,
                                     "Users",
                                     fields=dict,
                                     increment_fields=incr_fields)