esp_sdk 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +6 -1
  4. data/Gemfile.lock +11 -1
  5. data/README.md +287 -28
  6. data/bin/esp +15 -0
  7. data/esp_sdk.gemspec +2 -0
  8. data/lib/esp/aws_clients.rb +60 -0
  9. data/lib/esp/commands/add_external_account.rb +57 -0
  10. data/lib/esp/commands/commands_tasks.rb +106 -0
  11. data/lib/esp/commands/console.rb +68 -0
  12. data/lib/esp/extensions/active_resource/formats/json_api_format.rb +12 -4
  13. data/lib/esp/extensions/active_resource/paginated_collection.rb +5 -5
  14. data/lib/esp/extensions/active_resource/validations.rb +1 -1
  15. data/lib/esp/external_account_creator.rb +77 -0
  16. data/lib/esp/resources/alert.rb +30 -34
  17. data/lib/esp/resources/cloud_trail_event.rb +5 -0
  18. data/lib/esp/resources/contact_request.rb +6 -5
  19. data/lib/esp/resources/custom_signature.rb +32 -56
  20. data/lib/esp/resources/dashboard.rb +8 -1
  21. data/lib/esp/resources/external_account.rb +27 -19
  22. data/lib/esp/resources/organization.rb +27 -3
  23. data/lib/esp/resources/region.rb +15 -3
  24. data/lib/esp/resources/report.rb +28 -24
  25. data/lib/esp/resources/resource.rb +26 -10
  26. data/lib/esp/resources/service.rb +5 -0
  27. data/lib/esp/resources/signature.rb +28 -12
  28. data/lib/esp/resources/stat.rb +21 -2
  29. data/lib/esp/resources/stat_custom_signature.rb +30 -4
  30. data/lib/esp/resources/stat_region.rb +29 -3
  31. data/lib/esp/resources/stat_service.rb +29 -3
  32. data/lib/esp/resources/stat_signature.rb +29 -3
  33. data/lib/esp/resources/sub_organization.rb +27 -3
  34. data/lib/esp/resources/suppression/region.rb +14 -32
  35. data/lib/esp/resources/suppression/signature.rb +14 -40
  36. data/lib/esp/resources/suppression/unique_identifier.rb +8 -6
  37. data/lib/esp/resources/suppression.rb +43 -5
  38. data/lib/esp/resources/tag.rb +5 -0
  39. data/lib/esp/resources/team.rb +33 -9
  40. data/lib/esp/resources/user.rb +29 -3
  41. data/lib/esp/version.rb +1 -1
  42. data/lib/esp.rb +25 -5
  43. data/test/esp/aws_clients_test.rb +101 -0
  44. data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +26 -12
  45. data/test/esp/extensions/active_resource/paginated_collection_test.rb +93 -72
  46. data/test/esp/extensions/active_resource/validations_test.rb +2 -12
  47. data/test/esp/external_account_creator_test.rb +153 -0
  48. data/test/esp/resources/alert_test.rb +71 -33
  49. data/test/esp/resources/cloud_trail_event_test.rb +9 -1
  50. data/test/esp/resources/contact_request_test.rb +8 -0
  51. data/test/esp/resources/custom_signature_test.rb +8 -0
  52. data/test/esp/resources/dashboard_test.rb +8 -0
  53. data/test/esp/resources/external_account_test.rb +8 -0
  54. data/test/esp/resources/metadata_test.rb +1 -1
  55. data/test/esp/resources/organization_test.rb +8 -0
  56. data/test/esp/resources/region_test.rb +12 -4
  57. data/test/esp/resources/report_test.rb +13 -4
  58. data/test/esp/resources/resource_test.rb +208 -64
  59. data/test/esp/resources/service_test.rb +8 -0
  60. data/test/esp/resources/signature_test.rb +15 -9
  61. data/test/esp/resources/stat_custom_signature_test.rb +9 -1
  62. data/test/esp/resources/stat_region_test.rb +23 -1
  63. data/test/esp/resources/stat_service_test.rb +23 -1
  64. data/test/esp/resources/stat_signature_test.rb +23 -1
  65. data/test/esp/resources/stat_test.rb +52 -8
  66. data/test/esp/resources/sub_organization_test.rb +8 -0
  67. data/test/esp/resources/suppression/region_test.rb +10 -2
  68. data/test/esp/resources/suppression/signature_test.rb +10 -2
  69. data/test/esp/resources/suppression/unique_identifier_test.rb +10 -2
  70. data/test/esp/resources/suppression_test.rb +74 -14
  71. data/test/esp/resources/tag_test.rb +9 -1
  72. data/test/esp/resources/team_test.rb +8 -0
  73. data/test/esp/resources/user_test.rb +49 -19
  74. data/test/esp_test.rb +19 -1
  75. data/test/factories/alerts.rb +70 -0
  76. data/test/factories/organizations.rb +2 -2
  77. data/test/factories/regions.rb +1 -1
  78. data/test/factories/sub_organizations.rb +1 -1
  79. data/test/factories/suppressions.rb +109 -3
  80. data/test/factories/users.rb +65 -2
  81. data/test/test_helper.rb +9 -8
  82. metadata +41 -69
  83. data/bin/esp_console +0 -67
  84. data/rdoc/ActiveResource/Formats.html +0 -178
  85. data/rdoc/ActiveResource/PaginatedCollection.html +0 -912
  86. data/rdoc/ActiveResource.html +0 -182
  87. data/rdoc/ESP/Alert.html +0 -808
  88. data/rdoc/ESP/CloudTrailEvent.html +0 -377
  89. data/rdoc/ESP/ContactRequest.html +0 -368
  90. data/rdoc/ESP/CustomSignature.html +0 -748
  91. data/rdoc/ESP/Dashboard.html +0 -357
  92. data/rdoc/ESP/ExternalAccount.html +0 -567
  93. data/rdoc/ESP/Metadata.html +0 -411
  94. data/rdoc/ESP/Organization.html +0 -592
  95. data/rdoc/ESP/Region.html +0 -401
  96. data/rdoc/ESP/Report.html +0 -624
  97. data/rdoc/ESP/Service.html +0 -382
  98. data/rdoc/ESP/Signature.html +0 -557
  99. data/rdoc/ESP/Stat.html +0 -1780
  100. data/rdoc/ESP/StatCustomSignature.html +0 -1601
  101. data/rdoc/ESP/StatRegion.html +0 -1600
  102. data/rdoc/ESP/StatService.html +0 -1600
  103. data/rdoc/ESP/StatSignature.html +0 -1600
  104. data/rdoc/ESP/SubOrganization.html +0 -542
  105. data/rdoc/ESP/Suppression/Region.html +0 -456
  106. data/rdoc/ESP/Suppression/Signature.html +0 -472
  107. data/rdoc/ESP/Suppression/UniqueIdentifier.html +0 -419
  108. data/rdoc/ESP/Suppression.html +0 -651
  109. data/rdoc/ESP/Tag.html +0 -373
  110. data/rdoc/ESP/Team.html +0 -586
  111. data/rdoc/ESP/User.html +0 -485
  112. data/rdoc/ESP.html +0 -549
  113. data/rdoc/README_md.html +0 -503
  114. data/rdoc/created.rid +0 -31
  115. data/rdoc/images/add.png +0 -0
  116. data/rdoc/images/arrow_up.png +0 -0
  117. data/rdoc/images/brick.png +0 -0
  118. data/rdoc/images/brick_link.png +0 -0
  119. data/rdoc/images/bug.png +0 -0
  120. data/rdoc/images/bullet_black.png +0 -0
  121. data/rdoc/images/bullet_toggle_minus.png +0 -0
  122. data/rdoc/images/bullet_toggle_plus.png +0 -0
  123. data/rdoc/images/date.png +0 -0
  124. data/rdoc/images/delete.png +0 -0
  125. data/rdoc/images/find.png +0 -0
  126. data/rdoc/images/loadingAnimation.gif +0 -0
  127. data/rdoc/images/macFFBgHack.png +0 -0
  128. data/rdoc/images/package.png +0 -0
  129. data/rdoc/images/page_green.png +0 -0
  130. data/rdoc/images/page_white_text.png +0 -0
  131. data/rdoc/images/page_white_width.png +0 -0
  132. data/rdoc/images/plugin.png +0 -0
  133. data/rdoc/images/ruby.png +0 -0
  134. data/rdoc/images/tag_blue.png +0 -0
  135. data/rdoc/images/tag_green.png +0 -0
  136. data/rdoc/images/transparent.png +0 -0
  137. data/rdoc/images/wrench.png +0 -0
  138. data/rdoc/images/wrench_orange.png +0 -0
  139. data/rdoc/images/zoom.png +0 -0
  140. data/rdoc/index.html +0 -136
  141. data/rdoc/js/darkfish.js +0 -155
  142. data/rdoc/js/jquery.js +0 -4
  143. data/rdoc/js/navigation.js +0 -142
  144. data/rdoc/js/search.js +0 -94
  145. data/rdoc/js/search_index.js +0 -1
  146. data/rdoc/js/searcher.js +0 -228
  147. data/rdoc/rdoc.css +0 -595
  148. data/rdoc/table_of_contents.html +0 -942
@@ -39,14 +39,6 @@ module ESP
39
39
  end
40
40
  end
41
41
 
42
- context '.where' do
43
- should 'not be implemented yet' do
44
- assert_raise ESP::NotImplementedError do
45
- ESP::Team.where(id: 1)
46
- end
47
- end
48
- end
49
-
50
42
  context '#serializable_hash' do
51
43
  should 'format per json api standard' do
52
44
  t = build(:team)
@@ -101,90 +93,242 @@ module ESP
101
93
  assert_equal({ "0" => "3", "1" => "4" }, query['filter']['id_in'])
102
94
  end
103
95
  end
104
- end
105
96
 
106
- should 'not put page parameter inside filter parameter' do
107
- stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
97
+ should 'not put page parameter inside filter parameter' do
98
+ stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
108
99
 
109
- ESP::Team.find(:all, params: { id: 3, page: { number: 2, size: 3 } })
100
+ ESP::Team.find(:all, params: { id: 3, page: { number: 2, size: 3 } })
110
101
 
111
- assert_requested(:get, /teams.json*/) do |req|
112
- query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
113
- assert_equal true, query.key?('filter')
114
- assert_equal '2', query['page']['number']
102
+ assert_requested(:get, /teams.json*/) do |req|
103
+ query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
104
+ assert_equal true, query.key?('filter')
105
+ assert_equal '2', query['page']['number']
106
+ end
115
107
  end
116
- end
117
108
 
118
- should 'add the include option to param' do
119
- stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
109
+ should 'add the include option to param' do
110
+ stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
120
111
 
121
- ESP::Team.find(:all, include: 'organization')
112
+ ESP::Team.find(:all, include: 'organization')
122
113
 
123
- assert_requested(:get, /teams.json*/) do |req|
124
- query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
125
- assert_equal true, query.key?('include')
126
- assert_equal 'organization', query['include']
114
+ assert_requested(:get, /teams.json*/) do |req|
115
+ query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
116
+ assert_equal true, query.key?('include')
117
+ assert_equal 'organization', query['include']
118
+ end
127
119
  end
128
- end
129
120
 
130
- should 'add the include option to param when finding by id' do
131
- stub_request(:get, %r{teams/2.json*}).to_return(body: json_list(:team, 2))
121
+ should 'add the include option to param when finding by id' do
122
+ stub_request(:get, %r{teams/2.json*}).to_return(body: json_list(:team, 2))
132
123
 
133
- ESP::Team.find(2, include: 'organization')
124
+ ESP::Team.find(2, include: 'organization')
134
125
 
135
- assert_requested(:get, %r{teams/2.json*}) do |req|
136
- query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
137
- assert_equal true, query.key?('include')
138
- assert_equal 'organization', query['include']
126
+ assert_requested(:get, %r{teams/2.json*}) do |req|
127
+ query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
128
+ assert_equal true, query.key?('include')
129
+ assert_equal 'organization', query['include']
130
+ end
139
131
  end
140
- end
141
132
 
142
- should 'not ransackize the filter parameter if it is passed' do
143
- stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
133
+ should 'not ransackize the filter parameter if it is passed' do
134
+ stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
144
135
 
145
- ESP::Team.find(:all, params: { filter: { id_eq: 3 }, page: { number: 2, size: 3 } })
136
+ ESP::Team.find(:all, params: { filter: { id_eq: 3 }, page: { number: 2, size: 3 } })
146
137
 
147
- assert_requested(:get, /teams.json*/) do |req|
148
- query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
149
- assert_equal true, query.key?('filter')
150
- assert_equal true, query['filter'].key?('id_eq')
138
+ assert_requested(:get, /teams.json*/) do |req|
139
+ query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
140
+ assert_equal true, query.key?('filter')
141
+ assert_equal true, query['filter'].key?('id_eq')
142
+ end
151
143
  end
152
- end
153
144
 
154
- should 'add the from attribute to PaginatedCollection objects when from is supplied' do
155
- stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
145
+ should 'add the from attribute to PaginatedCollection objects when from is supplied' do
146
+ stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
156
147
 
157
- teams = ESP::Team.find(:all, from: "#{Team.prefix}teams.json", params: { filter: { id_eq: 3 }, page: { number: 2, size: 3 } })
148
+ teams = ESP::Team.find(:all, from: "#{Team.prefix}teams.json", params: { filter: { id_eq: 3 }, page: { number: 2, size: 3 } })
158
149
 
159
- assert_equal '/api/v2/teams.json', teams.from
150
+ assert_equal '/api/v2/teams.json', teams.from
151
+ end
160
152
  end
161
- end
162
153
 
163
- context 'live calls' do
164
- setup do
165
- skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
166
- WebMock.allow_net_connect!
167
- @team = ESP::Team.last
168
- skip "Live DB does not have any teams. Add a team and run tests again." if @team.blank?
169
- end
154
+ context '.where' do
155
+ should 'call the index method when finding by single id using put' do
156
+ stub_request(:put, /teams.json/).to_return(body: json_list(:team, 1))
157
+
158
+ ESP::Team.where(id: 3)
159
+
160
+ assert_requested(:put, /teams.json/)
161
+ end
162
+
163
+ should 'build body inside filter param and ad _eq when single value' do
164
+ stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
165
+
166
+ ESP::Team.where(id: 3)
167
+
168
+ assert_requested(:put, /teams.json*/) do |req|
169
+ body = JSON.parse req.body
170
+ assert_equal true, body.key?('filter')
171
+ assert_equal true, body['filter'].key?('id_eq')
172
+ assert_equal 3, body['filter']['id_eq']
173
+ end
174
+ end
175
+
176
+ should 'build body inside filter param and ad _in when multiple values' do
177
+ stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
178
+
179
+ ESP::Team.where(id: [3, 4])
180
+
181
+ assert_requested(:put, /teams.json*/) do |req|
182
+ body = JSON.parse req.body
183
+ assert_equal true, body.key?('filter')
184
+ assert_equal true, body['filter'].key?('id_in')
185
+ assert_equal([3, 4], body['filter']['id_in'])
186
+ end
187
+ end
170
188
 
171
- teardown do
172
- WebMock.disable_net_connect!
189
+ should 'not put page parameter inside filter parameter' do
190
+ stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
191
+
192
+ ESP::Team.where(id: 3, page: { number: 2, size: 3 })
193
+
194
+ assert_requested(:put, /teams.json*/) do |req|
195
+ body = JSON.parse req.body
196
+ assert_equal true, body.key?('filter')
197
+ assert_equal 2, body['page']['number']
198
+ end
199
+ end
200
+
201
+ should 'add the include option to param' do
202
+ stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
203
+
204
+ ESP::Team.where(id: 1, include: 'organization')
205
+
206
+ assert_requested(:put, /teams.json*/) do |req|
207
+ body = JSON.parse req.body
208
+ assert_equal true, body.key?('include')
209
+ assert_equal 'organization', body['include']
210
+ end
211
+ end
212
+
213
+ should 'add the sorts option to the params' do
214
+ stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
215
+
216
+ ESP::Team.where(name_cont: 'Team', sorts: 'created_at')
217
+
218
+ assert_requested(:put, /teams.json*/) do |req|
219
+ body = JSON.parse req.body
220
+ assert_equal true, body.key?('filter')
221
+ assert_equal 'Team', body['filter']['name_cont']
222
+ assert_equal 'created_at', body['filter']['sorts']
223
+ end
224
+ end
225
+
226
+ should 'add the combinator option to the params' do
227
+ stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
228
+
229
+ ESP::Team.where(name_cont: 'Team', id_eq: 3, m: :or)
230
+
231
+ assert_requested(:put, /teams.json*/) do |req|
232
+ body = JSON.parse req.body
233
+ assert_equal true, body.key?('filter')
234
+ assert_equal 'Team', body['filter']['name_cont']
235
+ assert_equal 3, body['filter']['id_eq']
236
+ assert_equal 'or', body['filter']['m']
237
+ end
238
+ end
239
+
240
+ should 'add _eq to attribute if predicate is not already appended' do
241
+ stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
242
+
243
+ ESP::Team.where(id: 3)
244
+
245
+ assert_requested(:put, /teams.json*/) do |req|
246
+ body = JSON.parse req.body
247
+ assert_equal true, body.key?('filter')
248
+ assert_equal true, body['filter'].key?("id_eq")
249
+ end
250
+ end
251
+
252
+ should 'add _in to array attribute if predicate is not already appended' do
253
+ stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
254
+
255
+ ESP::Team.where(id: [3])
256
+
257
+ assert_requested(:put, /teams.json*/) do |req|
258
+ body = JSON.parse req.body
259
+ assert_equal true, body.key?('filter')
260
+ assert_equal true, body['filter'].key?("id_in")
261
+ end
262
+ end
263
+
264
+ ESP::Resource::PREDICATES.split('|').each do |predicate|
265
+ next if predicate == 'm' # This is a special case
266
+ should "not ransackize attributes that already have ransack predicate #{predicate} appended" do
267
+ stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
268
+
269
+ args = { page: { number: 2, size: 3 } }
270
+ args["id_#{predicate}"] = 3
271
+ ESP::Team.where(args)
272
+
273
+ assert_requested(:put, /teams.json*/) do |req|
274
+ body = JSON.parse req.body
275
+ assert_equal true, body.key?('filter')
276
+ assert_equal true, body['filter'].key?("id_#{predicate}")
277
+ end
278
+ end
279
+ end
173
280
  end
174
281
 
175
- context 'with ESP::Team' do
176
- should 'find a team' do
177
- t = ESP::Team.find(@team.id)
282
+ context 'live calls' do
283
+ setup do
284
+ skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
285
+ WebMock.allow_net_connect!
286
+ @team = ESP::Team.last
287
+ skip "Live DB does not have any teams. Add a team and run tests again." if @team.blank?
288
+ end
178
289
 
179
- assert_equal ESP::Team, t.class
180
- assert_equal @team.id, t.id
290
+ teardown do
291
+ WebMock.disable_net_connect!
181
292
  end
182
293
 
183
- should 'find teams' do
184
- t = ESP::Team.find(:all, params: { id: @team.id })
294
+ context 'with ESP::Team' do
295
+ context '.find' do
296
+ should 'find a team' do
297
+ t = ESP::Team.find(@team.id)
298
+
299
+ assert_equal ESP::Team, t.class
300
+ assert_equal @team.id, t.id
301
+ end
302
+
303
+ should 'find teams' do
304
+ t = ESP::Team.find(:all, params: { id: @team.id })
305
+
306
+ assert_equal ESP::Team, t.resource_class
307
+ assert_equal 1, t.count
308
+ end
309
+ end
310
+
311
+ context '.where' do
312
+ should 'return teams' do
313
+ teams = ESP::Team.where(id: @team.id)
185
314
 
186
- assert_equal ESP::Team, t.resource_class
187
- assert_equal 1, t.count
315
+ assert_equal ESP::Team, teams.resource_class
316
+ assert_equal 1, teams.count
317
+ end
318
+
319
+ should 'return included object on first call' do
320
+ teams = ESP::Team.where(id: @team.id, include: 'organization')
321
+
322
+ assert_equal ESP::Organization, teams.first.attributes['organization'].class
323
+ end
324
+
325
+ should 'return multiple included objects on first call' do
326
+ teams = ESP::Team.where(id: @team.id, include: 'sub_organization, organization')
327
+
328
+ assert_equal ESP::Organization, teams.first.attributes['organization'].class
329
+ assert_equal ESP::SubOrganization, teams.first.attributes['sub_organization'].class
330
+ end
331
+ end
188
332
  end
189
333
  end
190
334
  end
@@ -4,6 +4,14 @@ module ESP
4
4
  class ServiceTest < ActiveSupport::TestCase
5
5
  context ESP::Service do
6
6
  context '#signatures' do
7
+ context '.where' do
8
+ should 'not be implemented' do
9
+ assert_raises ESP::NotImplementedError do
10
+ Tag.where(id_eq: 2)
11
+ end
12
+ end
13
+ end
14
+
7
15
  should 'call the api' do
8
16
  s = build(:service)
9
17
  stub_request(:get, /signatures.json*/).to_return(body: json_list(:signature, 2))
@@ -123,6 +123,8 @@ module ESP
123
123
  setup do
124
124
  skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
125
125
  WebMock.allow_net_connect!
126
+ @signature = ESP::Signature.where(name_cont: 'heartbleed').last
127
+ skip "Live DB does not have any signatures. Add a signature and run tests again." if @signature.blank?
126
128
  end
127
129
 
128
130
  teardown do
@@ -131,32 +133,36 @@ module ESP
131
133
 
132
134
  context '#service' do
133
135
  should 'return a service' do
134
- signature = ESP::Signature.first
136
+ service = @signature.service
135
137
 
136
- service = signature.service
137
-
138
- assert_equal signature.service_id, service.id
138
+ assert_equal @signature.service_id, service.id
139
139
  assert_equal ESP::Service, service.class
140
140
  end
141
141
  end
142
142
 
143
143
  context '#run' do
144
144
  should 'return alerts' do
145
- signature = ESP::Signature.first
146
145
  external_account_id = ESP::ExternalAccount.last.id
147
146
 
148
- alerts = signature.run(external_account_id: external_account_id, region: 'us_east_1')
147
+ alerts = @signature.run(external_account_id: external_account_id, region: 'us_east_1')
149
148
 
150
149
  assert_equal ESP::Alert, alerts.resource_class
151
150
  end
152
151
 
153
152
  should 'return errors' do
154
- signature = ESP::Signature.first
155
153
  external_account_id = 999_999_999_999
156
154
 
157
- signature = signature.run(external_account_id: external_account_id, region: 'us_east_1')
155
+ @signature.run(external_account_id: external_account_id, region: 'us_east_1')
156
+
157
+ assert_equal "Couldn't find ExternalAccount", @signature.errors.full_messages.first
158
+ end
159
+ end
160
+
161
+ context '.where' do
162
+ should 'return signature objects' do
163
+ signatures = ESP::Signature.where(id_eq: @signature.id)
158
164
 
159
- assert_equal "Couldn't find ExternalAccount", signature.errors.full_messages.first
165
+ assert_equal ESP::Signature, signatures.resource_class
160
166
  end
161
167
  end
162
168
 
@@ -5,6 +5,14 @@ module ESP
5
5
  class CustomSignatureTest < ActiveSupport::TestCase
6
6
  context ESP::StatCustomSignature do
7
7
  context '.for_stat' do
8
+ context '.where' do
9
+ should 'not be implemented' do
10
+ assert_raises ESP::NotImplementedError do
11
+ StatCustomSignature.where(id_eq: 2)
12
+ end
13
+ end
14
+ end
15
+
8
16
  should 'throw an error if stat id is not supplied' do
9
17
  error = assert_raises ArgumentError do
10
18
  ESP::StatCustomSignature.for_stat
@@ -100,7 +108,7 @@ module ESP
100
108
 
101
109
  context '.for_stat' do
102
110
  should 'return tags for stat id' do
103
- report = ESP::Report.find(:first, params: { status: 'complete' })
111
+ report = ESP::Report.find(:first, params: { id_eq: 1 })
104
112
  skip "make sure you have a complete report" unless report.present?
105
113
  stat_id = report.stat.id
106
114
  stats = ESP::StatCustomSignature.for_stat(stat_id)
@@ -4,6 +4,14 @@ module ESP
4
4
  class Stat
5
5
  class RegionTest < ActiveSupport::TestCase
6
6
  context ESP::StatRegion do
7
+ context '.where' do
8
+ should 'not be implemented' do
9
+ assert_raises ESP::NotImplementedError do
10
+ StatRegion.where(id_eq: 2)
11
+ end
12
+ end
13
+ end
14
+
7
15
  context '.for_stat' do
8
16
  should 'throw an error if stat id is not supplied' do
9
17
  error = assert_raises ArgumentError do
@@ -97,9 +105,23 @@ module ESP
97
105
  WebMock.disable_net_connect!
98
106
  end
99
107
 
108
+ context '#regions' do
109
+ should 'return regions' do
110
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
111
+ skip "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
112
+ stat = ESP::Stat.for_report(report.id)
113
+ regions = stat.regions
114
+
115
+ region = regions.first.region
116
+
117
+ assert_equal ESP::Region, region.class
118
+ assert_equal regions.first.region.code, region.code
119
+ end
120
+ end
121
+
100
122
  context '.for_stat' do
101
123
  should 'return tags for stat id' do
102
- report = ESP::Report.find(:first, params: { status: 'complete' })
124
+ report = ESP::Report.find(:first, params: { id_eq: 1 })
103
125
  skip "make sure you have a complete report" unless report.present?
104
126
  stat_id = report.stat.id
105
127
  stats = ESP::StatRegion.for_stat(stat_id)
@@ -4,6 +4,14 @@ module ESP
4
4
  class Stat
5
5
  class ServiceTest < ActiveSupport::TestCase
6
6
  context ESP::StatService do
7
+ context '.where' do
8
+ should 'not be implemented' do
9
+ assert_raises ESP::NotImplementedError do
10
+ StatService.where(id_eq: 2)
11
+ end
12
+ end
13
+ end
14
+
7
15
  context '.for_stat' do
8
16
  should 'throw an error if stat id is not supplied' do
9
17
  error = assert_raises ArgumentError do
@@ -97,9 +105,23 @@ module ESP
97
105
  WebMock.disable_net_connect!
98
106
  end
99
107
 
108
+ context '#services' do
109
+ should 'return signatures' do
110
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
111
+ skip "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
112
+ stat = ESP::Stat.for_report(report.id)
113
+ services = stat.services
114
+
115
+ service = services.first.service
116
+
117
+ assert_equal ESP::Service, service.class
118
+ assert_equal services.first.service.name, service.name
119
+ end
120
+ end
121
+
100
122
  context '.for_stat' do
101
123
  should 'return tags for stat id' do
102
- report = ESP::Report.find(:first, params: { status: 'complete' })
124
+ report = ESP::Report.find(:first, params: { id_eq: 1 })
103
125
  skip "make sure you have a complete report" unless report.present?
104
126
  stat_id = report.stat.id
105
127
  stats = ESP::StatService.for_stat(stat_id)
@@ -4,6 +4,14 @@ module ESP
4
4
  class Stat
5
5
  class SignatureTest < ActiveSupport::TestCase
6
6
  context ESP::StatSignature do
7
+ context '.where' do
8
+ should 'not be implemented' do
9
+ assert_raises ESP::NotImplementedError do
10
+ StatSignature.where(id_eq: 2)
11
+ end
12
+ end
13
+ end
14
+
7
15
  context '.for_stat' do
8
16
  should 'throw an error if stat id is not supplied' do
9
17
  error = assert_raises ArgumentError do
@@ -98,9 +106,23 @@ module ESP
98
106
  WebMock.disable_net_connect!
99
107
  end
100
108
 
109
+ context '#signatures' do
110
+ should 'return signatures' do
111
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
112
+ skip "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
113
+ stat = ESP::Stat.for_report(report.id)
114
+ signatures = stat.signatures
115
+
116
+ signature = signatures.first.signature
117
+
118
+ assert_equal ESP::Signature, signature.class
119
+ assert_equal signatures.first.signature.name, signature.name
120
+ end
121
+ end
122
+
101
123
  context '.for_stat' do
102
124
  should 'return tags for stat id' do
103
- report = ESP::Report.find(:first, params: { status: 'complete' })
125
+ report = ESP::Report.find(:first, params: { id_eq: 1 })
104
126
  skip "make sure you have a complete report" unless report.present?
105
127
  stat_id = report.stat.id
106
128
  stats = ESP::StatSignature.for_stat(stat_id)
@@ -3,6 +3,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
3
3
  module ESP
4
4
  class StatTest < ActiveSupport::TestCase
5
5
  context ESP::Stat do
6
+ context '.where' do
7
+ should 'not be implemented' do
8
+ assert_raises ESP::NotImplementedError do
9
+ Stat.where(id_eq: 2)
10
+ end
11
+ end
12
+ end
13
+
6
14
  context '#report' do
7
15
  should 'call the api' do
8
16
  stat = build(:stat, report_id: 3)
@@ -127,22 +135,58 @@ module ESP
127
135
  setup do
128
136
  skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
129
137
  WebMock.allow_net_connect!
130
- @team = ESP::Team.last
131
- skip "Live DB does not have any teams. Add a team and run tests again." if @team.blank?
138
+ @report = ESP::Report.all.detect { |r| r.status == 'complete' }
139
+ skip "Live DB does not have any reports. Add a report with stats and run tests again." if @report.blank?
140
+ @stat = ESP::Stat.for_report(@report.id)
132
141
  end
133
142
 
134
143
  teardown do
135
144
  WebMock.disable_net_connect!
136
145
  end
137
146
 
138
- context 'for_report' do
139
- should 'return the stat for the report' do
140
- report = ESP::Report.last
141
- skip "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
147
+ context '#report' do
148
+ should 'return a report' do
149
+ report = @stat.report
150
+
151
+ assert_equal @stat.report_id, report.id
152
+ end
153
+ end
154
+
155
+ context '#regions' do
156
+ should 'return regions' do
157
+ regions = @stat.regions
158
+
159
+ assert_equal ESP::StatRegion, regions.resource_class
160
+ end
161
+ end
162
+
163
+ context '#services' do
164
+ should 'return services' do
165
+ services = @stat.services
166
+
167
+ assert_equal ESP::StatService, services.resource_class
168
+ end
169
+ end
170
+
171
+ context '#signatures' do
172
+ should 'return signatures' do
173
+ signatures = @stat.signatures
174
+
175
+ assert_equal ESP::StatSignature, signatures.resource_class
176
+ end
177
+ end
142
178
 
143
- stat = ESP::Stat.for_report(report.id)
179
+ context '#custom_signautures' do
180
+ should 'return custom_signautures' do
181
+ custom_signatures = @stat.custom_signatures
144
182
 
145
- assert_equal report.id, stat.report.id
183
+ assert_equal ESP::StatCustomSignature, custom_signatures.resource_class
184
+ end
185
+ end
186
+
187
+ context 'for_report' do
188
+ should 'return the stat for the report' do
189
+ assert_equal @report.id, @stat.report_id
146
190
  end
147
191
  end
148
192
 
@@ -97,6 +97,14 @@ module ESP
97
97
  end
98
98
  end
99
99
 
100
+ context '.where' do
101
+ should 'return sub_organization objects' do
102
+ sub_organizations = ESP::SubOrganization.where(id_eq: @sub_organization.id)
103
+
104
+ assert_equal ESP::SubOrganization, sub_organizations.resource_class
105
+ end
106
+ end
107
+
100
108
  context '#CRUD' do
101
109
  should 'be able to create, update and destroy' do
102
110
  sub_organization = ESP::SubOrganization.new(name: 'bob', organization_id: @sub_organization.organization_id)
@@ -4,6 +4,14 @@ module ESP
4
4
  class Suppression
5
5
  class RegionTest < ActiveSupport::TestCase
6
6
  context ESP::Suppression::Region do
7
+ context '.where' do
8
+ should 'not be implemented' do
9
+ assert_raises ESP::NotImplementedError do
10
+ ESP::Suppression::Region.where(id_eq: 2)
11
+ end
12
+ end
13
+ end
14
+
7
15
  context '#find' do
8
16
  should 'not be implemented' do
9
17
  assert_raises ESP::NotImplementedError do
@@ -91,7 +99,7 @@ module ESP
91
99
 
92
100
  context 'for_alert' do
93
101
  should 'return error when reason is not supplied' do
94
- alert_id = ESP::Report.last.alerts.last.id
102
+ alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
95
103
 
96
104
  suppression = ESP::Suppression::Region.create(alert_id: alert_id)
97
105
 
@@ -99,7 +107,7 @@ module ESP
99
107
  end
100
108
 
101
109
  should 'return suppression' do
102
- alert_id = ESP::Report.last.alerts.last.id
110
+ alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
103
111
 
104
112
  suppression = ESP::Suppression::Region.create(alert_id: alert_id, reason: 'test')
105
113