UNPKG

1.99 kBPlain TextView Raw
1#!/usr/bin/env python
2# generate the "kitchen sink" tests
3
4import json, random
5
6configs = []
7operators = ['$gt', '$gte', '$eq', '$ne', '$lt', '$lte']
8fields = ['_id', 'rank', 'series', 'debut', 'name']
9
10docs = [
11 {'debut': 1981, 'series': 'mario', '_id': 'mario', 'name': 'mario', 'rank': 5},
12 {'debut': 1996, 'series': 'pokemon', '_id': 'puff', 'name': 'jigglypuff', 'rank': 8},
13 {'debut': 1986, 'series': 'zelda', '_id': 'link', 'name': 'link', 'rank': 10},
14 {'debut': 1981, 'series': 'mario', '_id': 'dk', 'name': 'donkey kong', 'rank': 7},
15 {'debut': 1996, 'series': 'pokemon', '_id': 'pikach', 'name': 'pikach', 'rank': 1},
16 {'debut': 1990, 'series': 'f-zero', '_id': 'falcon', 'name': 'captain falcon', 'rank': 4},
17 {'debut': 1983, 'series': 'mario', '_id': 'luigi', 'name': 'luigi', 'rank': 11},
18 {'debut': 1993, 'series': 'star fox', '_id': 'fox', 'name': 'fox', 'rank': 3},
19 {'debut': 1994, 'series': 'earthbound', '_id': 'ness', 'name': 'ness', 'rank': 9},
20 {'debut': 1986, 'series': 'metroid', '_id': 'samus', 'name': 'samus', 'rank': 12},
21 {'debut': 1990, 'series': 'mario', '_id': 'yoshi', 'name': 'yoshi', 'rank': 6},
22 {'debut': 1992, 'series': 'kirby', '_id': 'kirby', 'name': 'kirby', 'rank': 2}]
23
24def create_random_selector():
25 operator = random.choice(operators)
26 field = random.choice(fields)
27 value = random.choice(docs)[field]
28
29 return {field: {operator: value}}
30
31for i in range(100):
32 num_criteria = random.choice([1, 2, 3, 4]);
33 if num_criteria == 1:
34 selector = create_random_selector()
35 else:
36 selector = {'$and': []}
37 for j in range(num_criteria):
38 selector['$and'].append(create_random_selector())
39
40 num_sort_fields = random.choice([0, 1, 2, 3])
41 sort = []
42 for j in range(num_sort_fields):
43 sort.append(random.choice(fields))
44 sort = list(set(sort))
45 random.shuffle(sort)
46
47 config = {'selector': selector}
48 if (len(sort) > 0):
49 config['sort'] = sort
50 configs.append(config);
51
52print json.dumps(configs)