|
5 | 5 | from pytest import raises
|
6 | 6 |
|
7 | 7 | def test_repr():
|
8 |
| - max_score = aggs.Max('max_score', field='score') |
9 |
| - a = aggs.A('per_tag', 'terms', field='tags', aggs={'max_score': max_score}) |
| 8 | + max_score = aggs.Max(field='score') |
| 9 | + a = aggs.A('terms', field='tags', aggs={'max_score': max_score}) |
10 | 10 |
|
11 |
| - assert "A('per_tag', 'terms', aggs={'max_score': A('max_score', 'max', field='score')}, field='tags')" == repr(a) |
| 11 | + assert "A('terms', aggs={'max_score': A('max', field='score')}, field='tags')" == repr(a) |
12 | 12 |
|
13 | 13 | def test_A_creates_proper_agg():
|
14 |
| - a = aggs.A('per_tag', 'terms', field='tags') |
| 14 | + a = aggs.A('terms', field='tags') |
15 | 15 |
|
16 | 16 | assert isinstance(a, aggs.Terms)
|
17 | 17 | assert a._params == {'field': 'tags'}
|
18 |
| - assert a._name == 'per_tag' |
19 | 18 |
|
20 | 19 | def test_A_handles_nested_aggs_properly():
|
21 |
| - max_score = aggs.Max('max_score', field='score') |
22 |
| - a = aggs.A('per_tag', 'terms', field='tags', aggs={'max_score': max_score}) |
| 20 | + max_score = aggs.Max(field='score') |
| 21 | + a = aggs.A('terms', field='tags', aggs={'max_score': max_score}) |
23 | 22 |
|
24 | 23 | assert isinstance(a, aggs.Terms)
|
25 | 24 | assert a._params == {'field': 'tags', 'aggs': {'max_score': max_score}}
|
26 |
| - assert a._name == 'per_tag' |
27 | 25 |
|
28 | 26 | def test_A_passes_aggs_through():
|
29 |
| - a = aggs.A('per_tag', 'terms', field='tags') |
| 27 | + a = aggs.A('terms', field='tags') |
30 | 28 | assert aggs.A(a) is a
|
31 | 29 |
|
32 | 30 | def test_A_from_dict():
|
33 | 31 | d = {
|
34 |
| - 'per_tag': { |
35 |
| - 'terms': {'field': 'tags'}, |
36 |
| - 'aggs': {'per_author': {'terms': {'field': 'author.raw'}}}, |
37 |
| - } |
| 32 | + 'terms': {'field': 'tags'}, |
| 33 | + 'aggs': {'per_author': {'terms': {'field': 'author.raw'}}}, |
38 | 34 | }
|
39 | 35 | a = aggs.A(d)
|
40 | 36 |
|
41 | 37 | assert isinstance(a, aggs.Terms)
|
42 |
| - assert a._params == {'field': 'tags', 'aggs': {'per_author': aggs.A('per_author', 'terms', field='author.raw')}} |
43 |
| - assert a._name == 'per_tag' |
44 |
| - assert a['per_author'] == aggs.A('per_author', 'terms', field='author.raw') |
45 |
| - assert a.aggs.per_author == aggs.A('per_author', 'terms', field='author.raw') |
| 38 | + assert a._params == {'field': 'tags', 'aggs': {'per_author': aggs.A('terms', field='author.raw')}} |
| 39 | + assert a['per_author'] == aggs.A('terms', field='author.raw') |
| 40 | + assert a.aggs.per_author == aggs.A('terms', field='author.raw') |
46 | 41 |
|
47 | 42 | def test_A_fails_with_incorrect_dict():
|
48 | 43 | correct_d = {
|
49 |
| - 'per_tag': { |
50 |
| - 'terms': {'field': 'tags'}, |
51 |
| - 'aggs': {'per_author': {'terms': {'field': 'author.raw'}}}, |
52 |
| - } |
| 44 | + 'terms': {'field': 'tags'}, |
| 45 | + 'aggs': {'per_author': {'terms': {'field': 'author.raw'}}}, |
53 | 46 | }
|
54 | 47 |
|
55 | 48 | with raises(Exception):
|
56 | 49 | aggs.A(correct_d, field='f')
|
57 | 50 |
|
58 |
| - with raises(Exception): |
59 |
| - aggs.A(correct_d, 'name') |
60 |
| - |
61 |
| - d = deepcopy(correct_d) |
62 |
| - del d['per_tag']['terms'] |
63 |
| - with raises(Exception): |
64 |
| - aggs.A(d) |
65 |
| - |
66 |
| - d = deepcopy(correct_d) |
67 |
| - d['per_tag']['xx'] = {} |
| 51 | + d = correct_d.copy() |
| 52 | + del d['terms'] |
68 | 53 | with raises(Exception):
|
69 | 54 | aggs.A(d)
|
70 | 55 |
|
71 |
| - d = deepcopy(correct_d) |
| 56 | + d = correct_d.copy() |
72 | 57 | d['xx'] = {}
|
73 | 58 | with raises(Exception):
|
74 | 59 | aggs.A(d)
|
75 | 60 |
|
76 |
| -def test_A_fails_without_agg_type(): |
77 |
| - with raises(Exception): |
78 |
| - aggs.A('name', field='f') |
79 |
| - |
80 |
| -def test_A_fails_with_agg_and_name_or_params(): |
81 |
| - a = aggs.A('per_tag', 'terms', field='tags') |
82 |
| - |
83 |
| - with raises(Exception): |
84 |
| - aggs.A(a, 'name') |
| 61 | +def test_A_fails_with_agg_and_params(): |
| 62 | + a = aggs.A('terms', field='tags') |
85 | 63 |
|
86 | 64 | with raises(Exception):
|
87 | 65 | aggs.A(a, field='score')
|
88 | 66 |
|
89 | 67 | def test_buckets_are_nestable():
|
90 |
| - a = aggs.Terms('per_tag', field='tags') |
| 68 | + a = aggs.Terms(field='tags') |
91 | 69 | b = a.bucket('per_author', 'terms', field='author.raw')
|
92 | 70 |
|
93 | 71 | assert isinstance(b, aggs.Terms)
|
94 | 72 | assert b._params == {'field': 'author.raw'}
|
95 |
| - assert b._name == 'per_author' |
96 | 73 | assert a.aggs == {'per_author': b}
|
97 | 74 |
|
98 | 75 | def test_metric_inside_buckets():
|
99 |
| - a = aggs.Terms('per_tag', field='tags') |
| 76 | + a = aggs.Terms(field='tags') |
100 | 77 | b = a.metric('max_score', 'max', field='score')
|
101 | 78 |
|
102 | 79 | # returns bucket so it's chainable
|
103 | 80 | assert a is b
|
104 |
| - assert a.aggs['max_score'] == aggs.Max('max_score', field='score') |
| 81 | + assert a.aggs['max_score'] == aggs.Max(field='score') |
105 | 82 |
|
106 | 83 | def test_buckets_equals_counts_subaggs():
|
107 |
| - a = aggs.Terms('per_tag', field='tags') |
| 84 | + a = aggs.Terms(field='tags') |
108 | 85 | a.bucket('per_author', 'terms', field='author.raw')
|
109 |
| - b = aggs.Terms('per_tag', field='tags') |
| 86 | + b = aggs.Terms(field='tags') |
110 | 87 |
|
111 | 88 | assert a != b
|
112 | 89 |
|
113 | 90 | def test_buckets_to_dict():
|
114 |
| - a = aggs.Terms('per_tag', field='tags') |
| 91 | + a = aggs.Terms(field='tags') |
115 | 92 | a.bucket('per_author', 'terms', field='author.raw')
|
116 | 93 |
|
117 | 94 | assert {
|
118 |
| - 'per_tag': { |
119 |
| - 'terms': {'field': 'tags'}, |
120 |
| - 'aggs': {'per_author': {'terms': {'field': 'author.raw'}}}, |
121 |
| - } |
| 95 | + 'terms': {'field': 'tags'}, |
| 96 | + 'aggs': {'per_author': {'terms': {'field': 'author.raw'}}}, |
122 | 97 | } == a.to_dict()
|
123 | 98 |
|
124 |
| - a = aggs.Terms('per_tag', field='tags') |
| 99 | + a = aggs.Terms(field='tags') |
125 | 100 | a.metric('max_score', 'max', field='score')
|
126 | 101 |
|
127 | 102 | assert {
|
128 |
| - 'per_tag': { |
129 |
| - 'terms': {'field': 'tags'}, |
130 |
| - 'aggs': {'max_score': {'max': {'field': 'score'}}}, |
131 |
| - } |
| 103 | + 'terms': {'field': 'tags'}, |
| 104 | + 'aggs': {'max_score': {'max': {'field': 'score'}}}, |
132 | 105 | } == a.to_dict()
|
133 | 106 |
|
134 | 107 | def test_nested_buckets_are_reachable_as_getitem():
|
135 |
| - a = aggs.Terms('per_tag', field='tags') |
| 108 | + a = aggs.Terms(field='tags') |
136 | 109 | b = a.bucket('per_author', 'terms', field='author.raw')
|
137 | 110 |
|
138 | 111 | assert a['per_author'] is not b
|
139 | 112 | assert a['per_author'] == b
|
140 | 113 |
|
141 | 114 | def test_nested_buckets_are_settable_as_getitem():
|
142 |
| - a = aggs.Terms('per_tag', field='tags') |
143 |
| - b = a['per_author'] = aggs.A('per_author', 'terms', field='author.raw') |
| 115 | + a = aggs.Terms(field='tags') |
| 116 | + b = a['per_author'] = aggs.A('terms', field='author.raw') |
144 | 117 |
|
145 | 118 | assert a.aggs['per_author'] is b
|
146 | 119 |
|
0 commit comments