def test(self, valueToTest): if valueToTest is None: raise ValidationError("No filter provided") # Create the filters that we will need str_validate = Factory.create('string', 'string') int_validate = Factory.create('int', 'int') float_validate = Factory.create('float', 'float') list_validate = Factory.create('list', 'list') dict_validate = Factory.create('dict', 'dict') mode_validate = Factory.create('mode', 'mode') feature_validate = Factory.create('feature', 'feature') order_validate = Factory.create('order', 'order') item_type_validate = Factory.create('item_type', 'item_type') history_days_validate = Factory.create('history', 'history') result = {} # Verify that each individual filter is valid for name, fil in valueToTest.iteritems(): # Validate name name = str_validate.test(name) if len(name) <= 0 or len(name) > 30: raise ValidationError('Filter name must be length 1-30') result[name] = {} # Validate the filter fil = dict_validate.test(fil) result[name]['HistoryDays'] = history_days_validate.test( fil.get('HistoryDays')) result[name]['BuyMode'] = mode_validate.test(fil.get('BuyMode')) result[name]['SellMode'] = mode_validate.test(fil.get('SellMode')) result[name]['SortBy'] = feature_validate.test(fil.get('SortBy')) result[name]['SortOrder'] = order_validate.test( fil.get('SortOrder')) types = list_validate.test(fil.get('Types')) good_types = [] for t in types: t = item_type_validate.test(t) if t in good_types: raise ValidationError( 'Types list cannot contain duplicates') good_types.append(t) result[name]['Types'] = good_types bounds = dict_validate.test(fil.get('Bounds')) good_bounds = {} for feat, dic in bounds.iteritems(): feat = feature_validate.test(feat) dic = dict_validate.test(dic) good_bounds[feat] = {} min_val = dic.get('Min') max_val = dic.get('Max') if min_val is not None: min_val = float_validate.test(min_val) good_bounds[feat]['Min'] = min_val if max_val is not None: max_val = float_validate.test(max_val) good_bounds[feat]['Max'] = max_val result[name]['Bounds'] = good_bounds return result
def test(self, valueToTest): if valueToTest is None: raise ValidationError("No filter provided") # Create the filters that we will need str_validate = Factory.create('string', 'string') int_validate = Factory.create('int', 'int') float_validate = Factory.create('float', 'float') list_validate = Factory.create('list', 'list') dict_validate = Factory.create('dict', 'dict') mode_validate = Factory.create('mode', 'mode') feature_validate = Factory.create('feature', 'feature') order_validate = Factory.create('order', 'order') item_type_validate = Factory.create('item_type', 'item_type') history_days_validate = Factory.create('history', 'history') result = {} # Verify that each individual filter is valid for name, fil in valueToTest.iteritems(): # Validate name name = str_validate.test(name) if len(name) <= 0 or len(name) > 30: raise ValidationError('Filter name must be length 1-30') result[name] = {} # Validate the filter fil = dict_validate.test(fil) result[name]['HistoryDays'] = history_days_validate.test(fil.get('HistoryDays')) result[name]['BuyMode'] = mode_validate.test(fil.get('BuyMode')) result[name]['SellMode'] = mode_validate.test(fil.get('SellMode')) result[name]['SortBy'] = feature_validate.test(fil.get('SortBy')) result[name]['SortOrder'] = order_validate.test(fil.get('SortOrder')) types = list_validate.test(fil.get('Types')) good_types = [] for t in types: t = item_type_validate.test(t) if t in good_types: raise ValidationError('Types list cannot contain duplicates') good_types.append(t) result[name]['Types'] = good_types bounds = dict_validate.test(fil.get('Bounds')) good_bounds = {} for feat, dic in bounds.iteritems(): feat = feature_validate.test(feat) dic = dict_validate.test(dic) good_bounds[feat] = {} min_val = dic.get('Min') max_val = dic.get('Max') if min_val is not None: min_val = float_validate.test(min_val) good_bounds[feat]['Min'] = min_val if max_val is not None: max_val = float_validate.test(max_val) good_bounds[feat]['Max'] = max_val result[name]['Bounds'] = good_bounds return result
def test(self, valueToTest): if valueToTest is None: raise ValidationError("No history days provided") int_validate = Factory.create('int', 'int') days = int_validate.test(valueToTest) if days not in self.allowed_days: raise ValidationError(str(days) + " is not a valid history day amount") return days
def test(self, valueToTest): if valueToTest is None: raise ValidationError("No plan provided") # Create the filters that we'll need mode_validate = Factory.create('mode', 'mode') history_days_validate = Factory.create('history', 'history') int_validate = Factory.create('int', 'int') dict_validate = Factory.create('dict', 'dict') # Filter the input as a dict plan = dict_validate.test(valueToTest) # Use the filters to get the result result = {} result['Id'] = int_validate.test(plan.get('Id')) result['HistoryDays'] = history_days_validate.test(plan.get('HistoryDays')) result['BuyMode'] = mode_validate.test(plan.get('BuyMode')) result['SellMode'] = mode_validate.test(plan.get('SellMode')) return result
def test(self, valueToTest): if valueToTest is None: raise ValidationError("No feature provided") # Parse feature to string str_validate = Factory.create('string', 'string') feature = str_validate.test(valueToTest) # Verify that it is a valid value if feature not in self.features: raise ValidationError(feature + ' is not a valid feature') return feature
def test(self, valueToTest): if valueToTest is None: raise ValidationError("No mode provided") # Parse mode to string str_validate = Factory.create('string', 'string') mode = str_validate.test(valueToTest) # Verify that it is a valid value if mode != 'Instant' and mode != 'Bid': raise ValidationError('Mode must be Instant or Bid') return mode
def test(self, valueToTest): if valueToTest is None: raise ValidationError("No item type provided") # Parse item type to string str_validate = Factory.create('string', 'string') item_type = str_validate.test(valueToTest) # Verify that it is a valid value if item_type not in self.item_types: raise ValidationError(item_type + ' is not a valid item type') return item_type
def test(self, valueToTest): if valueToTest is None: raise ValidationError("No order provided") # Parse order to string str_validate = Factory.create('string', 'string') order = str_validate.test(valueToTest) # Verify that it is a valid value if order != 'Asc' and order != 'Desc': raise ValidationError('Order must be Asc or Desc') return order
def test(self, valueToTest): if valueToTest is None: raise ValidationError("No plan provided") # Create the filters that we'll need mode_validate = Factory.create('mode', 'mode') history_days_validate = Factory.create('history', 'history') int_validate = Factory.create('int', 'int') dict_validate = Factory.create('dict', 'dict') # Filter the input as a dict plan = dict_validate.test(valueToTest) # Use the filters to get the result result = {} result['Id'] = int_validate.test(plan.get('Id')) result['HistoryDays'] = history_days_validate.test( plan.get('HistoryDays')) result['BuyMode'] = mode_validate.test(plan.get('BuyMode')) result['SellMode'] = mode_validate.test(plan.get('SellMode')) return result
def _get_filter_name_from_json(jsonData): return ValidatorFactory.create('string', 'string').test(jsonData.get('filter_name'))
def _get_filters_from_json(jsonData): return ValidatorFactory.create('filter', 'filter').test(jsonData)
def _raiseError(self): raise BadType('', self.fieldName, self.label) class ListValidator(BasicTypeValidator): label = 'list' def __init__(self, fieldName, forbidNone=False): super(ListValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if not super(ListValidator, self)._testForNone(valueToTest): if not isinstance(valueToTest, list): self._raiseError() return valueToTest Factory.register(ListValidator) class DictValidator(BasicTypeValidator): label = 'dict' def __init__(self, fieldName, forbidNone=False): super(DictValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if not super(DictValidator, self)._testForNone(valueToTest): if not isinstance(valueToTest, dict): self._raiseError() return valueToTest Factory.register(DictValidator) class IntegerValidator(BasicTypeValidator):
# Create the filters that we'll need mode_validate = Factory.create('mode', 'mode') history_days_validate = Factory.create('history', 'history') int_validate = Factory.create('int', 'int') dict_validate = Factory.create('dict', 'dict') # Filter the input as a dict plan = dict_validate.test(valueToTest) # Use the filters to get the result result = {} result['Id'] = int_validate.test(plan.get('Id')) result['HistoryDays'] = history_days_validate.test(plan.get('HistoryDays')) result['BuyMode'] = mode_validate.test(plan.get('BuyMode')) result['SellMode'] = mode_validate.test(plan.get('SellMode')) return result Factory.register(PlanValidator) class FilterValidator(BasicTypeValidator): label = 'filter' def __init__(self, fieldName, forbidNone=False): super(FilterValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if valueToTest is None: raise ValidationError("No filter provided") # Create the filters that we will need str_validate = Factory.create('string', 'string') int_validate = Factory.create('int', 'int')
def _get_plan_from_json(jsonData): return ValidatorFactory.create('plan', 'plan').test(jsonData)
class ListValidator(BasicTypeValidator): label = 'list' def __init__(self, fieldName, forbidNone=False): super(ListValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if not super(ListValidator, self)._testForNone(valueToTest): if not isinstance(valueToTest, list): self._raiseError() return valueToTest Factory.register(ListValidator) class DictValidator(BasicTypeValidator): label = 'dict' def __init__(self, fieldName, forbidNone=False): super(DictValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if not super(DictValidator, self)._testForNone(valueToTest): if not isinstance(valueToTest, dict): self._raiseError() return valueToTest
def __init__(self, fieldName, forbidNone=False): super(ModeValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if valueToTest is None: raise ValidationError("No mode provided") # Parse mode to string str_validate = Factory.create('string', 'string') mode = str_validate.test(valueToTest) # Verify that it is a valid value if mode != 'Instant' and mode != 'Bid': raise ValidationError('Mode must be Instant or Bid') return mode Factory.register(ModeValidator) class FeatureValidator(BasicTypeValidator): label = 'feature' def __init__(self, fieldName, forbidNone=False): super(FeatureValidator, self).__init__(fieldName, forbidNone) self.features = ['ItemID', 'ItemType', 'ItemRarity', 'ItemLevel', 'NumBuyOrders', 'NumSellOrders', 'BuyPrice', 'SellPrice', 'ZScoreBuyPrice', 'ZScoreSellPrice', 'MeanBuyPrice', 'MeanSellPrice', 'VarBuyPrice', 'VarSellPrice', 'MedianBuyPrice', 'MedianSellPrice', 'SlopeBuyPrice', 'SlopeSellPrice', 'CurrentFlipProfit', 'MeanProfit', 'VarProfit', 'MedianProfit', 'OurBuyPrice', 'NumConsidered'] def test(self, valueToTest): if valueToTest is None:
history_days_validate = Factory.create('history', 'history') int_validate = Factory.create('int', 'int') dict_validate = Factory.create('dict', 'dict') # Filter the input as a dict plan = dict_validate.test(valueToTest) # Use the filters to get the result result = {} result['Id'] = int_validate.test(plan.get('Id')) result['HistoryDays'] = history_days_validate.test( plan.get('HistoryDays')) result['BuyMode'] = mode_validate.test(plan.get('BuyMode')) result['SellMode'] = mode_validate.test(plan.get('SellMode')) return result Factory.register(PlanValidator) class FilterValidator(BasicTypeValidator): label = 'filter' def __init__(self, fieldName, forbidNone=False): super(FilterValidator, self).__init__(fieldName, forbidNone) def test(self, valueToTest): if valueToTest is None: raise ValidationError("No filter provided") # Create the filters that we will need str_validate = Factory.create('string', 'string') int_validate = Factory.create('int', 'int')