Beispiel #1
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 #2
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 #3
0
def authenticate_web_account(account_id, password):
    entity = memcache_db.get_entity(account_id, "Accounts")
    if entity != None and entity.password == hashlib.sha1(password).hexdigest(
    ) and entity.isEnabled == ACCOUNT_STATUS.ENABLED:
        return entity
    else:
        return None
Beispiel #4
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 #5
0
def get_badge_instance(badge_instance_key):
    badge_ref = None
    try:
        badge_ref = memcache_db.get_entity(badge_instance_key, "BadgeInstance")
    except:
        logging.error("badges_dao: Error getting badge type with key %s" % badge_key)
        raise
    return badge_ref
Beispiel #6
0
def get_badge_instance(badge_instance_key):
    badge_ref = None
    try:
        badge_ref = memcache_db.get_entity(badge_instance_key, "BadgeInstance")
    except:
        logging.error("badges_dao: Error getting badge type with key %s" %
                      badge_key)
        raise
    return badge_ref
Beispiel #7
0
def get_trophy_case(key):
  """
  return corresponding trophy case entity
  
  This function seems unnecesary, but later we might need to do additional checking
  An effort to standardize data access
  """  
  logging.info("retrieving trophy case for account: " + key)
  return memcache_db.get_entity(key, "TrophyCase")
Beispiel #8
0
def get_user_with_key(user_key):
    user_ref = None
    try:
        user_ref = memcache_db.get_entity(user_key, "Users")
    except:
        logging.error("Error getting key %s"%\
              (user_key))
        return None
    return user_ref
Beispiel #9
0
def get_encrypt_secret():
    secret = memcache_db.get_entity(constants.ENCRYPTION_KEYNAME, "PassPhrase")
    if not secret:
        phrase = gen_random(8)  #must be 8 characters long
        ent = PassPhrase(key_name=constants.ENCRYPTION_KEYNAME, secret=phrase)
        memcache_db.save_entity(ent, constants.ENCRYPTION_KEYNAME)
        return phrase
    else:
        return secret.secret
Beispiel #10
0
def get_trophy_case(key):
  """
  return corresponding trophy case entity
  
  This function seems unnecesary, but later we might need to do additional checking
  An effort to standardize data access
  """  
  logging.info("retrieving trophy case for account: " + key)
  return memcache_db.get_entity(key, "TrophyCase")
Beispiel #11
0
def get_user_with_key(user_key):
  user_ref = None
  try:
    user_ref = memcache_db.get_entity(user_key, "Users")
  except:
    logging.error("Error getting key %s"%\
          (user_key))
    return None
  return user_ref
Beispiel #12
0
def get_aes_encrypt_secret():  
  secret = memcache_db.get_entity(constants.AES_ENCRYPTION_KEYNAME, "PassPhrase")
  if not secret: 
    phrase = gen_random(16) # must be 16 chars long
    ent = PassPhrase(key_name=constants.AES_ENCRYPTION_KEYNAME, secret=phrase)
    memcache_db.save_entity(ent, constants.AES_ENCRYPTION_KEYNAME)
    return phrase
  else:
    return secret.secret
Beispiel #13
0
def get_update_secret():
  secret = memcache_db.get_entity(constants.UPDATE.SECRET_KEYNAME, "PassPhrase")
  if not secret: 
    phrase = gen_random(16)
    ent = PassPhrase(key_name=constants.UPDATE.SECRET_KEYNAME, secret=phrase)
    memcache_db.save_entity(ent, constants.UPDATE.SECRET_KEYNAME)
    return phrase
  else:
    return secret.secret
Beispiel #14
0
def get_single_widget_value(key, entity_name, value_name):
  widget_entity = memcache_db.get_entity(key, entity_name)
  if widget_entity != None:
    value = str(widget_entity.__getattribute__(str(value_name)))
    if value != None:
      return value
    else:
      return "Error"
  else:
    return "Error"
Beispiel #15
0
def get_user(account_id, user_id):
    user_ref = None
    user_key = get_user_key(account_id, user_id)
    try:
        user_ref = memcache_db.get_entity(user_key, "Users")
    except:
        logging.error("Error getting key %s for user %s and account %s"%\
              (user_key, user_id, account_id))
        return None
    return user_ref
Beispiel #16
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 #17
0
def get_single_widget_value(key, entity_name, value_name):
  widget_entity = memcache_db.get_entity(key, entity_name)
  if widget_entity != None:
    value = str(widget_entity.__getattribute__(str(value_name)))
    if value != None:
      return value
    else:
      return "Error"
  else:
    return "Error"
Beispiel #18
0
def get_user(account_id, user_id):
  user_ref = None
  user_key = get_user_key(account_id, user_id)
  try:
    user_ref = memcache_db.get_entity(user_key, "Users")
  except:
    logging.error("Error getting key %s for user %s and account %s"%\
          (user_key, user_id, account_id))
    return None
  return user_ref 
def authenticate_web_account(account_id, password):
    entity = memcache_db.get_entity(account_id, "Accounts")
    if (
        entity != None
        and entity.password == hashlib.sha1(password).hexdigest()
        and entity.isEnabled == ACCOUNT_STATUS.ENABLED
    ):
        return entity
    else:
        return None
Beispiel #20
0
def get_badge(badge_key):
    """
  Returns the reference to a badge, otherwise logs an error
  """
    badge_ref = None
    try:
        badge_ref = memcache_db.get_entity(badge_key, "Badges")
    except:
        logging.error("badges_dao: Error getting badge type with key %s" % badge_key)
    return badge_ref
Beispiel #21
0
def get_badge(badge_key):
    """
  Returns the reference to a badge, otherwise logs an error
  """
    badge_ref = None
    try:
        badge_ref = memcache_db.get_entity(badge_key, "Badges")
    except:
        logging.error("badges_dao: Error getting badge type with key %s" %
                      badge_key)
    return badge_ref
Beispiel #22
0
def get_update_secret():
    secret = memcache_db.get_entity(constants.UPDATE.SECRET_KEYNAME,
                                    "PassPhrase")
    if not secret:
        phrase = gen_random(16)
        ent = PassPhrase(key_name=constants.UPDATE.SECRET_KEYNAME,
                         secret=phrase)
        memcache_db.save_entity(ent, constants.UPDATE.SECRET_KEYNAME)
        return phrase
    else:
        return secret.secret
Beispiel #23
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 #24
0
 def get_current_session(self, request):
   """
   Returns a session object if a session can be detected given the HTTP request.
   This may include sifting through cookie values, or request params.
   
   Args:
   request
   
   Returns:
   Session or None
   """
   quoted_email = request.request.cookies.get(WEB_ADMIN_PARAMS.COOKIE_EMAIL_PARAM)
   quoted_ssid = request.request.cookies.get(WEB_ADMIN_PARAMS.COOKIE_KEY_PARAM)
   quoted_exp = request.request.cookies.get(WEB_ADMIN_PARAMS.COOKIE_EXPIRATION)
   
   if quoted_email == "" or quoted_ssid == "" or quoted_exp == "" or quoted_email == None or quoted_ssid == None or quoted_exp == None:
     return None
   else:
     import base64
     try: 
       unquoted_email = base64.decodestring(quoted_email)
       unquoted_ssid = base64.decodestring(quoted_ssid)
       unquoted_exp = base64.decodestring(quoted_exp)
     
       decrypted_email = encryption.des_decrypt_str(unquoted_email)
       decrypted_ssid = encryption.des_decrypt_str(unquoted_ssid)
       decrypted_exp = encryption.des_decrypt_str(unquoted_exp)
     except:
       logging.error("Error decoding sesssion: UnicodeDecodeError: 'ascii' codec can't decode byte: ordinal not in range(128)")
       return None 
     """ Make sure that the session has not expired """
     now = time.time()
     if not decrypted_exp:
       decrypted_exp = 0
     exp = float(decrypted_exp)
     if(now < exp):
       """ Make sure that the session is still valid """
       account = memcache_db.get_entity(decrypted_email, "Accounts")
       if account != None and account.cookieKey == decrypted_ssid:
         """ Create a new session object and return it """
         self.email = decrypted_email
         self.ssid = decrypted_ssid
         self.expiration = decrypted_exp
         self.account = account
       else:
         return None
     else:
       return None
     return self
Beispiel #25
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)
def authorize_api(account_id, api_key):
    """
  return the account on success, non on failure
  """
    acc = None
    try:
        acc = memcache_db.get_entity(account_id, "Accounts")
    except:
        logging.error("Error getting account with key %s" % account_id)
        return None
    if not acc:
        logging.error("Permission error with null  account")
        return None
    if acc.apiKey != api_key or not acc.isEnabled:
        logging.error("Permission error with %s account with %s api key versus %s" % (account_id, api_key, acc.apiKey))
        return None
    return acc
Beispiel #27
0
def create_new_user(account_id, user_id):
    """
  Create a new user entity and save
  Look up account with account_id and use in reference when creating new user 
  """
    account_entity = memcache_db.get_entity(account_id, "Accounts")

    user_key = get_user_key(account_id, user_id)
    new_user = Users(key_name=user_key,
                     userid=user_id,
                     isEnabled="yes",
                     accountRef=account_entity)

    try:
        memcache_db.save_entity(new_user, user_key)
    except:
        logging.error("Error saving new user entity")
        return
Beispiel #28
0
def create_new_user(account_id, user_id):
  """
  Create a new user entity and save
  Look up account with account_id and use in reference when creating new user 
  """
  account_entity = memcache_db.get_entity(account_id, "Accounts")
  
  user_key= get_user_key(account_id, user_id)
  new_user = Users(key_name=user_key,
                   userid=user_id,
                   isEnabled="yes",
                   accountRef=account_entity)
  
  try:
    memcache_db.save_entity(new_user, user_key)
  except:
    logging.error("Error saving new user entity")
    return  
Beispiel #29
0
def reset_password(email):
  """
  Generates a random password for the account, and saves into account.
  Returns the new password.
  Returns None if account lookup/update fails
  """
  account_entity = memcache_db.get_entity(email, "Accounts")
  ret = None
  if account_entity:
    random_str = utils.generate_random_string(8)
    if change_account_password(email, random_str):
      ret = random_str
    else:
      logging.info("Unable to change password.")
  else:
    logging.info("Password cannot be reset, account was not located.")
      
  return ret
Beispiel #30
0
def authorize_api(account_id, api_key):
    """
  return the account on success, non on failure
  """
    acc = None
    try:
        acc = memcache_db.get_entity(account_id, "Accounts")
    except:
        logging.error("Error getting account with key %s" % account_id)
        return None
    if not acc:
        logging.error("Permission error with null  account")
        return None
    if acc.apiKey != api_key or not acc.isEnabled:
        logging.error("Permission error with %s account with %s api key versus %s"\
                      %(account_id, api_key, acc.apiKey))
        return None
    return acc
Beispiel #31
0
def reset_password(email):
    """
  Generates a random password for the account, and saves into account.
  Returns the new password.
  Returns None if account lookup/update fails
  """
    account_entity = memcache_db.get_entity(email, "Accounts")
    ret = None
    if account_entity:
        random_str = utils.generate_random_string(8)
        if change_account_password(email, random_str):
            ret = random_str
        else:
            logging.info("Unable to change password.")
    else:
        logging.info("Password cannot be reset, account was not located.")

    return ret
Beispiel #32
0
def delete_badge_blob(badge_key):
    badge = memcache_db.get_entity(badge_key, "Badges")
    if badge.blobKey:
        blob_key = badge.blobKey
        blob = BlobInfo.get(blob_key)
        blob.delete()
Beispiel #33
0
def get_badge_image(badge_key):
    return memcache_db.get_entity(badge_key, "BadgeImage")
Beispiel #34
0
def get_badge_image(badge_key):
    return memcache_db.get_entity(badge_key, "BadgeImage")
Beispiel #35
0
def delete_badge_blob(badge_key):
    badge = memcache_db.get_entity(badge_key, "Badges")
    if badge.blobKey:
        blob_key = badge.blobKey
        blob = BlobInfo.get(blob_key)
        blob.delete()
Beispiel #36
0
def authenticate_web_account_hashed(account_id, hashedpassword):
  entity = memcache_db.get_entity(account_id, "Accounts")
  if entity != None and entity.password == hashedpassword and entity.isEnabled == ACCOUNT_STATUS.ENABLED:
    return entity
  else:
    return None   
Beispiel #37
0
def get(acc_key):
    return memcache_db.get_entity(acc_key, "Accounts")
Beispiel #38
0
def authenticate_web_account_hashed(account_id, hashedpassword):
  entity = memcache_db.get_entity(account_id, "Accounts")
  if entity != None and entity.password == hashedpassword and entity.isEnabled == ACCOUNT_STATUS.ENABLED:
    return entity
  else:
    return None   
Beispiel #39
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 #40
0
def get(acc_key):
  return memcache_db.get_entity(acc_key, "Accounts")
Beispiel #41
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 #42
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 #43
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 #44
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 #45
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"