esp_sdk 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +8 -0
  4. data/Gemfile.lock +4 -1
  5. data/Rakefile +12 -1
  6. data/lib/esp/extensions/active_resource/formats/json_api_format.rb +1 -1
  7. data/lib/esp/extensions/active_resource/validations.rb +3 -2
  8. data/lib/esp/external_account_creator.rb +2 -2
  9. data/lib/esp/resources/custom_signature.rb +7 -0
  10. data/lib/esp/resources/report.rb +1 -1
  11. data/lib/esp/resources/reports/export/integration.rb +44 -0
  12. data/lib/esp/resources/team.rb +6 -0
  13. data/lib/esp/version.rb +1 -1
  14. data/lib/esp.rb +5 -0
  15. data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +0 -67
  16. data/test/esp/extensions/active_resource/paginated_collection_test.rb +0 -69
  17. data/test/esp/extensions/active_resource/validations_test.rb +0 -20
  18. data/test/esp/integration/alert_integration_test.rb +96 -0
  19. data/test/esp/integration/cloud_trail_event_integration_test.rb +18 -0
  20. data/test/esp/integration/contact_request_integration_test.rb +21 -0
  21. data/test/esp/integration/custom_signature_integration_test.rb +97 -0
  22. data/test/esp/integration/dashboard_integration_test.rb +17 -0
  23. data/test/esp/integration/external_account_integration_test.rb +68 -0
  24. data/test/esp/integration/json_api_format_integration_test.rb +61 -0
  25. data/test/esp/integration/metadata_integration_test.rb +18 -0
  26. data/test/esp/integration/organization_integration_test.rb +81 -0
  27. data/test/esp/integration/paginated_collection_integration_test.rb +67 -0
  28. data/test/esp/integration/region_integration_test.rb +32 -0
  29. data/test/esp/integration/report_export_integration_integration_test.rb +24 -0
  30. data/test/esp/integration/report_integration_test.rb +71 -0
  31. data/test/esp/integration/resource_integration_test.rb +54 -0
  32. data/test/esp/integration/scan_interval_integration_test.rb +49 -0
  33. data/test/esp/integration/service_integration_test.rb +28 -0
  34. data/test/esp/integration/signature_integration_test.rb +62 -0
  35. data/test/esp/integration/stat_custom_signature_integration_test.rb +22 -0
  36. data/test/esp/integration/stat_integration_test.rb +69 -0
  37. data/test/esp/integration/stat_region_integration_test.rb +36 -0
  38. data/test/esp/integration/stat_service_integration_test.rb +36 -0
  39. data/test/esp/integration/stat_signature_integration_test.rb +36 -0
  40. data/test/esp/integration/sub_organization_integration_test.rb +79 -0
  41. data/test/esp/integration/suppression_integration_test.rb +95 -0
  42. data/test/esp/integration/suppression_region_integration_test.rb +52 -0
  43. data/test/esp/integration/suppression_signature_integration_test.rb +52 -0
  44. data/test/esp/integration/suppression_unique_identifier_integration_test.rb +30 -0
  45. data/test/esp/integration/tag_integration_test.rb +18 -0
  46. data/test/esp/integration/team_integration_test.rb +87 -0
  47. data/test/esp/integration/user_integration_test.rb +52 -0
  48. data/test/esp/integration/validations_integration_test.rb +18 -0
  49. data/test/esp/resources/alert_test.rb +0 -93
  50. data/test/esp/resources/cloud_trail_event_test.rb +0 -20
  51. data/test/esp/resources/contact_request_test.rb +0 -23
  52. data/test/esp/resources/custom_signature_test.rb +14 -85
  53. data/test/esp/resources/dashboard_test.rb +0 -19
  54. data/test/esp/resources/external_account_test.rb +0 -67
  55. data/test/esp/resources/metadata_test.rb +0 -20
  56. data/test/esp/resources/organization_test.rb +0 -80
  57. data/test/esp/resources/region_test.rb +0 -31
  58. data/test/esp/resources/report_test.rb +0 -70
  59. data/test/esp/resources/reports/export/integration_test.rb +55 -0
  60. data/test/esp/resources/resource_test.rb +0 -53
  61. data/test/esp/resources/scan_interval_test.rb +0 -50
  62. data/test/esp/resources/service_test.rb +0 -27
  63. data/test/esp/resources/signature_test.rb +0 -60
  64. data/test/esp/resources/stat_custom_signature_test.rb +0 -22
  65. data/test/esp/resources/stat_region_test.rb +1 -36
  66. data/test/esp/resources/stat_service_test.rb +1 -36
  67. data/test/esp/resources/stat_signature_test.rb +0 -36
  68. data/test/esp/resources/stat_test.rb +0 -68
  69. data/test/esp/resources/sub_organization_test.rb +0 -78
  70. data/test/esp/resources/suppression/region_test.rb +0 -50
  71. data/test/esp/resources/suppression/signature_test.rb +0 -50
  72. data/test/esp/resources/suppression/unique_identifier_test.rb +0 -30
  73. data/test/esp/resources/suppression_test.rb +0 -94
  74. data/test/esp/resources/tag_test.rb +0 -20
  75. data/test/esp/resources/team_test.rb +14 -78
  76. data/test/esp/resources/user_test.rb +0 -47
  77. data/test/factories/custom_signatures.rb +17 -7
  78. data/test/factories/teams.rb +18 -8
  79. data/test/parallel_reporter.rb +93 -0
  80. data/test/test_helper.rb +20 -4
  81. metadata +70 -3
@@ -0,0 +1,69 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class StatTest < ESP::Integration::TestCase
5
+ context ESP::Stat do
6
+ context 'live calls' do
7
+ setup do
8
+ @report = ESP::Report.all.detect { |r| r.status == 'complete' }
9
+ fail "Live DB does not have any reports. Add a report with stats and run tests again." if @report.blank?
10
+ @stat = ESP::Stat.for_report(@report.id)
11
+ end
12
+
13
+ context '#report' do
14
+ should 'return a report' do
15
+ report = @stat.report
16
+
17
+ assert_equal @stat.report_id, report.id
18
+ end
19
+ end
20
+
21
+ context '#regions' do
22
+ should 'return regions' do
23
+ regions = @stat.regions
24
+
25
+ assert_equal ESP::StatRegion, regions.resource_class
26
+ end
27
+ end
28
+
29
+ context '#services' do
30
+ should 'return services' do
31
+ services = @stat.services
32
+
33
+ assert_equal ESP::StatService, services.resource_class
34
+ end
35
+ end
36
+
37
+ context '#signatures' do
38
+ should 'return signatures' do
39
+ signatures = @stat.signatures
40
+
41
+ assert_equal ESP::StatSignature, signatures.resource_class
42
+ end
43
+ end
44
+
45
+ context '#custom_signautures' do
46
+ should 'return custom_signautures' do
47
+ custom_signatures = @stat.custom_signatures
48
+
49
+ assert_equal ESP::StatCustomSignature, custom_signatures.resource_class
50
+ end
51
+ end
52
+
53
+ context 'for_report' do
54
+ should 'return the stat for the report' do
55
+ assert_equal @report.id, @stat.report_id
56
+ end
57
+ end
58
+
59
+ context '.latest_for_teams' do
60
+ should 'return a collection of stats' do
61
+ stats = ESP::Stat.latest_for_teams
62
+
63
+ assert_equal ESP::Stat, stats.resource_class
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class Stat
5
+ class RegionTest < ESP::Integration::TestCase
6
+ context ESP::StatRegion do
7
+ context 'live calls' do
8
+ context '#regions' do
9
+ should 'return regions' do
10
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
11
+ fail "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
12
+ stat = ESP::Stat.for_report(report.id)
13
+ regions = stat.regions
14
+
15
+ region = regions.first.region
16
+
17
+ assert_equal ESP::Region, region.class
18
+ assert_equal regions.first.region.code, region.code
19
+ end
20
+ end
21
+
22
+ context '.for_stat' do
23
+ should 'return tags for stat id' do
24
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
25
+ fail "make sure you have a complete report" unless report.present?
26
+ stat_id = report.stat.id
27
+ stats = ESP::StatRegion.for_stat(stat_id)
28
+
29
+ assert_equal ESP::StatRegion, stats.resource_class
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class Stat
5
+ class ServiceTest < ESP::Integration::TestCase
6
+ context ESP::StatService do
7
+ context 'live calls' do
8
+ context '#services' do
9
+ should 'return signatures' do
10
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
11
+ fail "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
12
+ stat = ESP::Stat.for_report(report.id)
13
+ services = stat.services
14
+
15
+ service = services.first.service
16
+
17
+ assert_equal ESP::Service, service.class
18
+ assert_equal services.first.service.name, service.name
19
+ end
20
+ end
21
+
22
+ context '.for_stat' do
23
+ should 'return tags for stat id' do
24
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
25
+ fail "make sure you have a complete report" unless report.present?
26
+ stat_id = report.stat.id
27
+ stats = ESP::StatService.for_stat(stat_id)
28
+
29
+ assert_equal ESP::StatService, stats.resource_class
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class Stat
5
+ class SignatureTest < ESP::Integration::TestCase
6
+ context ESP::StatSignature do
7
+ context 'live calls' do
8
+ context '#signatures' do
9
+ should 'return signatures' do
10
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
11
+ fail "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
12
+ stat = ESP::Stat.for_report(report.id)
13
+ signatures = stat.signatures
14
+
15
+ signature = signatures.first.signature
16
+
17
+ assert_equal ESP::Signature, signature.class
18
+ assert_equal signatures.first.signature.name, signature.name
19
+ end
20
+ end
21
+
22
+ context '.for_stat' do
23
+ should 'return tags for stat id' do
24
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
25
+ fail "make sure you have a complete report" unless report.present?
26
+ stat_id = report.stat.id
27
+ stats = ESP::StatSignature.for_stat(stat_id)
28
+
29
+ assert_equal ESP::StatSignature, stats.resource_class
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,79 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class SubOrganizationTest < ESP::Integration::TestCase
5
+ context ESP::SubOrganization do
6
+ context 'live calls' do
7
+ setup do
8
+ @sub_organization = ESP::SubOrganization.last
9
+ fail "Live DB does not have any sub organizations. Add a sub organization and run tests again." if @sub_organization.blank?
10
+ end
11
+
12
+ context '#organization' do
13
+ should 'return an organization' do
14
+ org = @sub_organization.organization
15
+
16
+ assert_equal @sub_organization.organization_id, org.id
17
+ end
18
+ end
19
+
20
+ context '#teams' do
21
+ should 'return a sub_organization' do
22
+ teams = @sub_organization.teams
23
+
24
+ assert_equal ESP::Team, teams.resource_class
25
+ end
26
+ end
27
+
28
+ context '#external_accounts' do
29
+ should 'return an array of external_accounts' do
30
+ external_accounts = @sub_organization.external_accounts
31
+
32
+ assert_equal ESP::ExternalAccount, external_accounts.resource_class
33
+ end
34
+ end
35
+
36
+ context '#reports' do
37
+ should 'return an array of reports' do
38
+ reports = @sub_organization.reports
39
+
40
+ assert_equal ESP::Report, reports.resource_class
41
+ end
42
+ end
43
+
44
+ context '.where' do
45
+ should 'return sub_organization objects' do
46
+ sub_organizations = ESP::SubOrganization.where(id_eq: @sub_organization.id)
47
+
48
+ assert_equal ESP::SubOrganization, sub_organizations.resource_class
49
+ end
50
+ end
51
+
52
+ context '#CRUD' do
53
+ should 'be able to create, update and destroy' do
54
+ sub_organization = ESP::SubOrganization.new(name: 'bob', organization_id: @sub_organization.organization_id)
55
+
56
+ assert_predicate sub_organization, :new?
57
+
58
+ sub_organization.save
59
+
60
+ refute_predicate sub_organization, :new?
61
+
62
+ sub_organization.name = 'jim'
63
+ sub_organization.save
64
+
65
+ assert_nothing_raised do
66
+ ESP::SubOrganization.find(sub_organization.id)
67
+ end
68
+
69
+ sub_organization.destroy
70
+
71
+ assert_raises ActiveResource::ResourceNotFound do
72
+ ESP::SubOrganization.find(sub_organization.id)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,95 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class SuppressionTest < ESP::Integration::TestCase
5
+ context ESP::Suppression do
6
+ context 'live calls' do
7
+ setup do
8
+ @s = ESP::Suppression.first
9
+ fail "Live DB does not have any suppressions. Add a suppression and run tests again." if @s.blank?
10
+ end
11
+
12
+ context '#organization' do
13
+ should 'return an organization' do
14
+ org = @s.organization
15
+
16
+ assert_equal @s.organization_id, org.id
17
+ end
18
+ end
19
+
20
+ context '#created_by' do
21
+ should 'return a user' do
22
+ u = @s.created_by
23
+
24
+ assert_equal @s.created_by_id, u.id
25
+ end
26
+ end
27
+
28
+ context '#regions' do
29
+ should 'return regions' do
30
+ r = @s.regions
31
+
32
+ assert_equal ESP::Region, r.resource_class unless r == []
33
+ end
34
+ end
35
+
36
+ context '#external_accounts' do
37
+ should 'return external_accounts' do
38
+ e = @s.external_accounts
39
+
40
+ assert_equal ESP::ExternalAccount, e.resource_class
41
+ end
42
+ end
43
+
44
+ context '#signatures' do
45
+ should 'return signatures' do
46
+ s = @s.signatures
47
+
48
+ assert_equal ESP::Signature, s.resource_class unless s == []
49
+ end
50
+ end
51
+
52
+ context '#custom_signatures' do
53
+ should 'return custom_signatures' do
54
+ cs = @s.custom_signatures
55
+
56
+ assert_equal ESP::CustomSignature, cs.resource_class unless cs == []
57
+ end
58
+ end
59
+
60
+ context '#deactivate' do
61
+ should 'deactivate the suppression' do
62
+ status = @s.status
63
+
64
+ @s.deactivate
65
+
66
+ assert_equal 'inactive', @s.status
67
+ assert_contains @s.errors.full_messages.first, 'Access Denied' if status == 'inactive'
68
+ end
69
+ end
70
+
71
+ context '#deactivate!' do
72
+ should 'raise an error if already inactive' do
73
+ status = @s.status
74
+
75
+ if status == 'inactive'
76
+ assert_raises ActiveResource::ResourceInvalid do
77
+ @s.deactivate!
78
+ end
79
+ assert_equal 'inactive', @s.status
80
+ assert_contains @s.errors.full_messages.first, 'Access Denied' if status == 'inactive'
81
+ end
82
+ end
83
+ end
84
+
85
+ context '.where' do
86
+ should 'return suppression objects' do
87
+ suppressions = ESP::Suppression.where(id_eq: @s.id)
88
+
89
+ assert_equal ESP::Suppression, suppressions.resource_class
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class Suppression
5
+ class RegionTest < ESP::Integration::TestCase
6
+ context ESP::Suppression::Region do
7
+ context 'live calls' do
8
+ context '.create' do
9
+ should 'return error when reason is not supplied' do
10
+ signature_id = ESP::Signature.last.id
11
+ external_account_id = ESP::ExternalAccount.last.id
12
+ region = ESP::Region.last
13
+
14
+ suppression = ESP::Suppression::Region.create(signature_ids: [signature_id], custom_signature_ids: [], regions: [region.code], external_account_ids: [external_account_id])
15
+
16
+ assert_equal "Suppression reason can't be blank", suppression.errors.full_messages.first
17
+ end
18
+
19
+ should 'return suppression' do
20
+ signature_id = ESP::Signature.last.id
21
+ external_account_id = ESP::ExternalAccount.last.id
22
+ region = ESP::Region.last
23
+
24
+ suppression = ESP::Suppression::Region.create(signature_ids: [signature_id], custom_signature_ids: [], reason: 'test', regions: [region.code], external_account_ids: [external_account_id])
25
+
26
+ assert_equal ESP::Suppression::Region, suppression.class
27
+ end
28
+
29
+ context 'for_alert' do
30
+ should 'return error when reason is not supplied' do
31
+ alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
32
+
33
+ suppression = ESP::Suppression::Region.create(alert_id: alert_id)
34
+
35
+ assert_equal "Suppression reason can't be blank", suppression.errors.full_messages.first
36
+ end
37
+
38
+ should 'return suppression' do
39
+ alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
40
+
41
+ suppression = ESP::Suppression::Region.create(alert_id: alert_id, reason: 'test')
42
+
43
+ assert_predicate suppression.errors, :blank?
44
+ assert_equal ESP::Suppression::Region, suppression.class
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class Suppression
5
+ class SignatureTest < ESP::Integration::TestCase
6
+ context ESP::Suppression::Signature do
7
+ context 'live calls' do
8
+ context '.create' do
9
+ should 'return error when reason is not supplied' do
10
+ signature_id = ESP::Signature.last.id
11
+ external_account_id = ESP::ExternalAccount.last.id
12
+ region = ESP::Region.last
13
+
14
+ suppression = ESP::Suppression::Signature.create(signature_ids: [signature_id], custom_signature_ids: [], regions: [region.code], external_account_ids: [external_account_id])
15
+
16
+ assert_equal "Suppression reason can't be blank", suppression.errors.full_messages.first
17
+ end
18
+
19
+ should 'return suppression' do
20
+ signature_id = ESP::Signature.last.id
21
+ external_account_id = ESP::ExternalAccount.last.id
22
+ region = ESP::Region.last
23
+
24
+ suppression = ESP::Suppression::Signature.create(signature_ids: [signature_id], custom_signature_ids: [], reason: 'test', regions: [region.code], external_account_ids: [external_account_id])
25
+
26
+ assert_equal ESP::Suppression::Signature, suppression.class
27
+ end
28
+
29
+ context 'for_alert' do
30
+ should 'return error when reason is not supplied' do
31
+ alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
32
+
33
+ suppression = ESP::Suppression::Signature.create(alert_id: alert_id)
34
+
35
+ assert_equal "Suppression reason can't be blank", suppression.errors.full_messages.first
36
+ end
37
+
38
+ should 'return suppression' do
39
+ alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
40
+
41
+ suppression = ESP::Suppression::Signature.create(alert_id: alert_id, reason: 'test')
42
+
43
+ assert_predicate suppression.errors, :blank?
44
+ assert_equal ESP::Suppression::Signature, suppression.class
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class Suppression
5
+ class UniqueIdentifierTest < ESP::Integration::TestCase
6
+ context ESP::Suppression::UniqueIdentifier do
7
+ context 'live calls' do
8
+ context '.create' do
9
+ should 'return error when reason is not supplied' do
10
+ alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
11
+
12
+ suppression = ESP::Suppression::UniqueIdentifier.create(alert_id: alert_id)
13
+
14
+ assert_equal "Suppression reason can't be blank", suppression.errors.full_messages.first
15
+ end
16
+
17
+ should 'return suppression' do
18
+ alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
19
+
20
+ suppression = ESP::Suppression::UniqueIdentifier.create(alert_id: alert_id, reason: 'test')
21
+
22
+ assert_predicate suppression.errors, :blank?
23
+ assert_equal ESP::Suppression::UniqueIdentifier, suppression.class
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class TagTest < ESP::Integration::TestCase
5
+ context ESP::Tag do
6
+ context 'live calls' do
7
+ context '.for_alert' do
8
+ should 'return tags for alert id' do
9
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
10
+ events = ESP::Tag.for_alert(report.alerts.last.id)
11
+
12
+ assert_equal ESP::Tag, events.resource_class
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,87 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class TeamTest < ESP::Integration::TestCase
5
+ context ESP::Team do
6
+ context 'live calls' do
7
+ setup do
8
+ @team = ESP::Team.last
9
+ fail "Live DB does not have any teams. Add a team and run tests again." if @team.blank?
10
+ end
11
+
12
+ context '#organization' do
13
+ should 'return an organization' do
14
+ org = @team.organization
15
+
16
+ assert_equal @team.organization_id, org.id
17
+ end
18
+ end
19
+
20
+ context '#sub_organization' do
21
+ should 'return a sub_organization' do
22
+ sub_org = @team.sub_organization
23
+
24
+ assert_equal @team.sub_organization_id, sub_org.id
25
+ end
26
+ end
27
+
28
+ context '#external_accounts' do
29
+ should 'return an array of external_accounts' do
30
+ external_accounts = @team.external_accounts
31
+
32
+ assert_equal ESP::ExternalAccount, external_accounts.resource_class
33
+ end
34
+ end
35
+
36
+ context '#custom_signatures' do
37
+ should 'return an array of custom_signatures' do
38
+ custom_signatures = @team.custom_signatures
39
+
40
+ assert_equal ESP::CustomSignature, custom_signatures.resource_class
41
+ end
42
+ end
43
+
44
+ context '#reports' do
45
+ should 'return an array of reports' do
46
+ reports = @team.reports
47
+
48
+ assert_equal ESP::Report, reports.resource_class
49
+ end
50
+ end
51
+
52
+ context '.where' do
53
+ should 'return team objects' do
54
+ teams = ESP::Team.where(name_eq: @team.name)
55
+
56
+ assert_equal ESP::Team, teams.resource_class
57
+ end
58
+ end
59
+
60
+ context '#CRUD' do
61
+ should 'be able to create, update and destroy' do
62
+ team = ESP::Team.new(name: 'bob', organization_id: @team.organization_id, sub_organization_id: @team.sub_organization_id)
63
+
64
+ assert_predicate team, :new?
65
+
66
+ team.save
67
+
68
+ refute_predicate team, :new?
69
+
70
+ team.name = 'jim'
71
+ team.save
72
+
73
+ assert_nothing_raised do
74
+ ESP::Team.find(team.id)
75
+ end
76
+
77
+ team.destroy
78
+
79
+ assert_raises ActiveResource::ResourceNotFound do
80
+ ESP::Team.find(team.id)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class UserTest < ESP::Integration::TestCase
5
+ context ESP::User do
6
+ context 'live calls' do
7
+ setup do
8
+ @user = ESP::User.last
9
+ fail "Live DB does not have any users. Add a user and run tests again." if @user.blank?
10
+ end
11
+
12
+ teardown do
13
+ WebMock.disable_net_connect!
14
+ end
15
+
16
+ context '#organization' do
17
+ should 'return an organization' do
18
+ org = @user.organization
19
+
20
+ assert_equal @user.organization_id, org.id
21
+ end
22
+ end
23
+
24
+ context '#sub_organizations' do
25
+ should 'return an array of sub_organizations' do
26
+ sub_orgs = @user.sub_organizations
27
+
28
+ assert_equal @user.sub_organization_ids.count, sub_orgs.count
29
+ assert_equal @user.sub_organization_ids, sub_orgs.map(&:id)
30
+ end
31
+ end
32
+
33
+ context '#teams' do
34
+ should 'return an array of teams' do
35
+ teams = @user.teams
36
+
37
+ assert_equal @user.team_ids.count, teams.count
38
+ assert_equal @user.team_ids.sort, teams.map(&:id).sort
39
+ end
40
+ end
41
+
42
+ context '.where' do
43
+ should 'return user objects' do
44
+ users = ESP::User.where(id_eq: @user.id)
45
+
46
+ assert_equal ESP::User, users.resource_class
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class ValidationsTest < ESP::Integration::TestCase
5
+ context ActiveResource::Validations do
6
+ context 'live calls' do
7
+ context "#load_remote_errors" do
8
+ should 'should parse the response and put error messages in the errors object' do
9
+ team = ESP::Team.create(name: 'bob')
10
+
11
+ assert_contains team.errors.full_messages, "Organization can't be blank"
12
+ assert_contains team.errors.full_messages, "Organization can't be blank"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end