Exemplo n.º 1
0
 def _generate_tests(cls, object, tests):
     for name, schema in object.items():
         tags = normalize_list(schema.pop('tags', []))
         method_name = "test_{}".format(name)
         single_schema = True
         
         if 'params' in schema:
             params = schema['params']
             
             if isinstance(params, (list, tuple)):
                 for index, param_set in enumerate(list(params)):
                     sub_method_name = "{}_{}".format(method_name, index+1)
                     sub_schema = copy.deepcopy(schema)
                     sub_schema['params'] = param_set
                     tests[sub_method_name] = cls._elem_test_method(name, sub_schema)
                     
                     if len(tags):
                         tests[sub_method_name].tags = tags
                 
                 single_schema = False
         
         if single_schema:
             tests[method_name] = cls._elem_test_method(name, copy.deepcopy(schema))
             
             if len(tags):
                 tests[method_name].tags = tags
Exemplo n.º 2
0
 def _generate_field_tests(cls, fields, tests):   
     if fields is None: return
     
     index_map = {}
     
     for field, lookups in fields.items():
         field_info = cls._field_info(field)
         
         tags = normalize_list(lookups.pop('tags', []))
         tags.append('field')
        
         for lookup, search_value in lookups.items():
             info = cls._validation_info(lookup, '@')
             lookup = info['lookup']
             id = "{}_{}".format(field, lookup)
             
             index_map[id] = 1 if id not in index_map else index_map[id] + 1
             
             if isinstance(search_value, (list, tuple, QuerySet)):
                 search_value = list(search_value)
             
             field_method_name = "test_field_{}_{}".format(id, index_map[id])
             values_method_name = "test_field_values_{}_{}".format(id, index_map[id])
             params = [search_value]
             
             tests[field_method_name] = cls._field_test_method(field_info, info, params)
             tests[field_method_name].tags = tags + ['field_test']
             
             tests[values_method_name] = cls._field_values_test_method(field_info, info, params)
             tests[values_method_name].tags = tags + ['values_test']
Exemplo n.º 3
0
    def map(self, validator, base_key, lookup_keys, value, **params):
        lookup_keys = normalize_list(lookup_keys)
        data_pool = self.get_data_value(base_key)
        success = False

        if isinstance(data_pool, (list, QuerySet)):
            for index, element in enumerate(list(data_pool)):
                if self.map(validator, (base_key + [index]),
                            lookup_keys,
                            value,
                            inner=True):
                    success = True

        elif isinstance(data_pool, dict):
            value_key = base_key + [lookup_keys[0]]

            if len(lookup_keys) == 1:
                if self.check(validator, value_key, value):
                    success = True
            else:
                if self.map(validator,
                            value_key,
                            lookup_keys[1:],
                            value,
                            inner=True):
                    success = True

        if not 'inner' in params and not success:
            raise self._wrap_error(
                AssertionError("Value ({}) {} {} keys {}".format(
                    value, validator, base_key, lookup_keys)))

        return success
Exemplo n.º 4
0
 def _generate_ordering_tests(cls, ordering, tests):
     if ordering is None: return
     
     fields = normalize_list(ordering['fields'])
     tags = normalize_list(ordering.pop('tags', []))
     tags.append('ordering')
        
     for field in fields:
         asc_name = 'test_ordering_{}_asc'.format(field)
         info = {'field': field, 'order': 'asc'}
         tests[asc_name] = cls._ordering_test_method(info)
         tests[asc_name].tags = tags + ['asc_test']
         
         desc_name = 'test_ordering_{}_desc'.format(field)
         info = {'field': field, 'order': 'desc'}
         tests[desc_name] = cls._ordering_test_method(info)
         tests[desc_name].tags = tags + ['desc_test']
Exemplo n.º 5
0
    def _generate_ordering_tests(cls, ordering, tests):
        if ordering is None: return

        for field in normalize_list(ordering):
            info = {'field': field, 'order': 'asc'}
            tests['test_ordering_{}_asc'.format(
                field)] = cls._ordering_test_method(info)

            info = {'field': field, 'order': 'desc'}
            tests['test_ordering_{}_desc'.format(
                field)] = cls._ordering_test_method(info)
Exemplo n.º 6
0
 def _generate_request_tests(cls, requests, tests): 
     if requests is None: return
     
     for name, config in requests.items():
         info = cls._validation_info(name, '@')
         method_name = "test_request_{}".format(info['lookup'])
         
         tags = normalize_list(config.pop('tags', []))
         tags.append('request')
        
         tests[method_name] = cls._request_test_method(info, config)
         tests[method_name].tags = tags
Exemplo n.º 7
0
 def _generate_object_tests(cls, object, tests):
     if object is None: return
     
     tags = normalize_list(object.pop('tags', []))
     tags.append('object')
     
     index = 1
         
     for id, params in object.items():
         info = cls._validation_info(id, '&')
         method_name = "test_object_{}".format(index)
         
         tests[method_name] = cls._object_test_method(info, params)
         tests[method_name].tags = tags
         index += 1
Exemplo n.º 8
0
 def _generate_search_tests(cls, search, tests):
     if search is None: return
     
     tags = normalize_list(search.pop('tags', []))
     tags.append('search')
     
     index_map = {}
     
     for name, params in search.items():
         info = cls._validation_info(name, '@')
         lookup = info['lookup']
             
         index_map[lookup] = 1 if lookup not in index_map else index_map[lookup] + 1
         method_name = "test_search_{}_{}".format(lookup, index_map[lookup])
         
         tests[method_name] = cls._search_test_method(info, params)
         tests[method_name].tags = tags
Exemplo n.º 9
0
 def _generate_pagination_tests(cls, pagination, tests):
     if pagination is None: return
     
     tags = normalize_list(pagination.pop('tags', []))
     tags.append('pagination')
     
     index_map = {}
     
     for name, params in pagination.items():
         info = cls._validation_info(name, '@')
         lookup = info['lookup']
         
         index_map[lookup] = 1 if lookup not in index_map else index_map[lookup] + 1
         method_name = "test_pagination_{}_{}".format(lookup, index_map[lookup])
         
         tests[method_name] = cls._pagination_test_method(info, params)
         tests[method_name].tags = tags