wavefront-sdk 3.3.2 → 3.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +42 -35
  3. data/README.md +5 -5
  4. data/lib/wavefront-sdk/alert.rb +2 -0
  5. data/lib/wavefront-sdk/core/api_caller.rb +6 -3
  6. data/lib/wavefront-sdk/defs/version.rb +2 -2
  7. data/lib/wavefront-sdk/derivedmetric.rb +7 -0
  8. data/lib/wavefront-sdk/externallink.rb +2 -2
  9. data/lib/wavefront-sdk/maintenancewindow.rb +6 -2
  10. data/lib/wavefront-sdk/notificant.rb +7 -0
  11. data/lib/wavefront-sdk/paginator/base.rb +8 -0
  12. data/lib/wavefront-sdk/search.rb +11 -2
  13. data/lib/wavefront-sdk/user.rb +39 -8
  14. data/lib/wavefront-sdk/webhook.rb +1 -1
  15. data/spec/constants.rb +30 -0
  16. data/spec/spec_helper.rb +12 -237
  17. data/spec/support/bad_mocket.rb +15 -0
  18. data/spec/support/hash.rb +9 -0
  19. data/spec/support/minitest_assertions.rb +110 -0
  20. data/spec/support/mocket.rb +19 -0
  21. data/spec/test_mixins/acl.rb +78 -0
  22. data/spec/test_mixins/general.rb +120 -0
  23. data/spec/test_mixins/tag.rb +55 -0
  24. data/spec/test_mixins/update_keys.rb +11 -0
  25. data/spec/wavefront-sdk/alert_spec.rb +88 -136
  26. data/spec/wavefront-sdk/apitoken_spec.rb +26 -13
  27. data/spec/wavefront-sdk/cloudintegration_spec.rb +42 -44
  28. data/spec/wavefront-sdk/dashboard_spec.rb +53 -72
  29. data/spec/wavefront-sdk/derivedmetric_spec.rb +23 -49
  30. data/spec/wavefront-sdk/distribution_spec.rb +14 -14
  31. data/spec/wavefront-sdk/event_spec.rb +39 -48
  32. data/spec/wavefront-sdk/externallink_spec.rb +19 -50
  33. data/spec/wavefront-sdk/integration_spec.rb +33 -38
  34. data/spec/wavefront-sdk/maintenancewindow_spec.rb +18 -33
  35. data/spec/wavefront-sdk/message_spec.rb +19 -4
  36. data/spec/wavefront-sdk/metric_spec.rb +13 -9
  37. data/spec/wavefront-sdk/notificant_spec.rb +16 -15
  38. data/spec/wavefront-sdk/proxy_spec.rb +20 -25
  39. data/spec/wavefront-sdk/query_spec.rb +50 -24
  40. data/spec/wavefront-sdk/report_spec.rb +3 -6
  41. data/spec/wavefront-sdk/resources/user_responses/add_user_groups.json +1 -0
  42. data/spec/wavefront-sdk/resources/user_responses/create.json +28 -0
  43. data/spec/wavefront-sdk/resources/user_responses/delete_multiple.json +1 -0
  44. data/spec/wavefront-sdk/resources/user_responses/describe.json +1 -0
  45. data/spec/wavefront-sdk/resources/user_responses/grant.json +1 -0
  46. data/spec/wavefront-sdk/resources/user_responses/list.json +1 -0
  47. data/spec/wavefront-sdk/savedsearch_spec.rb +41 -35
  48. data/spec/wavefront-sdk/search_spec.rb +35 -29
  49. data/spec/wavefront-sdk/settings_spec.rb +18 -12
  50. data/spec/wavefront-sdk/source_spec.rb +29 -32
  51. data/spec/wavefront-sdk/user_spec.rb +101 -74
  52. data/spec/wavefront-sdk/usergroup_spec.rb +56 -67
  53. data/spec/wavefront-sdk/webhook_spec.rb +22 -34
  54. data/spec/wavefront-sdk/write_spec.rb +2 -0
  55. data/spec/wavefront-sdk/writers/core_spec.rb +2 -0
  56. data/spec/wavefront-sdk/writers/summary_spec.rb +2 -0
  57. data/wavefront-sdk.gemspec +5 -5
  58. metadata +44 -13
@@ -1,41 +1,36 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- PROXY = 'fd248f53-378e-4fbe-bbd3-efabace8d724'.freeze
4
+ require_relative '../test_mixins/general'
6
5
 
7
6
  # Unit tests for proxy class
8
7
  #
9
8
  class WavefrontProxyTest < WavefrontTestBase
10
- def test_list
11
- should_work(:list, 10, '?offset=10&limit=100')
12
- end
9
+ include WavefrontTest::DeleteUndelete
10
+ include WavefrontTest::Describe
11
+ include WavefrontTest::List
12
+
13
+ def test_rename
14
+ assert_puts("/api/v2/proxy/#{id}", name: 'newname') do
15
+ wf.rename(id, 'newname')
16
+ end
13
17
 
14
- def test_describe
15
- should_work(:describe, PROXY, PROXY)
16
- should_be_invalid(:describe)
17
- assert_raises(ArgumentError) { wf.describe }
18
+ assert_invalid_id { wf.rename(invalid_id, 'newname') }
19
+ assert_raises(ArgumentError) { wf.rename(id) }
20
+ assert_raises(ArgumentError) { wf.rename }
18
21
  end
19
22
 
20
- def test_delete
21
- should_work(:delete, PROXY, PROXY, :delete)
22
- should_be_invalid('delete')
23
+ private
24
+
25
+ def api_class
26
+ 'proxy'
23
27
  end
24
28
 
25
- def test_rename
26
- should_work(:rename, [PROXY, 'newname'],
27
- [PROXY, { name: 'newname' }.to_json], :put,
28
- JSON_POST_HEADERS)
29
- assert_raises(ArgumentError) { wf.rename }
30
- assert_raises(ArgumentError) { wf.rename('abc123') }
31
- assert_raises(Wavefront::Exception::InvalidProxyId) do
32
- wf.rename('abc', 'name')
33
- end
29
+ def id
30
+ 'fd248f53-378e-4fbe-bbd3-efabace8d724'
34
31
  end
35
32
 
36
- def test_undelete
37
- should_work(:undelete, PROXY, ["#{PROXY}/undelete", nil],
38
- :post, POST_HEADERS)
39
- should_be_invalid('undelete')
33
+ def invalid_id
34
+ 'my awesome stupid proxy id'
40
35
  end
41
36
  end
@@ -4,30 +4,47 @@ require 'cgi'
4
4
  require 'date'
5
5
  require_relative '../spec_helper'
6
6
 
7
- SERIES = 'test.metric'.freeze
8
- T = Time.now.freeze
9
- T_MS = T.to_datetime.strftime('%Q').freeze
10
- TE = (T + 10).freeze
11
- TE_MS = TE.to_datetime.strftime('%Q')
12
- Q = "ts(\"#{SERIES}\")".freeze
13
- QE = CGI.escape(Q).freeze
14
-
15
7
  # Unit tests for Query class
16
8
  #
17
9
  class WavefrontQueryTest < WavefrontTestBase
18
- def api_base
19
- 'chart'
10
+ attr_reader :series, :t_start, :t_start_in_ms, :t_end, :t_end_in_ms,
11
+ :query, :escaped_query
12
+
13
+ def setup_fixtures
14
+ @series = 'test.metric'
15
+ @t_start = Time.now
16
+ @t_start_in_ms = t_start.to_datetime.strftime('%Q')
17
+ @t_end = t_start + 10
18
+ @t_end_in_ms = t_end.to_datetime.strftime('%Q')
19
+ @query = "ts(\"#{series}\")"
20
+ @escaped_query = CGI.escape(query)
20
21
  end
21
22
 
22
23
  def test_query
23
- should_work(:query, [Q, 'd', T_MS], "api?q=#{QE}&g=d&s=#{T_MS}")
24
- should_work(:query, [Q, 'h', T], "api?q=#{QE}&g=h&s=#{T_MS}")
25
- should_work(:query, [Q, 'm', T, TE],
26
- "api?q=#{QE}&g=m&s=#{T_MS}&e=#{TE_MS}")
27
- should_work(:query, [Q, 'h', T, nil, {}], "api?q=#{Q}&g=h&s=#{T_MS}")
28
- should_work(:query, [Q, 'h', T, nil, { strict: true,
29
- summarization: 'MAX' }],
30
- "api?q=#{QE}&g=h&s=#{T_MS}&strict=true&summarization=MAX")
24
+ assert_gets("/api/v2/chart/api?q=#{escaped_query}&g=d&" \
25
+ "s=#{t_start_in_ms}") do
26
+ wf.query(query, 'd', t_start_in_ms)
27
+ end
28
+
29
+ assert_gets("/api/v2/chart/api?q=#{escaped_query}&g=h&" \
30
+ "s=#{t_start_in_ms}") do
31
+ wf.query(query, 'h', t_start)
32
+ end
33
+
34
+ assert_gets("/api/v2/chart/api?q=#{escaped_query}&g=m&" \
35
+ "s=#{t_start_in_ms}&e=#{t_end_in_ms}") do
36
+ wf.query(query, 'm', t_start, t_end)
37
+ end
38
+
39
+ assert_gets("/api/v2/chart/api?q=#{query}&g=h&s=#{t_start_in_ms}") do
40
+ wf.query(query, 'h', t_start, nil, {})
41
+ end
42
+
43
+ assert_gets("/api/v2/chart/api?q=#{escaped_query}&g=h&" \
44
+ "s=#{t_start_in_ms}&strict=true&summarization=MAX") do
45
+ wf.query(query, 'h', t_start, nil, strict: true,
46
+ summarization: 'MAX')
47
+ end
31
48
 
32
49
  assert_raises(ArgumentError) { wf.query }
33
50
 
@@ -41,12 +58,21 @@ class WavefrontQueryTest < WavefrontTestBase
41
58
  end
42
59
 
43
60
  def test_raw
44
- should_work(:raw, [SERIES, 'src'], "raw?metric=#{SERIES}&source=src")
45
- should_work(:raw, [SERIES, 'src', T],
46
- "raw?metric=#{SERIES}&source=src&startTime=#{T_MS}")
47
- should_work(:raw, [SERIES, 'src', T, TE],
48
- "raw?metric=#{SERIES}&source=src&startTime=#{T_MS}" \
49
- "&endTime=#{TE_MS}")
61
+ assert_gets("/api/v2/chart/raw?metric=#{series}&source=src") do
62
+ wf.raw(series, 'src')
63
+ end
64
+
65
+ assert_gets("/api/v2/chart/raw?metric=#{series}&source=src&" \
66
+ "startTime=#{t_start_in_ms}") do
67
+ wf.raw(series, 'src', t_start)
68
+ end
69
+
70
+ assert_gets("/api/v2/chart/raw?metric=#{series}&source=src&" \
71
+ "startTime=#{t_start_in_ms}" \
72
+ "&endTime=#{t_end_in_ms}") do
73
+ wf.raw(series, 'src', t_start, t_end)
74
+ end
75
+
50
76
  assert_raises(ArgumentError) { wf.raw }
51
77
  end
52
78
  end
@@ -8,12 +8,9 @@ REPORT_HEADERS = POST_HEADERS.merge('Content-Type': 'application/octet-stream')
8
8
  # Unit tests for Report class
9
9
  #
10
10
  class WavefrontReportTest < WavefrontTestBase
11
- def uri_base
12
- "https://#{CREDS[:endpoint]}/report"
13
- end
14
-
15
11
  def test_write
16
- should_work(:write, POINT, ['?f=wavefront', nil],
17
- :post, REPORT_HEADERS, POINT_L)
12
+ assert_posts('/report?f=wavefront', POINT_L, :octet) do
13
+ wf.write(POINT)
14
+ end
18
15
  end
19
16
  end
@@ -0,0 +1 @@
1
+ {"identifier":"slackboy@gmail.com","customer":"sysdef","lastSuccessfulLogin":1535977667674,"groups":["host_tag_management","dashboard_management","embedded_charts","metrics_management","agent_management","events_management","external_links_management","alerts_management","ingestion","user_management","application_management"],"userGroups":[{"id":"2659191e-aad4-4302-a94e-9667e1517127","name":"Everyone","permissions":[],"customer":"sysdef","properties":{"nameEditable":false,"permissionsEditable":true,"usersEditable":false},"description":"System group which contains all users"},{"id":"6fd972d9-9a20-4872-acf9-4ef34797f14e","name":"grp1","permissions":["host_tag_management","alerts_management"],"customer":"sysdef"}]}
@@ -0,0 +1,28 @@
1
+ {
2
+ "status": {
3
+ "result": "OK",
4
+ "message": "Invalid user groups found and ignored [8b23136b-ecd2-4cb5-8c92-62477dcc4090]",
5
+ "code": 202
6
+ },
7
+ "response": {
8
+ "identifier": "user@example.com",
9
+ "customer": "sysdef",
10
+ "groups": [
11
+ "user_management"
12
+ ],
13
+ "userGroups": [
14
+ {
15
+ "id": "2659191e-aad4-4302-a94e-9667e1517127",
16
+ "name": "Everyone",
17
+ "permissions": [],
18
+ "customer": "sysdef",
19
+ "properties": {
20
+ "nameEditable": false,
21
+ "permissionsEditable": true,
22
+ "usersEditable": false
23
+ },
24
+ "description": "System group which contains all users"
25
+ }
26
+ ]
27
+ }
28
+ }
@@ -0,0 +1 @@
1
+ {"status":{"result":"OK","message":"","code":200},"response":["user@example.com"]}
@@ -0,0 +1 @@
1
+ {"identifier":"user1@merp.com","customer":"sysdef","groups":[],"userGroups":[{"id":"2659191e-aad4-4302-a94e-9667e1517127","name":"Everyone","permissions":[],"customer":"sysdef","properties":{"nameEditable":false,"permissionsEditable":true,"usersEditable":false},"description":"System group which contains all users"}]}
@@ -0,0 +1 @@
1
+ {"identifier":"user1@merp.com","customer":"sysdef","groups":["host_tag_management"],"userGroups":[{"id":"2659191e-aad4-4302-a94e-9667e1517127","name":"Everyone","permissions":[],"customer":"sysdef","properties":{"nameEditable":false,"permissionsEditable":true,"usersEditable":false},"description":"System group which contains all users"}]}
@@ -0,0 +1 @@
1
+ [{"identifier":"dev+sysdef@wavefront.com","customer":"sysdef","lastSuccessfulLogin":1549996596333,"groups":["agent_management","alerts_management","dashboard_management","ingestion","events_management","host_tag_management","user_management","embedded_charts","metrics_management","application_management","external_links_management"]},{"identifier":"rob.fisher@hivehome.com","customer":"sysdef","lastSuccessfulLogin":1560162693875,"groups":["user_management","alerts_management"]},{"identifier":"rob@sysdef.xyz","customer":"sysdef","lastSuccessfulLogin":1567547135169,"groups":["agent_management","host_tag_management","events_management","alerts_management","dashboard_management","metrics_management","embedded_charts","ingestion","user_management","application_management","external_links_management"]},{"identifier":"sam@outsidethe.net","customer":"sysdef","lastSuccessfulLogin":1558370774253,"groups":[]},{"identifier":"services@id264.net","customer":"sysdef","groups":[]},{"identifier":"slackboy@gmail.com","customer":"sysdef","lastSuccessfulLogin":1535977667674,"groups":["host_tag_management","dashboard_management","embedded_charts","metrics_management","agent_management","events_management","external_links_management","alerts_management","ingestion","user_management","application_management"]},{"identifier":"test1@sysdef.xyz","customer":"sysdef","groups":[]},{"identifier":"test@sysdef.xyz","customer":"sysdef","groups":[]},{"identifier":"user1@merp.com","customer":"sysdef","groups":[]}]
@@ -1,54 +1,60 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- SAVED_SEARCH = 'e2hLH2FR'.freeze
6
- SAVED_SEARCH_BODY = {
7
- query: {
8
- foo: '{"searchTerms":[{"type":"freetext","value":"foo"}]}'
9
- },
10
- entityType: 'DASHBOARD'
11
- }.freeze
4
+ require_relative '../test_mixins/general'
12
5
 
13
6
  # Unit tests for SavedSearch class
14
7
  #
15
8
  class WavefrontSavedSearchTest < WavefrontTestBase
16
- def test_list
17
- should_work(:list, [], '?offset=0&limit=100')
18
- should_work(:list, 10, '?offset=10&limit=100')
19
- should_work(:list, [20, 250], '?offset=20&limit=250')
9
+ include WavefrontTest::Create
10
+ include WavefrontTest::Delete
11
+ include WavefrontTest::Describe
12
+ include WavefrontTest::List
13
+ include WavefrontTest::Update
14
+
15
+ def test_update
16
+ assert_puts("/api/v2/savedsearch/#{id}", payload) do
17
+ wf.update(id, payload)
18
+ end
19
+
20
+ assert_invalid_id { wf.update(invalid_id, payload) }
21
+ assert_raises(ArgumentError) { wf.update }
20
22
  end
21
23
 
22
- def test_create
23
- should_work(:create, SAVED_SEARCH_BODY, '', :post, JSON_POST_HEADERS,
24
- SAVED_SEARCH_BODY.to_json)
25
- assert_raises(ArgumentError) { wf.create }
26
- assert_raises(ArgumentError) { wf.create('test') }
24
+ def test_entity
25
+ %w[ALERT EVENT MAINTENANCE_WINDOW DASHBOARD SOURCE AGENT].each do |e|
26
+ assert_gets("/api/v2/savedsearch/type/#{e}?offset=0&limit=100") do
27
+ wf.entity(e)
28
+ end
29
+
30
+ assert_gets("/api/v2/savedsearch/type/#{e}?offset=20&limit=100") do
31
+ wf.entity(e, 20)
32
+ end
33
+
34
+ assert_gets("/api/v2/savedsearch/type/#{e}?offset=10&limit=50") do
35
+ wf.entity(e, 10, 50)
36
+ end
37
+ end
27
38
  end
28
39
 
29
- def test_delete
30
- should_work(:delete, SAVED_SEARCH, SAVED_SEARCH, :delete)
31
- should_be_invalid(:delete)
40
+ private
41
+
42
+ def api_class
43
+ 'savedsearch'
32
44
  end
33
45
 
34
- def test_describe
35
- should_work(:describe, SAVED_SEARCH, SAVED_SEARCH)
36
- should_be_invalid(:describe)
46
+ def id
47
+ 'e2hLH2FR'
37
48
  end
38
49
 
39
- def test_update
40
- should_work(:update, [SAVED_SEARCH, SAVED_SEARCH_BODY],
41
- SAVED_SEARCH, :put, JSON_POST_HEADERS,
42
- SAVED_SEARCH_BODY.to_json)
43
- should_be_invalid(:update, ['abcde', SAVED_SEARCH_BODY])
44
- assert_raises(ArgumentError) { wf.update }
50
+ def invalid_id
51
+ 'some bad id or other'
45
52
  end
46
53
 
47
- def test_entity
48
- %w[ALERT EVENT MAINTENANCE_WINDOW DASHBOARD SOURCE AGENT].each do |e|
49
- should_work(:entity, e, "type/#{e}?offset=0&limit=100")
50
- should_work(:entity, [e, 20], "type/#{e}?offset=20&limit=100")
51
- should_work(:entity, [e, 20, 50], "type/#{e}?offset=20&limit=50")
52
- end
54
+ def payload
55
+ { query: {
56
+ foo: '{"searchTerms":[{"type":"freetext","value":"foo"}]}'
57
+ },
58
+ entityType: 'DASHBOARD' }
53
59
  end
54
60
  end
@@ -2,44 +2,38 @@
2
2
 
3
3
  require_relative '../spec_helper'
4
4
 
5
- SEARCH_BODY = {
6
- limit: 10,
7
- offset: 0,
8
- query: [{ key: 'name',
9
- value: 'Wavefront',
10
- matchingMethod: 'CONTAINS' }],
11
- sort: { field: 'string',
12
- ascending: true }
13
- }.freeze
14
-
15
5
  # Unit tests for Search class
16
6
  #
17
7
  class WavefrontSearchTest < WavefrontTestBase
18
- def test_search
19
- should_work(:raw_search, ['agent', SEARCH_BODY], 'agent', :post,
20
- JSON_POST_HEADERS, SEARCH_BODY.to_json)
21
- should_work(:raw_search, ['agent', SEARCH_BODY, true], 'agent/deleted',
22
- :post, JSON_POST_HEADERS, SEARCH_BODY.to_json)
23
- assert_raises(ArgumentError) { wf.raw_search }
8
+ def test_raw_search
9
+ assert_posts('/api/v2/search/agent', payload) do
10
+ wf.raw_search('agent', payload)
11
+ end
12
+
13
+ assert_posts('/api/v2/search/agent/deleted', payload) do
14
+ wf.raw_search('agent', payload, true)
15
+ end
16
+
24
17
  assert_raises(ArgumentError) { wf.raw_search('ALERT', 'junk') }
18
+ assert_raises(ArgumentError) { wf.raw_search }
25
19
  end
26
20
 
27
- def test_facet_search
28
- should_work(:raw_facet_search, ['agent', SEARCH_BODY],
29
- 'agent/facets', :post, JSON_POST_HEADERS,
30
- SEARCH_BODY.to_json)
21
+ def test_raw_facet_search
22
+ assert_posts('/api/v2/search/agent/facets', payload) do
23
+ wf.raw_facet_search('agent', payload)
24
+ end
31
25
 
32
- should_work(:raw_facet_search, ['agent', SEARCH_BODY, true],
33
- 'agent/deleted/facets', :post, JSON_POST_HEADERS,
34
- SEARCH_BODY.to_json)
26
+ assert_posts('/api/v2/search/agent/deleted/facets', payload) do
27
+ wf.raw_facet_search('agent', payload, true)
28
+ end
35
29
 
36
- should_work(:raw_facet_search, ['agent', SEARCH_BODY, false, 'Tags'],
37
- 'agent/Tags', :post, JSON_POST_HEADERS,
38
- SEARCH_BODY.to_json)
30
+ assert_posts('/api/v2/search/agent/Tags', payload) do
31
+ wf.raw_facet_search('agent', payload, false, 'Tags')
32
+ end
39
33
 
40
- should_work(:raw_facet_search, ['agent', SEARCH_BODY, true, 'Tags'],
41
- 'agent/deleted/Tags', :post, JSON_POST_HEADERS,
42
- SEARCH_BODY.to_json)
34
+ assert_posts('/api/v2/search/agent/deleted/Tags', payload) do
35
+ wf.raw_facet_search('agent', payload, true, 'Tags')
36
+ end
43
37
 
44
38
  assert_raises(ArgumentError) { wf.raw_facet_search }
45
39
  assert_raises(ArgumentError) { wf.raw_facet_search('ALERT', 'junk') }
@@ -72,4 +66,16 @@ class WavefrontSearchTest < WavefrontTestBase
72
66
  r4 = wf.body(q, sort_field: :mykey)
73
67
  assert_equal({ field: :mykey, ascending: true }, r4[:sort])
74
68
  end
69
+
70
+ private
71
+
72
+ def payload
73
+ { limit: 10,
74
+ offset: 0,
75
+ query: [{ key: 'name',
76
+ value: 'Wavefront',
77
+ matchingMethod: 'CONTAINS' }],
78
+ sort: { field: 'string',
79
+ ascending: true } }
80
+ end
75
81
  end
@@ -2,30 +2,36 @@
2
2
 
3
3
  require_relative '../spec_helper'
4
4
 
5
- SETTINGS_BODY = { showQuerybuilderByDefault: true,
6
- hideTSWhenQuerybuilderShown: true }.freeze
7
-
8
5
  # Unit tests for Settings class
9
6
  #
10
7
  class WavefrontSettingsTest < WavefrontTestBase
11
- def api_base
12
- 'customer'
13
- end
14
-
15
8
  def test_permissions
16
- should_work(:permissions, nil, 'permissions')
9
+ assert_gets('/api/v2/customer/permissions') do
10
+ wf.permissions
11
+ end
17
12
  end
18
13
 
19
14
  def test_preferences
20
- should_work(:preferences, nil, 'preferences')
15
+ assert_gets('/api/v2/customer/preferences') do
16
+ wf.preferences
17
+ end
21
18
  end
22
19
 
23
20
  def test_update_preferences
24
- should_work(:update_preferences, SETTINGS_BODY, 'preferences',
25
- :post, JSON_POST_HEADERS, SETTINGS_BODY.to_json)
21
+ assert_posts('/api/v2/customer/preferences', payload) do
22
+ wf.update_preferences(payload)
23
+ end
26
24
  end
27
25
 
28
26
  def test_default_user_groups
29
- should_work(:default_user_groups, nil, 'preferences/defaultUserGroups')
27
+ assert_gets('/api/v2/customer/preferences/defaultUserGroups') do
28
+ wf.default_user_groups
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def payload
35
+ { showQuerybuilderByDefault: true, hideTSWhenQuerybuilderShown: true }
30
36
  end
31
37
  end
@@ -1,51 +1,48 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../spec_helper'
4
-
5
- SOURCE = '74a247a9-f67c-43ad-911f-fabafa9dc2f3joyent'.freeze
6
- SOURCE_BODY = {
7
- sourceName: 'source.name',
8
- tags: {
9
- sourceTag1: true
10
- },
11
- description: 'Source Description'
12
- }.freeze
4
+ require_relative '../test_mixins/general'
5
+ require_relative '../test_mixins/tag'
13
6
 
14
7
  # Unit tests for Source class
15
8
  #
16
9
  class WavefrontSourceTest < WavefrontTestBase
10
+ include WavefrontTest::Create
11
+ include WavefrontTest::Delete
12
+ include WavefrontTest::Describe
13
+ include WavefrontTest::Tag
14
+ include WavefrontTest::Update
15
+
17
16
  def test_list
18
- should_work(:list, [], '')
19
- should_work(:list, 10, '?limit=10')
20
- should_work(:list, [10, 'mysource'], '?limit=10&cursor=mysource')
21
- should_work(:list, [nil, 'mysource'], '?cursor=mysource')
22
- end
17
+ assert_gets('/api/v2/source') { wf.list }
18
+ assert_gets('/api/v2/source?limit=10') { wf.list(10) }
23
19
 
24
- def test_create
25
- should_work(:create, SOURCE_BODY, '', :post,
26
- JSON_POST_HEADERS, SOURCE_BODY.to_json)
27
- assert_raises(ArgumentError) { wf.create }
28
- assert_raises(ArgumentError) { wf.create('test') }
20
+ assert_gets('/api/v2/source?limit=10&cursor=mysource') do
21
+ wf.list(10, 'mysource')
22
+ end
23
+
24
+ assert_gets('/api/v2/source?cursor=mysource') do
25
+ wf.list(nil, 'mysource')
26
+ end
29
27
  end
30
28
 
31
- def test_describe
32
- should_work(:describe, SOURCE, SOURCE)
33
- assert_raises(ArgumentError) { wf.describe }
29
+ private
30
+
31
+ def api_class
32
+ 'source'
34
33
  end
35
34
 
36
- def test_delete
37
- should_work(:delete, SOURCE, SOURCE, :delete)
38
- should_be_invalid(:delete)
35
+ def id
36
+ '74a247a9-f67c-43ad-911f-fabafa9dc2f3joyent'
39
37
  end
40
38
 
41
- def test_update
42
- should_work(:update, [SOURCE, SOURCE_BODY, false], SOURCE, :put,
43
- JSON_POST_HEADERS, SOURCE_BODY.to_json)
44
- should_be_invalid(:update, ['!invalid source!', SOURCE_BODY])
45
- assert_raises(ArgumentError) { wf.update }
39
+ def invalid_id
40
+ '(>_<)'
46
41
  end
47
42
 
48
- def test_tags
49
- tag_tester(SOURCE)
43
+ def payload
44
+ { sourceName: 'source.name',
45
+ tags: { sourceTag1: true },
46
+ description: 'Source Description' }
50
47
  end
51
48
  end