esp_sdk 1.1.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.rubocop.yml +53 -6
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +8 -2
  6. data/Gemfile.lock +171 -0
  7. data/Guardfile +47 -0
  8. data/README.md +230 -5
  9. data/Rakefile +14 -1
  10. data/assets/logo.png +0 -0
  11. data/bin/esp_console +71 -0
  12. data/esp_sdk.gemspec +27 -18
  13. data/lib/esp/exceptions.rb +3 -0
  14. data/lib/esp/extensions/active_resource/formats/json_api_format.rb +105 -0
  15. data/lib/esp/extensions/active_resource/paginated_collection.rb +198 -0
  16. data/lib/esp/extensions/active_resource/validations.rb +45 -0
  17. data/lib/esp/resources/alert.rb +135 -0
  18. data/lib/esp/resources/cloud_trail_event.rb +45 -0
  19. data/lib/esp/resources/concerns/stat_totals.rb +79 -0
  20. data/lib/esp/resources/contact_request.rb +42 -0
  21. data/lib/esp/resources/custom_signature.rb +224 -0
  22. data/lib/esp/resources/dashboard.rb +31 -0
  23. data/lib/esp/resources/external_account.rb +89 -0
  24. data/lib/esp/resources/organization.rb +61 -0
  25. data/lib/esp/resources/region.rb +46 -0
  26. data/lib/esp/resources/report.rb +100 -0
  27. data/lib/esp/resources/resource.rb +66 -0
  28. data/lib/esp/resources/service.rb +31 -0
  29. data/lib/esp/resources/signature.rb +106 -0
  30. data/lib/esp/resources/stat.rb +124 -0
  31. data/lib/esp/resources/stat_custom_signature.rb +121 -0
  32. data/lib/esp/resources/stat_region.rb +121 -0
  33. data/lib/esp/resources/stat_service.rb +121 -0
  34. data/lib/esp/resources/stat_signature.rb +121 -0
  35. data/lib/esp/resources/sub_organization.rb +69 -0
  36. data/lib/esp/resources/suppression/region.rb +99 -0
  37. data/lib/esp/resources/suppression/signature.rb +107 -0
  38. data/lib/esp/resources/suppression/unique_identifier.rb +60 -0
  39. data/lib/esp/resources/suppression.rb +86 -0
  40. data/lib/esp/resources/tag.rb +45 -0
  41. data/lib/esp/resources/team.rb +79 -0
  42. data/lib/esp/resources/user.rb +46 -0
  43. data/lib/esp/version.rb +3 -0
  44. data/lib/esp.rb +95 -0
  45. data/lib/esp_sdk.rb +9 -45
  46. data/lib/tasks/rubocop.rake +2 -0
  47. data/lib/tasks/testing.rake +3 -0
  48. data/rdoc/ActiveResource/Formats.html +176 -0
  49. data/rdoc/ActiveResource/PaginatedCollection.html +910 -0
  50. data/rdoc/ActiveResource.html +180 -0
  51. data/rdoc/ESP/Alert.html +771 -0
  52. data/rdoc/ESP/CloudTrailEvent.html +375 -0
  53. data/rdoc/ESP/ContactRequest.html +366 -0
  54. data/rdoc/ESP/CustomSignature.html +746 -0
  55. data/rdoc/ESP/Dashboard.html +355 -0
  56. data/rdoc/ESP/ExternalAccount.html +565 -0
  57. data/rdoc/ESP/Organization.html +590 -0
  58. data/rdoc/ESP/Region.html +399 -0
  59. data/rdoc/ESP/Report.html +622 -0
  60. data/rdoc/ESP/Service.html +380 -0
  61. data/rdoc/ESP/Signature.html +555 -0
  62. data/rdoc/ESP/Stat.html +1778 -0
  63. data/rdoc/ESP/StatCustomSignature.html +1599 -0
  64. data/rdoc/ESP/StatRegion.html +1598 -0
  65. data/rdoc/ESP/StatService.html +1598 -0
  66. data/rdoc/ESP/StatSignature.html +1598 -0
  67. data/rdoc/ESP/SubOrganization.html +540 -0
  68. data/rdoc/ESP/Suppression/Region.html +454 -0
  69. data/rdoc/ESP/Suppression/Signature.html +470 -0
  70. data/rdoc/ESP/Suppression/UniqueIdentifier.html +417 -0
  71. data/rdoc/ESP/Suppression.html +649 -0
  72. data/rdoc/ESP/Tag.html +371 -0
  73. data/rdoc/ESP/Team.html +584 -0
  74. data/rdoc/ESP/User.html +483 -0
  75. data/rdoc/ESP.html +546 -0
  76. data/rdoc/README_md.html +501 -0
  77. data/rdoc/created.rid +30 -0
  78. data/rdoc/images/add.png +0 -0
  79. data/rdoc/images/arrow_up.png +0 -0
  80. data/rdoc/images/brick.png +0 -0
  81. data/rdoc/images/brick_link.png +0 -0
  82. data/rdoc/images/bug.png +0 -0
  83. data/rdoc/images/bullet_black.png +0 -0
  84. data/rdoc/images/bullet_toggle_minus.png +0 -0
  85. data/rdoc/images/bullet_toggle_plus.png +0 -0
  86. data/rdoc/images/date.png +0 -0
  87. data/rdoc/images/delete.png +0 -0
  88. data/rdoc/images/find.png +0 -0
  89. data/rdoc/images/loadingAnimation.gif +0 -0
  90. data/rdoc/images/macFFBgHack.png +0 -0
  91. data/rdoc/images/package.png +0 -0
  92. data/rdoc/images/page_green.png +0 -0
  93. data/rdoc/images/page_white_text.png +0 -0
  94. data/rdoc/images/page_white_width.png +0 -0
  95. data/rdoc/images/plugin.png +0 -0
  96. data/rdoc/images/ruby.png +0 -0
  97. data/rdoc/images/tag_blue.png +0 -0
  98. data/rdoc/images/tag_green.png +0 -0
  99. data/rdoc/images/transparent.png +0 -0
  100. data/rdoc/images/wrench.png +0 -0
  101. data/rdoc/images/wrench_orange.png +0 -0
  102. data/rdoc/images/zoom.png +0 -0
  103. data/rdoc/index.html +134 -0
  104. data/rdoc/js/darkfish.js +155 -0
  105. data/rdoc/js/jquery.js +4 -0
  106. data/rdoc/js/navigation.js +142 -0
  107. data/rdoc/js/search.js +94 -0
  108. data/rdoc/js/search_index.js +1 -0
  109. data/rdoc/js/searcher.js +228 -0
  110. data/rdoc/rdoc.css +595 -0
  111. data/rdoc/table_of_contents.html +927 -0
  112. data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +109 -0
  113. data/test/esp/extensions/active_resource/paginated_collection_test.rb +435 -0
  114. data/test/esp/extensions/active_resource/validations_test.rb +59 -0
  115. data/test/esp/resources/alert_test.rb +263 -0
  116. data/test/esp/resources/cloud_trail_event_test.rb +98 -0
  117. data/test/esp/resources/contact_request_test.rb +73 -0
  118. data/test/esp/resources/custom_signature_test.rb +241 -0
  119. data/test/esp/resources/dashboard_test.rb +71 -0
  120. data/test/esp/resources/external_account_test.rb +125 -0
  121. data/test/esp/resources/organization_test.rb +175 -0
  122. data/test/esp/resources/region_test.rb +84 -0
  123. data/test/esp/resources/report_test.rb +180 -0
  124. data/test/esp/resources/resource_test.rb +183 -0
  125. data/test/esp/resources/service_test.rb +64 -0
  126. data/test/esp/resources/signature_test.rb +177 -0
  127. data/test/esp/resources/stat_custom_signature_test.rb +115 -0
  128. data/test/esp/resources/stat_region_test.rb +114 -0
  129. data/test/esp/resources/stat_service_test.rb +114 -0
  130. data/test/esp/resources/stat_signature_test.rb +115 -0
  131. data/test/esp/resources/stat_test.rb +159 -0
  132. data/test/esp/resources/sub_organization_test.rb +127 -0
  133. data/test/esp/resources/suppression/region_test.rb +115 -0
  134. data/test/esp/resources/suppression/signature_test.rb +117 -0
  135. data/test/esp/resources/suppression/unique_identifier_test.rb +79 -0
  136. data/test/esp/resources/suppression_test.rb +226 -0
  137. data/test/esp/resources/tag_test.rb +98 -0
  138. data/test/esp/resources/team_test.rb +140 -0
  139. data/test/esp/resources/user_test.rb +113 -0
  140. data/test/esp_test.rb +139 -0
  141. data/test/factories/alerts.rb +234 -0
  142. data/test/factories/cloud_trail_events.rb +16 -0
  143. data/test/factories/contact_requests.rb +14 -0
  144. data/test/factories/custom_signatures.rb +30 -0
  145. data/test/factories/dashboards.rb +91 -0
  146. data/test/factories/errors.rb +24 -0
  147. data/test/factories/external_accounts.rb +44 -0
  148. data/test/factories/organizations.rb +48 -0
  149. data/test/factories/regions.rb +9 -0
  150. data/test/factories/reports.rb +56 -0
  151. data/test/factories/services.rb +12 -0
  152. data/test/factories/signatures.rb +28 -0
  153. data/test/factories/stat_custom_signatures.rb +97 -0
  154. data/test/factories/stat_regions.rb +97 -0
  155. data/test/factories/stat_services.rb +97 -0
  156. data/test/factories/stat_signautures.rb +97 -0
  157. data/test/factories/stats.rb +129 -0
  158. data/test/factories/sub_organizations.rb +34 -0
  159. data/test/factories/suppression/regions.rb +90 -0
  160. data/test/factories/suppression/signatures.rb +117 -0
  161. data/test/factories/suppression/unique_identifiers.rb +111 -0
  162. data/test/factories/suppressions.rb +71 -0
  163. data/test/factories/tags.rb +12 -0
  164. data/test/factories/teams.rb +32 -0
  165. data/test/factories/users.rb +54 -0
  166. data/test/json_strategy.rb +25 -0
  167. data/test/test_helper.rb +44 -5
  168. metadata +387 -119
  169. data/bin/esp_repl +0 -60
  170. data/lib/esp_sdk/api.rb +0 -33
  171. data/lib/esp_sdk/client.rb +0 -62
  172. data/lib/esp_sdk/configure.rb +0 -40
  173. data/lib/esp_sdk/end_points/base.rb +0 -102
  174. data/lib/esp_sdk/end_points/contact_requests.rb +0 -6
  175. data/lib/esp_sdk/end_points/custom_signatures.rb +0 -41
  176. data/lib/esp_sdk/end_points/dashboard.rb +0 -35
  177. data/lib/esp_sdk/end_points/external_accounts.rb +0 -9
  178. data/lib/esp_sdk/end_points/organizations.rb +0 -6
  179. data/lib/esp_sdk/end_points/reports.rb +0 -6
  180. data/lib/esp_sdk/end_points/services.rb +0 -6
  181. data/lib/esp_sdk/end_points/signatures.rb +0 -39
  182. data/lib/esp_sdk/end_points/sub_organizations.rb +0 -6
  183. data/lib/esp_sdk/end_points/teams.rb +0 -6
  184. data/lib/esp_sdk/end_points/users.rb +0 -6
  185. data/lib/esp_sdk/exceptions.rb +0 -8
  186. data/lib/esp_sdk/extensions/rest_client/request.rb +0 -9
  187. data/lib/esp_sdk/repl.rb +0 -61
  188. data/lib/esp_sdk/version.rb +0 -3
  189. data/test/esp_sdk/api_test.rb +0 -36
  190. data/test/esp_sdk/client_test.rb +0 -129
  191. data/test/esp_sdk/configure_test.rb +0 -65
  192. data/test/esp_sdk/end_points/.keep +0 -0
  193. data/test/esp_sdk/end_points/base_test.rb +0 -230
  194. data/test/esp_sdk/end_points/custom_signatures_test.rb +0 -90
  195. data/test/esp_sdk/end_points/dashboard_test.rb +0 -55
  196. data/test/esp_sdk/end_points/external_accounts_test.rb +0 -20
  197. data/test/esp_sdk/end_points/signatures_test.rb +0 -83
  198. data/test/esp_sdk/exceptions_test.rb +0 -41
  199. data/test/esp_sdk_test.rb +0 -70
@@ -0,0 +1,114 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP
4
+ class Stat
5
+ class ServiceTest < ActiveSupport::TestCase
6
+ context ESP::StatService do
7
+ context '.for_stat' do
8
+ should 'throw an error if stat id is not supplied' do
9
+ error = assert_raises ArgumentError do
10
+ ESP::StatService.for_stat
11
+ end
12
+ assert_equal 'You must supply a stat id.', error.message
13
+ end
14
+
15
+ should 'call the api' do
16
+ stub_service = stub_request(:get, %r{stats/5/services.json*}).to_return(body: json_list(:stat_service, 2))
17
+
18
+ services = ESP::StatService.for_stat(5)
19
+
20
+ assert_requested(stub_service)
21
+ assert_equal ESP::StatService, services.resource_class
22
+ end
23
+ end
24
+ context '.find' do
25
+ should 'throw an error if stat_id is not supplied' do
26
+ error = assert_raises ArgumentError do
27
+ ESP::StatService.find(:all, params: { id: 3 })
28
+ end
29
+ assert_equal 'You must supply a stat id.', error.message
30
+ end
31
+
32
+ should 'call the show api and return a service if searching by id' do
33
+ stub_service = stub_request(:get, %r{services/5.json*}).to_return(body: json(:stat_service))
34
+
35
+ service = ESP::StatService.find(5)
36
+
37
+ assert_requested(stub_service)
38
+ assert_equal ESP::StatService, service.class
39
+ end
40
+
41
+ should 'call the api and return services when stat_id is supplied' do
42
+ stub_service = stub_request(:get, %r{stats/5/services.json*}).to_return(body: json_list(:stat_service, 2))
43
+
44
+ services = ESP::StatService.find(:all, params: { stat_id: 5 })
45
+
46
+ assert_requested(stub_service)
47
+ assert_equal ESP::StatService, services.resource_class
48
+ end
49
+ end
50
+
51
+ context '#create' do
52
+ should 'not be implemented' do
53
+ assert_raises ESP::NotImplementedError do
54
+ ESP::StatService.create(name: 'test')
55
+ end
56
+ end
57
+ end
58
+
59
+ context '#update' do
60
+ should 'not be implemented' do
61
+ service = ESP::StatService.new
62
+ assert_raises ESP::NotImplementedError do
63
+ service.save
64
+ end
65
+ end
66
+ end
67
+
68
+ context '#destroy' do
69
+ should 'not be implemented' do
70
+ s = ESP::StatService.new
71
+ assert_raises ESP::NotImplementedError do
72
+ s.destroy
73
+ end
74
+ end
75
+ end
76
+
77
+ context '#service' do
78
+ should 'call the show api and return the service' do
79
+ service_stat = ESP::StatService.new(service_id: 3)
80
+
81
+ stub_service = stub_request(:get, %r{services/#{service_stat.service_id}.json*}).to_return(body: json(:service))
82
+
83
+ service = service_stat.service
84
+
85
+ assert_requested(stub_service)
86
+ assert_equal ESP::Service, service.class
87
+ end
88
+ end
89
+
90
+ context 'live calls' do
91
+ setup do
92
+ skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
93
+ WebMock.allow_net_connect!
94
+ end
95
+
96
+ teardown do
97
+ WebMock.disable_net_connect!
98
+ end
99
+
100
+ context '.for_stat' do
101
+ should 'return tags for stat id' do
102
+ report = ESP::Report.find(:first, params: { status: 'complete' })
103
+ skip "make sure you have a complete report" unless report.present?
104
+ stat_id = report.stat.id
105
+ stats = ESP::StatService.for_stat(stat_id)
106
+
107
+ assert_equal ESP::StatService, stats.resource_class
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,115 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP
4
+ class Stat
5
+ class SignatureTest < ActiveSupport::TestCase
6
+ context ESP::StatSignature do
7
+ context '.for_stat' do
8
+ should 'throw an error if stat id is not supplied' do
9
+ error = assert_raises ArgumentError do
10
+ ESP::StatSignature.for_stat
11
+ end
12
+ assert_equal 'You must supply a stat id.', error.message
13
+ end
14
+
15
+ should 'call the api' do
16
+ stub_signature = stub_request(:get, %r{stats/5/signatures.json*}).to_return(body: json_list(:stat_signature, 2))
17
+
18
+ signatures = ESP::StatSignature.for_stat(5)
19
+
20
+ assert_requested(stub_signature)
21
+ assert_equal ESP::StatSignature, signatures.resource_class
22
+ end
23
+ end
24
+
25
+ context '.find' do
26
+ should 'throw an error if stat_id is not supplied' do
27
+ error = assert_raises ArgumentError do
28
+ ESP::StatSignature.find(:all, params: { id: 3 })
29
+ end
30
+ assert_equal 'You must supply a stat id.', error.message
31
+ end
32
+
33
+ should 'call the show api and return a signature if searching by id' do
34
+ stub_signature = stub_request(:get, %r{signatures/5.json*}).to_return(body: json(:stat_signature))
35
+
36
+ signature = ESP::StatSignature.find(5)
37
+
38
+ assert_requested(stub_signature)
39
+ assert_equal ESP::StatSignature, signature.class
40
+ end
41
+
42
+ should 'call the api and return signatures when stat_id is supplied' do
43
+ stub_signature = stub_request(:get, %r{stats/5/signatures.json*}).to_return(body: json_list(:stat_signature, 2))
44
+
45
+ signatures = ESP::StatSignature.find(:all, params: { stat_id: 5 })
46
+
47
+ assert_requested(stub_signature)
48
+ assert_equal ESP::StatSignature, signatures.resource_class
49
+ end
50
+ end
51
+
52
+ context '#create' do
53
+ should 'not be implemented' do
54
+ assert_raises ESP::NotImplementedError do
55
+ ESP::StatSignature.create(name: 'test')
56
+ end
57
+ end
58
+ end
59
+
60
+ context '#update' do
61
+ should 'not be implemented' do
62
+ signature = ESP::StatSignature.new
63
+ assert_raises ESP::NotImplementedError do
64
+ signature.save
65
+ end
66
+ end
67
+ end
68
+
69
+ context '#destroy' do
70
+ should 'not be implemented' do
71
+ s = ESP::StatSignature.new
72
+ assert_raises ESP::NotImplementedError do
73
+ s.destroy
74
+ end
75
+ end
76
+ end
77
+
78
+ context '#signature' do
79
+ should 'call the show api and return the signature' do
80
+ signature_stat = ESP::StatSignature.new(signature_id: 3)
81
+
82
+ stub_signature = stub_request(:get, %r{signatures/#{signature_stat.signature_id}.json*}).to_return(body: json(:signature))
83
+
84
+ signature = signature_stat.signature
85
+
86
+ assert_requested(stub_signature)
87
+ assert_equal ESP::Signature, signature.class
88
+ end
89
+ end
90
+
91
+ context 'live calls' do
92
+ setup do
93
+ skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
94
+ WebMock.allow_net_connect!
95
+ end
96
+
97
+ teardown do
98
+ WebMock.disable_net_connect!
99
+ end
100
+
101
+ context '.for_stat' do
102
+ should 'return tags for stat id' do
103
+ report = ESP::Report.find(:first, params: { status: 'complete' })
104
+ skip "make sure you have a complete report" unless report.present?
105
+ stat_id = report.stat.id
106
+ stats = ESP::StatSignature.for_stat(stat_id)
107
+
108
+ assert_equal ESP::StatSignature, stats.resource_class
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,159 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP
4
+ class StatTest < ActiveSupport::TestCase
5
+ context ESP::Stat do
6
+ context '#report' do
7
+ should 'call the api' do
8
+ stat = build(:stat, report_id: 3)
9
+ stubbed_report = stub_request(:get, %r{reports/#{stat.report_id}.json*}).to_return(body: json(:report))
10
+
11
+ stat.report
12
+
13
+ assert_requested(stubbed_report)
14
+ end
15
+ end
16
+
17
+ context '#regions' do
18
+ should 'call the api for the stat' do
19
+ stat = build(:stat)
20
+ stubbed_regions = stub_request(:get, %r{stats/#{stat.id}/regions.json*}).to_return(body: json_list(:stat_region, 2))
21
+
22
+ stat.regions
23
+
24
+ assert_requested(stubbed_regions)
25
+ end
26
+ end
27
+
28
+ context '#services' do
29
+ should 'call the api for the stat' do
30
+ stat = build(:stat)
31
+ stubbed_services = stub_request(:get, %r{stats/#{stat.id}/services.json*}).to_return(body: json_list(:stat_service, 2))
32
+
33
+ stat.services
34
+
35
+ assert_requested(stubbed_services)
36
+ end
37
+ end
38
+
39
+ context '#signatures' do
40
+ should 'call the api for the stat' do
41
+ stat = build(:stat)
42
+ stubbed_signatures = stub_request(:get, %r{stats/#{stat.id}/signatures.json*}).to_return(body: json_list(:stat_signature, 2))
43
+
44
+ stat.signatures
45
+
46
+ assert_requested(stubbed_signatures)
47
+ end
48
+ end
49
+
50
+ context '#custom_signatures' do
51
+ should 'call the api for the stat' do
52
+ stat = build(:stat)
53
+ stubbed_custom_signatures = stub_request(:get, %r{stats/#{stat.id}/custom_signatures.json*}).to_return(body: json_list(:stat_custom_signature, 2))
54
+
55
+ stat.custom_signatures
56
+
57
+ assert_requested(stubbed_custom_signatures)
58
+ end
59
+ end
60
+
61
+ context '#find' do
62
+ should 'not be implemented' do
63
+ assert_raises ESP::NotImplementedError do
64
+ ESP::Stat.find(1)
65
+ end
66
+ end
67
+ end
68
+
69
+ context '#create' do
70
+ should 'not be implemented' do
71
+ assert_raises ESP::NotImplementedError do
72
+ ESP::Stat.create(report_id: 1)
73
+ end
74
+ end
75
+ end
76
+
77
+ context '#update' do
78
+ should 'not be implemented' do
79
+ s = build(:stat)
80
+
81
+ assert_raises ESP::NotImplementedError do
82
+ s.save
83
+ end
84
+ end
85
+ end
86
+
87
+ context '#destroy' do
88
+ should 'not be implemented' do
89
+ s = build(:stat)
90
+
91
+ assert_raises ESP::NotImplementedError do
92
+ s.destroy
93
+ end
94
+ end
95
+ end
96
+
97
+ context '.for_report' do
98
+ should 'raise an error if report_id is not provided' do
99
+ error = assert_raises ArgumentError do
100
+ ESP::Stat.for_report
101
+ end
102
+ assert_equal "You must supply a report id.", error.message
103
+ end
104
+
105
+ should 'call the api and return a stat' do
106
+ stub_stat = stub_request(:get, %r{reports/5/stats.json*}).to_return(body: json(:stat))
107
+
108
+ stat = ESP::Stat.for_report(5)
109
+
110
+ assert_requested(stub_stat)
111
+ assert_equal ESP::Stat, stat.class
112
+ end
113
+ end
114
+
115
+ context '.latest_for_teams' do
116
+ should 'call the api and return a collection of stats' do
117
+ stub_stat = stub_request(:get, %r{stats/latest_for_teams.json*}).to_return(body: json_list(:stat, 2))
118
+
119
+ stats = ESP::Stat.latest_for_teams
120
+
121
+ assert_requested(stub_stat)
122
+ assert_equal ESP::Stat, stats.resource_class
123
+ end
124
+ end
125
+
126
+ context 'live calls' do
127
+ setup do
128
+ skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
129
+ 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?
132
+ end
133
+
134
+ teardown do
135
+ WebMock.disable_net_connect!
136
+ end
137
+
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?
142
+
143
+ stat = ESP::Stat.for_report(report.id)
144
+
145
+ assert_equal report.id, stat.report.id
146
+ end
147
+ end
148
+
149
+ context '.latest_for_teams' do
150
+ should 'return a collection of stats' do
151
+ stats = ESP::Stat.latest_for_teams
152
+
153
+ assert_equal ESP::Stat, stats.resource_class
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,127 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP
4
+ class SubOrganizationTest < ActiveSupport::TestCase
5
+ context ESP::SubOrganization do
6
+ context '#organization' do
7
+ should 'call the api' do
8
+ sub_organization = build(:sub_organization, organization_id: 4)
9
+ stub_org = stub_request(:get, %r{organizations/#{sub_organization.organization_id}.json*}).to_return(body: json(:organization))
10
+
11
+ sub_organization.organization
12
+
13
+ assert_requested(stub_org)
14
+ end
15
+ end
16
+
17
+ context '#teams' do
18
+ should 'call the api' do
19
+ sub_organization = build(:sub_organization, team_id: 4)
20
+ stub_request(:get, /teams.json*/).to_return(body: json_list(:sub_organization, 2))
21
+
22
+ sub_organization.teams
23
+
24
+ assert_requested(:get, /teams.json*/) do |req|
25
+ assert_equal "filter[sub_organization_id_eq]=#{sub_organization.id}", URI.unescape(req.uri.query)
26
+ end
27
+ end
28
+ end
29
+
30
+ context '#external_accounts' do
31
+ should 'call the api' do
32
+ sub_organization = build(:sub_organization)
33
+ stub_request(:get, /external_accounts.json*/).to_return(body: json_list(:external_account, 2))
34
+
35
+ sub_organization.external_accounts
36
+
37
+ assert_requested(:get, /external_accounts.json*/) do |req|
38
+ assert_equal "filter[sub_organization_id_eq]=#{sub_organization.id}", URI.unescape(req.uri.query)
39
+ end
40
+ end
41
+ end
42
+
43
+ context '#reports' do
44
+ should 'call the api' do
45
+ sub_organization = build(:sub_organization)
46
+ stub_request(:get, /reports.json*/).to_return(body: json_list(:report, 2))
47
+
48
+ sub_organization.reports
49
+
50
+ assert_requested(:get, /reports.json*/) do |req|
51
+ assert_equal "filter[sub_organization_id_eq]=#{sub_organization.id}", URI.unescape(req.uri.query)
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'live calls' do
57
+ setup do
58
+ skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
59
+ WebMock.allow_net_connect!
60
+ @sub_organization = ESP::SubOrganization.last
61
+ skip "Live DB does not have any sub organizations. Add a sub organization and run tests again." if @sub_organization.blank?
62
+ end
63
+
64
+ teardown do
65
+ WebMock.disable_net_connect!
66
+ end
67
+
68
+ context '#organization' do
69
+ should 'return an organization' do
70
+ org = @sub_organization.organization
71
+
72
+ assert_equal @sub_organization.organization_id, org.id
73
+ end
74
+ end
75
+
76
+ context '#teams' do
77
+ should 'return a sub_organization' do
78
+ teams = @sub_organization.teams
79
+
80
+ assert_equal ESP::Team, teams.resource_class
81
+ end
82
+ end
83
+
84
+ context '#external_accounts' do
85
+ should 'return an array of external_accounts' do
86
+ external_accounts = @sub_organization.external_accounts
87
+
88
+ assert_equal ESP::ExternalAccount, external_accounts.resource_class
89
+ end
90
+ end
91
+
92
+ context '#reports' do
93
+ should 'return an array of reports' do
94
+ reports = @sub_organization.reports
95
+
96
+ assert_equal ESP::Report, reports.resource_class
97
+ end
98
+ end
99
+
100
+ context '#CRUD' do
101
+ should 'be able to create, update and destroy' do
102
+ sub_organization = ESP::SubOrganization.new(name: 'bob', organization_id: @sub_organization.organization_id)
103
+
104
+ assert_predicate sub_organization, :new?
105
+
106
+ sub_organization.save
107
+
108
+ refute_predicate sub_organization, :new?
109
+
110
+ sub_organization.name = 'jim'
111
+ sub_organization.save
112
+
113
+ assert_nothing_raised do
114
+ ESP::SubOrganization.find(sub_organization.id)
115
+ end
116
+
117
+ sub_organization.destroy
118
+
119
+ assert_raises ActiveResource::ResourceNotFound do
120
+ ESP::SubOrganization.find(sub_organization.id)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,115 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
2
+
3
+ module ESP
4
+ class Suppression
5
+ class RegionTest < ActiveSupport::TestCase
6
+ context ESP::Suppression::Region do
7
+ context '#find' do
8
+ should 'not be implemented' do
9
+ assert_raises ESP::NotImplementedError do
10
+ ESP::Suppression::Region.find(4)
11
+ end
12
+ end
13
+ end
14
+
15
+ context '#update' do
16
+ should 'not be implemented' do
17
+ s = ESP::Suppression::Region.new
18
+ assert_raises ESP::NotImplementedError do
19
+ s.update
20
+ end
21
+ end
22
+ end
23
+
24
+ context '#destroy' do
25
+ should 'not be implemented' do
26
+ s = ESP::Suppression::Region.new
27
+ assert_raises ESP::NotImplementedError do
28
+ s.destroy
29
+ end
30
+ end
31
+ end
32
+
33
+ context '#create' do
34
+ should 'call the api' do
35
+ stub_request(:post, %r{suppressions/regions.json*}).to_return(body: json(:suppression_region))
36
+
37
+ suppression = ESP::Suppression::Region.create(regions: ['us_east_1'], external_account_ids: [5], reason: 'because')
38
+
39
+ assert_requested(:post, %r{suppressions/regions.json*}) do |req|
40
+ body = JSON.parse(req.body)
41
+ assert_equal 'because', body['data']['attributes']['reason']
42
+ assert_equal ['us_east_1'], body['data']['attributes']['regions']
43
+ assert_equal [5], body['data']['attributes']['external_account_ids']
44
+ end
45
+ assert_equal ESP::Suppression::Region, suppression.class
46
+ end
47
+
48
+ context 'for alert' do
49
+ should 'call the api' do
50
+ stub_request(:post, %r{suppressions/alert/5/regions.json*}).to_return(body: json(:suppression_region))
51
+
52
+ suppression = ESP::Suppression::Region.create(alert_id: 5, reason: 'because')
53
+
54
+ assert_requested(:post, %r{suppressions/alert/5/regions.json*}) do |req|
55
+ body = JSON.parse(req.body)
56
+ assert_equal 'because', body['data']['attributes']['reason']
57
+ end
58
+ assert_equal ESP::Suppression::Region, suppression.class
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'live calls' do
64
+ setup do
65
+ skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
66
+ WebMock.allow_net_connect!
67
+ end
68
+
69
+ teardown do
70
+ WebMock.disable_net_connect!
71
+ end
72
+
73
+ context '.create' do
74
+ should 'return error when reason is not supplied' do
75
+ signature_id = ESP::Signature.last.id
76
+ external_account_id = ESP::ExternalAccount.last.id
77
+
78
+ suppression = ESP::Suppression::Region.create(signature_ids: [signature_id], custom_signature_ids: [], regions: ['us_east_1'], external_account_ids: [external_account_id])
79
+
80
+ assert_equal "Reason can't be blank", suppression.errors.full_messages.first
81
+ end
82
+
83
+ should 'return suppression' do
84
+ signature_id = ESP::Signature.last.id
85
+ external_account_id = ESP::ExternalAccount.last.id
86
+
87
+ suppression = ESP::Suppression::Region.create(signature_ids: [signature_id], custom_signature_ids: [], reason: 'test', regions: ['us_east_1'], external_account_ids: [external_account_id])
88
+
89
+ assert_equal ESP::Suppression::Region, suppression.class
90
+ end
91
+
92
+ context 'for_alert' do
93
+ should 'return error when reason is not supplied' do
94
+ alert_id = ESP::Report.last.alerts.last.id
95
+
96
+ suppression = ESP::Suppression::Region.create(alert_id: alert_id)
97
+
98
+ assert_equal "Reason can't be blank", suppression.errors.full_messages.first
99
+ end
100
+
101
+ should 'return suppression' do
102
+ alert_id = ESP::Report.last.alerts.last.id
103
+
104
+ suppression = ESP::Suppression::Region.create(alert_id: alert_id, reason: 'test')
105
+
106
+ assert_predicate suppression.errors, :blank?
107
+ assert_equal ESP::Suppression::Region, suppression.class
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end