author | ymh <ymh.work@gmail.com> |
Mon, 12 Jun 2017 14:53:59 +0200 | |
changeset 537 | d2e6ee099125 |
parent 407 | 2dba812c7ef2 |
permissions | -rw-r--r-- |
308
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
|
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
class GeoStatsControllerTest extends TestCase |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
{ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
public function testGetIndex() |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
{ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
$query = [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
'index' => env('ELASTICSEARCH_INDEX'), |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
'body' => [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
"size" => 0, |
320 | 11 |
"query" => [ |
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
387
diff
changeset
|
12 |
'match_all' => (object) null |
320 | 13 |
], |
308
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
"aggs" => [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
"geos" => [ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
"terms" => [ |
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
387
diff
changeset
|
17 |
"size" => 2147483647, |
308
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
"field" => "geonames_hierarchy" |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
]; |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
|
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
Es::shouldReceive('search') |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
->once() |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
->with($query) |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
->andReturn(json_decode("{ |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
\"took\" : 17, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
\"timed_out\" : false, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
\"_shards\" : { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
\"total\" : 1, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
\"successful\" : 1, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
\"failed\" : 0 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
}, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
\"hits\" : { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
\"total\" : 3011, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
\"max_score\" : 0.0, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
\"hits\" : [ ] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
}, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
\"aggregations\" : { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
\"geos\" : { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
\"doc_count_error_upper_bound\" : 0, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
\"sum_other_doc_count\" : 0, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
\"buckets\" : [ { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
\"key\" : 6255148, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
\"doc_count\" : 2684 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
}, { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
\"key\" : 3017382, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
\"doc_count\" : 2674 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
}, { |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
\"key\" : 3027939, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
\"doc_count\" : 851 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
} ] |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
} |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
} |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
}", true)); |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
|
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
59 |
$response = $this->get('/api/v1/stats/geostats/'); |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
60 |
$response |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
61 |
->assertStatus(200) |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
62 |
->assertJson(["geostats" => [ |
308
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
'6255148' => 2684, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
'3017382' => 2674, |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
'3027939' => 851 |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
]]); |
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
} |
320 | 68 |
|
69 |
||
70 |
public function testGetIndexEarth() |
|
71 |
{ |
|
72 |
$query = [ |
|
73 |
'index' => env('ELASTICSEARCH_INDEX'), |
|
74 |
'body' => [ |
|
75 |
"size" => 0, |
|
76 |
"query" => [ |
|
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
387
diff
changeset
|
77 |
'match_all' => (object) null |
320 | 78 |
], |
79 |
"aggs" => [ |
|
80 |
"geos" => [ |
|
81 |
"terms" => [ |
|
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
387
diff
changeset
|
82 |
"size" => 2147483647, |
320 | 83 |
"field" => "geonames_hierarchy" |
84 |
] |
|
85 |
] |
|
86 |
] |
|
87 |
] |
|
88 |
]; |
|
89 |
||
90 |
Es::shouldReceive('search') |
|
91 |
->once() |
|
92 |
->with($query) |
|
93 |
->andReturn(json_decode("{ |
|
94 |
\"took\" : 17, |
|
95 |
\"timed_out\" : false, |
|
96 |
\"_shards\" : { |
|
97 |
\"total\" : 1, |
|
98 |
\"successful\" : 1, |
|
99 |
\"failed\" : 0 |
|
100 |
}, |
|
101 |
\"hits\" : { |
|
102 |
\"total\" : 3011, |
|
103 |
\"max_score\" : 0.0, |
|
104 |
\"hits\" : [ ] |
|
105 |
}, |
|
106 |
\"aggregations\" : { |
|
107 |
\"geos\" : { |
|
108 |
\"doc_count_error_upper_bound\" : 0, |
|
109 |
\"sum_other_doc_count\" : 0, |
|
110 |
\"buckets\" : [] |
|
111 |
} |
|
112 |
} |
|
113 |
}", true)); |
|
114 |
||
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
115 |
$response = $this->get('/api/v1/stats/geostats/?area='.config('corpusparole.geonames_earth_geonamesid')); |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
116 |
$response->assertStatus(200); |
320 | 117 |
} |
118 |
||
119 |
||
120 |
public function testGetIndexArea() |
|
121 |
{ |
|
387 | 122 |
|
320 | 123 |
$query = [ |
387 | 124 |
"index" => env('ELASTICSEARCH_INDEX'), |
125 |
"body" => [ |
|
320 | 126 |
"size" => 0, |
127 |
"query" => [ |
|
387 | 128 |
"constant_score" => [ |
129 |
"filter" => [ |
|
130 |
"bool" => [ |
|
131 |
"must" => [ [ |
|
132 |
"term" => [ "geonames_hierarchy" => "code_area" ] |
|
133 |
] ] |
|
134 |
] |
|
135 |
] |
|
320 | 136 |
] |
137 |
], |
|
138 |
"aggs" => [ |
|
139 |
"geos" => [ |
|
140 |
"terms" => [ |
|
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
387
diff
changeset
|
141 |
"size" => 2147483647, |
320 | 142 |
"field" => "geonames_hierarchy" |
143 |
] |
|
144 |
] |
|
145 |
] |
|
146 |
] |
|
147 |
]; |
|
148 |
||
149 |
Es::shouldReceive('search') |
|
150 |
->once() |
|
151 |
->with($query) |
|
152 |
->andReturn(json_decode("{ |
|
153 |
\"took\" : 17, |
|
154 |
\"timed_out\" : false, |
|
155 |
\"_shards\" : { |
|
156 |
\"total\" : 1, |
|
157 |
\"successful\" : 1, |
|
158 |
\"failed\" : 0 |
|
159 |
}, |
|
160 |
\"hits\" : { |
|
161 |
\"total\" : 3011, |
|
162 |
\"max_score\" : 0.0, |
|
163 |
\"hits\" : [ ] |
|
164 |
}, |
|
165 |
\"aggregations\" : { |
|
166 |
\"geos\" : { |
|
167 |
\"doc_count_error_upper_bound\" : 0, |
|
168 |
\"sum_other_doc_count\" : 0, |
|
169 |
\"buckets\" : [] |
|
170 |
} |
|
171 |
} |
|
172 |
}", true)); |
|
173 |
||
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
174 |
$response = $this->get('/api/v1/stats/geostats/?area=code_area'); |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
175 |
$response->assertStatus(200); |
320 | 176 |
} |
177 |
||
308
e032d686d88e
add hierarchy info in document indexation + geostats api controllers + add some keys to geonames resolver
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
178 |
} |