|
@@ -129,84 +129,6 @@ class FrameworkTest:
|
|
##########################################################################################
|
|
##########################################################################################
|
|
|
|
|
|
|
|
|
|
- ############################################################
|
|
|
|
- # Validates the jsonString is a JSON object that has an "id"
|
|
|
|
- # and a "randomNumber" key, and that both keys map to
|
|
|
|
- # integers.
|
|
|
|
- ############################################################
|
|
|
|
- def validateDb(self, jsonString, out, err):
|
|
|
|
- err_str = ""
|
|
|
|
- if jsonString is None or len(jsonString) == 0:
|
|
|
|
- err_str += "Empty Response"
|
|
|
|
- return (False, err_str)
|
|
|
|
- try:
|
|
|
|
- obj = {k.lower(): v for k,v in json.loads(jsonString).iteritems()}
|
|
|
|
-
|
|
|
|
- # We are allowing the single-object array for the DB
|
|
|
|
- # test for now, but will likely remove this later.
|
|
|
|
- if type(obj) == list:
|
|
|
|
- obj = obj[0]
|
|
|
|
-
|
|
|
|
- if "id" not in obj or "randomnumber" not in obj:
|
|
|
|
- err_str += "Expected keys id and randomNumber to be in JSON string. "
|
|
|
|
- return (False, err_str)
|
|
|
|
-
|
|
|
|
- # This will error out of the value could not parsed to a
|
|
|
|
- # float (this will work with ints, but it will turn them
|
|
|
|
- # into their float equivalent; i.e. "123" => 123.0)
|
|
|
|
- id_ret_val = True
|
|
|
|
- try:
|
|
|
|
- if not isinstance(float(obj["id"]), float):
|
|
|
|
- id_ret_val=False
|
|
|
|
- except:
|
|
|
|
- id_ret_val=False
|
|
|
|
- if not id_ret_val:
|
|
|
|
- err_str += "Expected id to be type int or float, got '{rand}' ".format(rand=obj["randomnumber"])
|
|
|
|
- random_num_ret_val = True
|
|
|
|
- try:
|
|
|
|
- if not isinstance(float(obj["randomnumber"]), float):
|
|
|
|
- random_num_ret_val=False
|
|
|
|
- except:
|
|
|
|
- random_num_ret_val=False
|
|
|
|
- if not random_num_ret_val:
|
|
|
|
- err_str += "Expected id to be type int or float, got '{rand}' ".format(rand=obj["randomnumber"])
|
|
|
|
- except:
|
|
|
|
- err_str += "Got exception when trying to validate the db test: {exception}".format(exception=traceback.format_exc())
|
|
|
|
- return (True, ) if len(err_str) == 0 else (False, err_str)
|
|
|
|
-
|
|
|
|
- def validateDbStrict(self, jsonString, out, err):
|
|
|
|
- err_str = ""
|
|
|
|
- if jsonString is None or len(jsonString) == 0:
|
|
|
|
- err_str += "Empty Response "
|
|
|
|
- return (False, err_str)
|
|
|
|
- try:
|
|
|
|
- obj = {k.lower(): v for k,v in json.loads(jsonString).iteritems()}
|
|
|
|
-
|
|
|
|
- # This will error out of the value could not parsed to a
|
|
|
|
- # float (this will work with ints, but it will turn them
|
|
|
|
- # into their float equivalent; i.e. "123" => 123.0)
|
|
|
|
- id_ret_val = True
|
|
|
|
- try:
|
|
|
|
- if not isinstance(float(obj["id"]), float):
|
|
|
|
- id_ret_val=False
|
|
|
|
- except:
|
|
|
|
- id_ret_val=False
|
|
|
|
- if not id_ret_val:
|
|
|
|
- err_str += "Expected id to be type int or float, got '{rand}' ".format(rand=obj["randomnumber"])
|
|
|
|
- random_num_ret_val = True
|
|
|
|
- try:
|
|
|
|
- if not isinstance(float(obj["randomnumber"]), float):
|
|
|
|
- random_num_ret_val=False
|
|
|
|
- except:
|
|
|
|
- random_num_ret_val=False
|
|
|
|
- if not random_num_ret_val:
|
|
|
|
- err_str += "Expected id to be type int or float, got '{rand}' ".format(rand=obj["randomnumber"])
|
|
|
|
- return id_ret_val and random_num_ret_val
|
|
|
|
- except:
|
|
|
|
- err_str += "Got exception when trying to validate the db test: {exception}".format(exception=traceback.format_exc())
|
|
|
|
- return (True, ) if len(err_str) == 0 else (False, err_str)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
############################################################
|
|
############################################################
|
|
# Validates the jsonString is an array with a length of
|
|
# Validates the jsonString is an array with a length of
|
|
# 2, that each entry in the array is a JSON object, that
|
|
# 2, that each entry in the array is a JSON object, that
|