datarobot-ai_api 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +3 -0
  4. data/README.md +12 -0
  5. data/Rakefile +54 -0
  6. data/datarobot-ai_api.gemspec +19 -0
  7. data/lib/datarobot.rb +1 -0
  8. data/lib/datarobot/ai_api.rb +190 -0
  9. data/lib/datarobot/ai_api/ai.rb +191 -0
  10. data/lib/datarobot/ai_api/dataset.rb +99 -0
  11. data/lib/datarobot/ai_api/deployment.rb +20 -0
  12. data/lib/datarobot/ai_api/evaluation.rb +21 -0
  13. data/lib/datarobot/ai_api/learning_session.rb +112 -0
  14. data/lib/datarobot/ai_api/output.rb +58 -0
  15. data/lib/datarobot/ai_api/page.rb +50 -0
  16. data/lib/datarobot/ai_api/prediction.rb +20 -0
  17. data/lib/datarobot/ai_api/refreshable.rb +20 -0
  18. data/lib/datarobot/ai_api/task.rb +86 -0
  19. data/test/cassettes/Datarobot_AiApi/_ping/returns_unauthorized_when_not_authorized.yml +41 -0
  20. data/test/cassettes/Datarobot_AiApi/_ping/works_when_authorized.yml +58 -0
  21. data/test/cassettes/Datarobot_AiApi/_ping_me/returns_unauthorized_when_not_authorized.yml +41 -0
  22. data/test/cassettes/Datarobot_AiApi/_ping_me/works_when_authorized.yml +58 -0
  23. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/404s_if_there_is_no_matching_output.yml +190 -0
  24. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/_find/should_accept_a_block.yml +66 -0
  25. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/_next_page/can_go_to_the_next_page.yml +132 -0
  26. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/_next_page/returns_the_same_page_if_there_is_no_next_page.yml +123 -0
  27. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/_previous_page/can_go_to_the_previous_page.yml +262 -0
  28. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/_previous_page/returns_the_same_page_if_there_is_no_previous_page.yml +67 -0
  29. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/_refresh/can_refresh_to_a_new_object.yml +129 -0
  30. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/_refresh_/can_refresh_its_values.yml +129 -0
  31. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_add_datasets_to_AIs.yml +120 -0
  32. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_add_learning_sessions_to_AIs.yml +120 -0
  33. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_be_trained.yml +4554 -0
  34. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_create_AIs.yml +120 -0
  35. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_delete_AIs.yml +58 -0
  36. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_find_AIs.yml +63 -0
  37. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_get_AI_datasets.yml +131 -0
  38. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_get_AI_outputs.yml +124 -0
  39. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_list_AIs.yml +123 -0
  40. data/test/cassettes/Datarobot_AiApi_AI/when_authorized/can_predict_things.yml +190 -0
  41. data/test/cassettes/Datarobot_AiApi_AI/when_not_authorized/can_not_create_AIs.yml +43 -0
  42. data/test/cassettes/Datarobot_AiApi_AI/when_not_authorized/can_not_find_AIs.yml +43 -0
  43. data/test/cassettes/Datarobot_AiApi_AI/when_not_authorized/can_not_list_AIs.yml +45 -0
  44. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/_find/should_accept_a_block.yml +64 -0
  45. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/_next_page/can_go_to_the_next_page.yml +126 -0
  46. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/_next_page/returns_the_same_page_if_there_is_no_next_page.yml +113 -0
  47. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/_previous_page/can_go_to_the_previous_page.yml +250 -0
  48. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/_previous_page/returns_the_same_page_if_there_is_no_previous_page.yml +64 -0
  49. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/_refresh/can_refresh_to_a_new_object.yml +125 -0
  50. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/_refresh_/can_refresh_its_values.yml +125 -0
  51. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/can_delete_datasets.yml +58 -0
  52. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/can_find_datasets.yml +61 -0
  53. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/can_import_a_dataset_from_a_file.yml +1077 -0
  54. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/can_import_a_dataset_from_a_url.yml +55 -0
  55. data/test/cassettes/Datarobot_AiApi_Dataset/when_authorized/can_list_datasets.yml +113 -0
  56. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/_find/should_accept_a_block.yml +67 -0
  57. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/_next_page/can_go_to_the_next_page.yml +67 -0
  58. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/_next_page/returns_the_same_page_if_there_is_no_next_page.yml +100 -0
  59. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/_previous_page/can_go_to_the_previous_page.yml +67 -0
  60. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/_previous_page/returns_the_same_page_if_there_is_no_previous_page.yml +100 -0
  61. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/_refresh/can_refresh_to_a_new_object.yml +131 -0
  62. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/_refresh_/can_refresh_its_values.yml +130 -0
  63. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/can_create_learning_sessions.yml +2815 -0
  64. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/can_delete_learning_sessions.yml +58 -0
  65. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/can_find_learning_sessions.yml +63 -0
  66. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/can_get_learning_session_deployment_data.yml +123 -0
  67. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/can_get_learning_session_evaluation_data.yml +67 -0
  68. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/can_get_learning_session_features.yml +127 -0
  69. data/test/cassettes/Datarobot_AiApi_LearningSession/when_authorized/can_list_learning_sessions.yml +100 -0
  70. data/test/cassettes/Datarobot_AiApi_Output/when_authorized/can_create_outputs.yml +60 -0
  71. data/test/cassettes/Datarobot_AiApi_Output/when_authorized/can_find_named_outputs.yml +123 -0
  72. data/test/cassettes/Datarobot_AiApi_Output/when_authorized/can_get_features_of_an_output.yml +184 -0
  73. data/test/cassettes/Datarobot_AiApi_Output/when_authorized/can_get_the_evaluation_of_an_output.yml +131 -0
  74. data/test/cassettes/Datarobot_AiApi_Output/when_authorized/can_list_outputs.yml +124 -0
  75. data/test/cassettes/Datarobot_AiApi_Task/when_authorized/_find/should_accept_a_block.yml +63 -0
  76. data/test/cassettes/Datarobot_AiApi_Task/when_authorized/_refresh/can_refresh_to_a_new_object.yml +124 -0
  77. data/test/cassettes/Datarobot_AiApi_Task/when_authorized/_refresh_/can_refresh_its_values.yml +125 -0
  78. data/test/cassettes/Datarobot_AiApi_Task/when_authorized/can_stop_a_task.yml +58 -0
  79. data/test/cassettes/Datarobot_AiApi_Task/when_authorized/can_wait_until_completed.yml +1138 -0
  80. data/test/cassettes/Datarobot_AiApi_Task/when_authorized/check_the_status_of_a_task.yml +64 -0
  81. data/test/data/delete-me.csv +8037 -0
  82. data/test/data/test.csv +8037 -0
  83. data/test/datarobot/ai_api/test_ai.rb +133 -0
  84. data/test/datarobot/ai_api/test_dataset.rb +64 -0
  85. data/test/datarobot/ai_api/test_learning_session.rb +77 -0
  86. data/test/datarobot/ai_api/test_output.rb +54 -0
  87. data/test/datarobot/ai_api/test_page.rb +50 -0
  88. data/test/datarobot/ai_api/test_prediction.rb +0 -0
  89. data/test/datarobot/ai_api/test_refreshable.rb +39 -0
  90. data/test/datarobot/ai_api/test_task.rb +53 -0
  91. data/test/datarobot/test_ai_api.rb +52 -0
  92. data/test/test_helper.rb +40 -0
  93. metadata +217 -0
@@ -0,0 +1,133 @@
1
+ require 'test_helper'
2
+ require_relative "test_page.rb"
3
+ require_relative "test_refreshable.rb"
4
+
5
+ describe "Datarobot::AiApi::AI" do
6
+ before do
7
+ @key = "testingKey"
8
+ end
9
+
10
+ it "is sane" do
11
+ Datarobot::AiApi::AI.new
12
+ # if we make it to here, nothing has exploded
13
+ assert true
14
+ end
15
+
16
+ describe "when authorized" do
17
+ before do
18
+ Datarobot::AiApi.configure!(api_key: @key)
19
+ @klass = Datarobot::AiApi::AI
20
+ @id = '5d322e625c142b15dff826fc'
21
+ end
22
+
23
+ it_behaves_like "a paginated resource"
24
+ it_behaves_like "a refreshable resource"
25
+
26
+ it "can list AIs", vcr: true do
27
+ ais = Datarobot::AiApi::AI.all
28
+ assert ais.is_a? Datarobot::AiApi::Page
29
+ assert_equal ais.length, 15
30
+ assert_includes(ais.map(&:name), "Bird classifier")
31
+ end
32
+
33
+ it "can find AIs", vcr: true do
34
+ ai = Datarobot::AiApi::AI.find('5d322e625c142b15dff826fc')
35
+ assert ai.is_a? Datarobot::AiApi::AI
36
+ assert_equal ai.name, "Bird classifier"
37
+ end
38
+
39
+ it "handles when the AI ID is nil" do
40
+ assert_raises Datarobot::AiApi::NotFoundError do
41
+ ai = Datarobot::AiApi::AI.find(nil)
42
+ end
43
+ end
44
+
45
+ it "can create AIs", vcr: true do
46
+ ai = Datarobot::AiApi::AI.create(name: 'a testing AI')
47
+ assert ai.is_a? Datarobot::AiApi::AI
48
+ assert_equal ai.name, "a testing AI"
49
+ end
50
+
51
+ it "can delete AIs", vcr: true do
52
+ ai = Datarobot::AiApi::AI.delete('5d5c72af42eabf0c8b66f2eb')
53
+ assert_nil ai
54
+ end
55
+
56
+ it "can get AI outputs", vcr: true do
57
+ ai = Datarobot::AiApi::AI.find('5d322e625c142b15dff826fc')
58
+ outputs = ai.outputs
59
+ assert outputs.is_a? Datarobot::AiApi::Page
60
+ assert_includes outputs.map(&:name), "class"
61
+ end
62
+
63
+ it "can get AI datasets", vcr: true do
64
+ ai = Datarobot::AiApi::AI.find('5d322e625c142b15dff826fc')
65
+ datasets = ai.datasets
66
+ assert datasets.length == ai.dataset_count
67
+ assert datasets.is_a? Datarobot::AiApi::Page
68
+ assert_includes datasets.map(&:name), "image_birds_multiclass_6x100.csv"
69
+ end
70
+
71
+ it "can add datasets to AIs", vcr: true do
72
+ ai = Datarobot::AiApi::AI.find('5d322e625c142b15dff826fc')
73
+ was_added = ai.add_dataset('5d5d914e42eabf0f1166f29f')
74
+ assert was_added
75
+ end
76
+
77
+ it "can add learning sessions to AIs", vcr: true do
78
+ ai = Datarobot::AiApi::AI.find('5d322e625c142b15dff826fc')
79
+ was_added = ai.add_learning_session('5d41de29d8c81f0587732a4f')
80
+ assert was_added
81
+ end
82
+
83
+ it "404s if there is no matching output", vcr: true do
84
+ ai = Datarobot::AiApi::AI.find('5d4205d6d8c81f05fe732a42')
85
+ data = {'date': '2019-08-26', 'league_id': '1845', 'league': 'German Bundesliga', 'team1': 'Werder Bremen', 'team2': 'Hamburg SV', 'spi1': '64.54', 'spi2': '43.91'}
86
+
87
+ assert_raises Datarobot::AiApi::NotFoundError do
88
+ predictions = ai.predict('not_a_valid_target', data)
89
+ end
90
+ end
91
+
92
+ it "can predict things", vcr: true do
93
+ ai = Datarobot::AiApi::AI.find('5d4205d6d8c81f05fe732a42')
94
+ data = {'date': '2019-08-26', 'league_id': '1845', 'league': 'German Bundesliga', 'team1': 'Werder Bremen', 'team2': 'Hamburg SV', 'spi1': '64.54', 'spi2': '43.91'}
95
+ predictions = ai.predict('score1', data)
96
+ assert predictions.is_a? Datarobot::AiApi::Page
97
+
98
+ prediction = predictions.first
99
+
100
+ assert prediction.is_a? Datarobot::AiApi::Prediction
101
+ assert_equal prediction.prediction, 3.7707404629
102
+ end
103
+
104
+ it "can be trained", vcr: true do
105
+ ai = Datarobot::AiApi::AI.create(name: 'test AI')
106
+ ai.train('score1', './test/data/test.csv')
107
+ end
108
+ end
109
+
110
+ describe "when not authorized" do
111
+ before do
112
+ Datarobot::AiApi.configure!(api_key: '')
113
+ end
114
+
115
+ it "can not list AIs", vcr: true do
116
+ assert_raises Datarobot::AiApi::UnauthorizedError do
117
+ Datarobot::AiApi::AI.all
118
+ end
119
+ end
120
+
121
+ it "can not find AIs", vcr: true do
122
+ assert_raises Datarobot::AiApi::UnauthorizedError do
123
+ Datarobot::AiApi::AI.find('5d322e625c142b15dff826fc')
124
+ end
125
+ end
126
+
127
+ it "can not create AIs", vcr: true do
128
+ assert_raises Datarobot::AiApi::UnauthorizedError do
129
+ Datarobot::AiApi::AI.create(name: 'a testing AI')
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+ require_relative "test_page.rb"
3
+ require_relative "test_refreshable.rb"
4
+
5
+ describe "Datarobot::AiApi::Dataset" do
6
+ before do
7
+ @key = "testingKey"
8
+ end
9
+
10
+ it "is sane" do
11
+ Datarobot::AiApi::AI.new
12
+ # if we make it to here, nothing has exploded
13
+ assert true
14
+ end
15
+
16
+ describe "when authorized" do
17
+ before do
18
+ Datarobot::AiApi.configure!(api_key: @key)
19
+ @klass = Datarobot::AiApi::Dataset
20
+ @id = "5d4b20f37741a3052f171759"
21
+ end
22
+
23
+ it_behaves_like "a paginated resource"
24
+ it_behaves_like "a refreshable resource"
25
+
26
+ it "can list datasets", vcr: true do
27
+ datasets = Datarobot::AiApi::Dataset.all
28
+ assert datasets.is_a? Datarobot::AiApi::Page
29
+ assert_equal datasets.length, 38
30
+ assert_includes(datasets.map(&:name), "chords_part0000.csv")
31
+ end
32
+
33
+ it "can find datasets", vcr: true do
34
+ dataset = Datarobot::AiApi::Dataset.find('5d4b20f37741a3052f171759')
35
+ assert dataset.is_a? Datarobot::AiApi::Dataset
36
+ assert_equal dataset.name, "chords_part0000.csv"
37
+ end
38
+
39
+ it "handles when the dataset ID is nil" do
40
+ assert_raises Datarobot::AiApi::NotFoundError do
41
+ ai = Datarobot::AiApi::Dataset.find(nil)
42
+ end
43
+ end
44
+
45
+ it "can delete datasets", vcr: true do
46
+ dataset = Datarobot::AiApi::Dataset.delete('5d41f1bbd8c81f05c9732a25')
47
+ assert_nil dataset
48
+ end
49
+
50
+ it "can import a dataset from a file", vcr: true do
51
+ dataset = Datarobot::AiApi::Dataset.create_from_file('./test/data/delete-me.csv')
52
+ assert dataset.is_a? Datarobot::AiApi::Dataset
53
+ assert_equal dataset.name, "delete-me.csv"
54
+ assert dataset.id
55
+ end
56
+
57
+ it "can import a dataset from a url", vcr: true do
58
+ dataset = Datarobot::AiApi::Dataset.create_from_url('https://projects.fivethirtyeight.com/congress-model-2018/house_national_forecast.csv')
59
+ assert dataset.is_a? Datarobot::AiApi::Dataset
60
+ assert_equal dataset.name, "house_national_forecast.csv"
61
+ assert dataset.id
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,77 @@
1
+ require 'test_helper'
2
+ require_relative 'test_page.rb'
3
+ require_relative "test_refreshable.rb"
4
+
5
+ describe "Datarobot::AiApi::LearningSession" do
6
+ before do
7
+ @key = "testingKey"
8
+ end
9
+
10
+ it "is sane" do
11
+ Datarobot::AiApi::LearningSession.new
12
+ # if we make it to here, nothing has exploded
13
+ assert true
14
+ end
15
+
16
+ describe "when authorized" do
17
+ before do
18
+ Datarobot::AiApi.configure!(api_key: @key)
19
+ @klass = Datarobot::AiApi::LearningSession
20
+ @id = '5d41e055d8c81f0587732a93'
21
+ end
22
+
23
+ it_behaves_like "a paginated resource"
24
+ it_behaves_like "a refreshable resource"
25
+
26
+ it "can list learning sessions", vcr: true do
27
+ sessions = Datarobot::AiApi::LearningSession.all
28
+ assert sessions.is_a? Datarobot::AiApi::Page
29
+ assert_equal sessions.length, 19
30
+ end
31
+
32
+ it "can find learning sessions", vcr: true do
33
+ session = Datarobot::AiApi::LearningSession.find('5d322f2c5c142b15d2f826e7')
34
+ assert session.is_a? Datarobot::AiApi::LearningSession
35
+ assert_equal session.name, "Learning class"
36
+ end
37
+
38
+ it "handles when the learning session ID is nil" do
39
+ assert_raises Datarobot::AiApi::NotFoundError do
40
+ ai = Datarobot::AiApi::LearningSession.find(nil)
41
+ end
42
+ end
43
+
44
+ it "can create learning sessions", vcr: true do
45
+ session = Datarobot::AiApi::LearningSession.create(dataset_id: '5d656bb042eabf201366f2d7', target: 'score1')
46
+ assert session.is_a? Datarobot::AiApi::LearningSession
47
+ end
48
+
49
+ it "can delete learning sessions", vcr: true do
50
+ session = Datarobot::AiApi::LearningSession.delete('5d322f2c5c142b15d2f826e7')
51
+ assert_nil session
52
+ end
53
+
54
+ it "can get learning session deployment data", vcr: true do
55
+ session = Datarobot::AiApi::LearningSession.find('5d41e055d8c81f0587732a93')
56
+ deployment = session.deployment
57
+ assert deployment
58
+ assert deployment.is_a? Datarobot::AiApi::Deployment
59
+ assert_equal deployment.target, 'score1'
60
+ end
61
+
62
+ it "can get learning session features", vcr: true do
63
+ session = Datarobot::AiApi::LearningSession.find('5d41e055d8c81f0587732a93')
64
+ features = session.features
65
+ assert features
66
+ assert features.is_a? Array
67
+ assert_equal features.length, 12
68
+ end
69
+
70
+ it "can get learning session evaluation data", vcr: true do
71
+ session = Datarobot::AiApi::LearningSession.find('5d76980cf2ff5200587ce3da')
72
+ evaluation = session.evaluation
73
+ assert evaluation
74
+ assert_equal evaluation.summary, "Because 6.6% of the variability in the values of score1 are explained, fit accuracy for the current top performing model is ranked as weak."
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ describe "Datarobot::AiApi::Output" do
4
+ before do
5
+ @key = "testingKey"
6
+ end
7
+
8
+ it "is sane" do
9
+ Datarobot::AiApi::Output.new
10
+ # if we make it to here, nothing has exploded
11
+ assert true
12
+ end
13
+
14
+ describe "when authorized" do
15
+ before do
16
+ Datarobot::AiApi.configure!(api_key: @key)
17
+ end
18
+
19
+ it "can list outputs", vcr: true do
20
+ ai = Datarobot::AiApi::AI.find('5d5c6f7c42eabf0cb166f2c6')
21
+ outputs = ai.outputs
22
+ assert outputs.is_a? Datarobot::AiApi::Page
23
+ assert_equal outputs.length, 1
24
+ assert_includes(outputs.map(&:name), "test")
25
+ end
26
+
27
+ it "can create outputs", vcr: true do
28
+ output = Datarobot::AiApi::Output.create(ai_id: '5d5c6f7c42eabf0cb166f2c6', output_name: 'test', learning_session_id: '5d420b75d8c81f05e0732a3d')
29
+ assert output.is_a? Datarobot::AiApi::Output
30
+ assert_equal output.name, "test"
31
+ end
32
+
33
+ it "can find named outputs", vcr: true do
34
+ ai = Datarobot::AiApi::AI.find('5d5c6f7c42eabf0cb166f2c6')
35
+ output = ai.find_output('test')
36
+ assert output.is_a? Datarobot::AiApi::Output
37
+ assert_equal output.name, "test"
38
+ end
39
+
40
+ it "can get features of an output", vcr: true do
41
+ ai = Datarobot::AiApi::AI.find('5d5c6f7c42eabf0cb166f2c6')
42
+ output = ai.find_output('test')
43
+ features = output.features
44
+ assert_includes features, {"type"=>"Categorical", "name"=>"league"}
45
+ end
46
+
47
+ it "can get the evaluation of an output", vcr: true do
48
+ ai = Datarobot::AiApi::AI.find('5d76962ab153720056bb5783')
49
+ output = ai.find_output('score1 output')
50
+ evaluation = output.evaluation
51
+ assert_equal evaluation.summary, "Because 6.6% of the variability in the values of score1 are explained, fit accuracy for the current top performing model is ranked as weak."
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ shared_examples_for 'a paginated resource' do
4
+ describe "#next_page" do
5
+ it "can go to the next page", vcr: true do
6
+ raise "Set @klass in a before block to use pagination tests" unless @klass
7
+ page = @klass.all(limit: 1, offset: 0)
8
+ next_page = page.next_page
9
+ assert next_page.is_a? Datarobot::AiApi::Page
10
+ assert_equal next_page.items.length, 1
11
+ assert_equal next_page.size, 1
12
+ end
13
+ it "returns the same page if there is no next page", vcr: true do
14
+ # puts self.inspect
15
+ raise "Set @klass in a before block to use pagination tests" unless @klass
16
+ page = @klass.all(limit: 100, offset: 0)
17
+ assert_nil page.links["next"]
18
+
19
+ next_page = page.next_page
20
+ assert_equal page, next_page
21
+ end
22
+ end
23
+ describe "#previous_page" do
24
+ it "can go to the previous page", vcr: true do
25
+ raise "Set @klass in a before block to use pagination tests" unless @klass
26
+ page_0 = @klass.all(limit: 1, offset: 0)
27
+ assert_equal page_0.items.length, 1
28
+ assert_equal page_0.size, 1
29
+
30
+ page_1 = page_0.next_page
31
+ page_2 = page_1.next_page
32
+
33
+ assert page_0.is_a? Datarobot::AiApi::Page
34
+ assert page_1.is_a? Datarobot::AiApi::Page
35
+ assert page_2.is_a? Datarobot::AiApi::Page
36
+
37
+ assert_equal page_1.map(&:id), page_2.previous_page.map(&:id)
38
+ end
39
+
40
+ it "returns the same page if there is no previous page", vcr: true do
41
+ raise "Set @klass in a before block to use pagination tests" unless @klass
42
+ page = @klass.all(limit: 1, offset: 0)
43
+
44
+ assert_nil page.links['previous']
45
+
46
+ prev_page = page.previous_page
47
+ assert_equal page.map(&:id), prev_page.map(&:id)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ shared_examples_for 'a refreshable resource' do
4
+ describe "#refresh" do
5
+ it "can refresh to a new object", vcr: true do
6
+ raise "Set @klass in a before block to use refreshing tests" unless @klass
7
+ raise "Set @id in a before block to use refreshing tests" unless @id
8
+ object = @klass.find(@id)
9
+ assert object
10
+ new_object = object.refresh
11
+ assert_equal object.id, new_object.id
12
+ assert object.inspect != new_object.inspect
13
+ end
14
+ end
15
+ describe "#refresh!" do
16
+ it "can refresh its values", vcr: true do
17
+ raise "Set @klass in a before block to use refreshing tests" unless @klass
18
+ raise "Set @id in a before block to use refreshing tests" unless @id
19
+ object = @klass.find(@id)
20
+ assert object
21
+ object_dump = object.inspect
22
+ object.refresh!
23
+ assert object_dump != object.inspect
24
+ end
25
+ end
26
+ describe "#find" do
27
+ it "should accept a block", vcr: true do
28
+ raise "Set @klass in a before block to use refreshing tests" unless @klass
29
+ raise "Set @id in a before block to use refreshing tests" unless @id
30
+
31
+ class SpecialSpecificTestError < StandardError; end
32
+ assert_raises(SpecialSpecificTestError) do
33
+ @klass.find(@id) do
34
+ raise SpecialSpecificTestError
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+ require_relative "test_refreshable.rb"
3
+
4
+ describe "Datarobot::AiApi::Task" do
5
+ before do
6
+ @key = "testingKey"
7
+ end
8
+
9
+ it "is sane" do
10
+ Datarobot::AiApi::Task.new
11
+ # if we make it to here, nothing has exploded
12
+ assert true
13
+ end
14
+
15
+ describe "when authorized" do
16
+ before do
17
+ Datarobot::AiApi.configure!(api_key: @key)
18
+ @klass = Datarobot::AiApi::Task
19
+ @id = '5d0efc9e-b77e-40e4-bd7e-1d162b53155c'
20
+ end
21
+
22
+ it_behaves_like "a refreshable resource"
23
+
24
+ it "check the status of a task", vcr: true do
25
+ task = Datarobot::AiApi::Task.find('5d0efc9e-b77e-40e4-bd7e-1d162b53155c')
26
+ assert task.is_a? Datarobot::AiApi::Task
27
+ assert_equal task.status, "COMPLETED"
28
+ end
29
+
30
+ it "can stop a task", vcr: true do
31
+ task = Datarobot::AiApi::Task.stop('5d0efc9e-b77e-40e4-bd7e-1d162b53155c')
32
+ assert_nil task
33
+ end
34
+
35
+ it "handles when Task ID is nil" do
36
+ assert_raises Datarobot::AiApi::NotFoundError do
37
+ task = Datarobot::AiApi::Task.find(nil)
38
+ end
39
+ end
40
+
41
+ it "can wait until completed", vcr: true do
42
+ resp_data = Datarobot::AiApi.upload_to_endpoint('/aiapi/datasets/fileImports', './test/data/test.csv')
43
+ task = Datarobot::AiApi::Task.new(resp_data)
44
+
45
+ dataset = task.wait_until_complete
46
+
47
+ task = Datarobot::AiApi::Task.find(task.id)
48
+ assert task.status == "COMPLETED"
49
+ assert dataset.is_a? Datarobot::AiApi::Dataset
50
+ end
51
+ end
52
+ end
53
+