kgrift 1.3.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/KGrift/Gemfile +22 -0
- data/KGrift/README.md +66 -0
- data/KGrift/bin/kgrift +11 -0
- data/KGrift/grifter.yml +224 -0
- data/KGrift/internal_test_graphs/basic_test_graph_definition.yml +2915 -0
- data/KGrift/internal_test_graphs/unicode_test_graph_definition.yml +3070 -0
- data/KGrift/knewton_grifts/analytics_grifts.rb +103 -0
- data/KGrift/knewton_grifts/async_helper_grifts.rb +63 -0
- data/KGrift/knewton_grifts/authenticator_grifts.rb +46 -0
- data/KGrift/knewton_grifts/basic_grifts.rb +29 -0
- data/KGrift/knewton_grifts/batch_grifts.rb +14 -0
- data/KGrift/knewton_grifts/content_collection_grifts.rb +204 -0
- data/KGrift/knewton_grifts/content_collection_v1_grifts.rb +521 -0
- data/KGrift/knewton_grifts/content_eid_grifts.rb +41 -0
- data/KGrift/knewton_grifts/copy_grifts.rb +151 -0
- data/KGrift/knewton_grifts/deprecated_graph_and_taxonomy_grifts.rb +353 -0
- data/KGrift/knewton_grifts/goal_grifts.rb +203 -0
- data/KGrift/knewton_grifts/graph_and_taxonomy_grifts.rb +136 -0
- data/KGrift/knewton_grifts/graph_create_grifts.rb +34 -0
- data/KGrift/knewton_grifts/graph_query_grifts.rb +448 -0
- data/KGrift/knewton_grifts/graph_tools_grifts.rb +151 -0
- data/KGrift/knewton_grifts/graph_validation_grifts.rb +447 -0
- data/KGrift/knewton_grifts/helper_grifts.rb +92 -0
- data/KGrift/knewton_grifts/jmeter_data_grifts.rb +56 -0
- data/KGrift/knewton_grifts/learning_instance_grifts.rb +46 -0
- data/KGrift/knewton_grifts/looper_grifts.rb +34 -0
- data/KGrift/knewton_grifts/moxy_grifts.rb +64 -0
- data/KGrift/knewton_grifts/oauth_grifts.rb +182 -0
- data/KGrift/knewton_grifts/partner_grifts.rb +70 -0
- data/KGrift/knewton_grifts/partner_support_grifts.rb +85 -0
- data/KGrift/knewton_grifts/recommendation_setup_grifts.rb +215 -0
- data/KGrift/knewton_grifts/registration_grifts.rb +159 -0
- data/KGrift/knewton_grifts/registration_info_grifts.rb +23 -0
- data/KGrift/knewton_grifts/report_grifts.rb +122 -0
- data/KGrift/knewton_grifts/shell_command_grifts.rb +21 -0
- data/KGrift/knewton_grifts/student_flow_grifts.rb +560 -0
- data/KGrift/knewton_grifts/tag_grifts.rb +41 -0
- data/KGrift/knewton_grifts/test_data_grifts.rb +328 -0
- data/KGrift/knewton_grifts/test_user_grifts.rb +264 -0
- data/KGrift/lib/dtrace.rb +20 -0
- data/KGrift/lib/kgrift.rb +7 -0
- data/KGrift/test_data_generators/basic_book_and_taxonomies.rb +35 -0
- data/KGrift/test_data_generators/lo_test_graph.rb +34 -0
- data/KGrift/test_data_generators/partner_owned_book_and_taxonomies.rb +28 -0
- data/KGrift/test_data_generators/partner_owned_book_and_taxonomies_unicode.rb +28 -0
- data/KGrift/test_data_generators/sandcastle_book_and_taxonomies.rb +13 -0
- data/KGrift/test_data_generators/sandcastle_book_and_taxonomies.yml +3709 -0
- data/KGrift/test_data_generators/sandcastle_graph.rb +8 -0
- data/KGrift/test_data_generators/sandcastle_graph_definition.json +4483 -0
- data/KGrift/test_data_generators/sandcastle_graph_full.rb +7 -0
- data/KGrift/test_data_generators/sandcastle_taxonomies.yml +378 -0
- data/KGrift/test_data_generators/sandcastle_with_taxons.rb +56 -0
- data/KGrift/test_data_generators/sandcastle_with_taxons.yml +3994 -0
- data/KGrift/test_data_generators/test_users_and_partners.rb +76 -0
- data/kgrift.gemspec +43 -0
- metadata +144 -0
@@ -0,0 +1,521 @@
|
|
1
|
+
|
2
|
+
# return a list of all inventories
|
3
|
+
def get_inventories_v1
|
4
|
+
Log.info "getting all inventories"
|
5
|
+
coco.get "/v1/cc/admin/inventories"
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_inventory_admin_v1 partner_id, new_inventory_id=nil
|
9
|
+
new_inventory_id = "V1_KGriftTestInventory_#{random_string(16)}" if new_inventory_id.nil?
|
10
|
+
Log.info "Admin creating an inventory - partner_id: #{partner_id} - inventory_id: #{new_inventory_id}"
|
11
|
+
# response = create_modules_admin partner_id, new_inventory_id
|
12
|
+
response = coco.post "/v1/cc/admin/#{partner_id}/#{URI.encode new_inventory_id}/inventory", ''
|
13
|
+
|
14
|
+
{
|
15
|
+
'id' => new_inventory_id,
|
16
|
+
'inventory_id' => new_inventory_id,
|
17
|
+
'partner_id' => partner_id,
|
18
|
+
'inventory' => response,
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
# this is used to make production inventories for real partners
|
23
|
+
def create_prod_inventory_admin_v1 partner_id, new_inventory_id
|
24
|
+
set_prod_mode
|
25
|
+
set_account :prod_knerd
|
26
|
+
create_inventory_admin_v1 partner_id, new_inventory_id
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_inventory_admin_v1 partner_id, inventory_id
|
30
|
+
Log.info "Admin deleting an inventory - partner_id: #{partner_id}"
|
31
|
+
coco.delete "/v1/cc/admin/#{partner_id}/#{inventory_id}/inventory"
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_all_v1_inventories_for_partner partner_id
|
35
|
+
invs = get_inventories_v1['partner_inventories']
|
36
|
+
invs.select!{|i| i['partner_id'] == partner_id}
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete_all_v1_inventories_for_partner partner_id
|
40
|
+
invs = get_inventories_v1['partner_inventories']
|
41
|
+
invs.select!{|i| i['partner_id'] == partner_id}
|
42
|
+
inv_ids = invs.map{|i| i['inventory_id']}
|
43
|
+
inv_ids.each do |inv_id|
|
44
|
+
delete_inventory_admin_v1 partner_id, inv_id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_inventory_admin_v1 partner_id, inventory_id, query_params={}
|
49
|
+
Log.info "Admin getting inventory - partner_id: #{partner_id} - inventory_id: #{inventory_id}"
|
50
|
+
coco.get "/v1/cc/admin/#{partner_id}/#{inventory_id}?#{URI.encode_www_form query_params}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_inventory_v1 inventory_id, query_params={}
|
54
|
+
Log.info "getting inventory - inventory_id: #{inventory_id}"
|
55
|
+
coco.get "/v1/cc/inventory/#{inventory_id}?#{URI.encode_www_form query_params}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_inventory_existence_v1 partner_id, inventory_id
|
59
|
+
Log.info "Admin checking inventory existence - partner_id: #{partner_id} - inventory_id: #{inventory_id}"
|
60
|
+
coco.head "/v1/cc/admin/#{partner_id}/#{inventory_id}/inventory"
|
61
|
+
end
|
62
|
+
|
63
|
+
# build out a basic module object, ready to be created directly
|
64
|
+
# or you can merge in customizations
|
65
|
+
def test_module_object_v1 params={}
|
66
|
+
params = {
|
67
|
+
"module_id" => 'KGrift V1 test module ' + random_uuid,
|
68
|
+
"module_name" => random_string,
|
69
|
+
"module_version" => random_string,
|
70
|
+
"module_type" => ['instruction', 'assessment', 'both'].sample,
|
71
|
+
"module_url" => "http://kgriftlms.com/#{random_string}",
|
72
|
+
'module_metadata' => ["some-test-metadata",random_string],
|
73
|
+
}.merge(params)
|
74
|
+
end
|
75
|
+
|
76
|
+
# create a batch of modules against some inventory
|
77
|
+
def create_modules_v1 inventory_id, modules=[]
|
78
|
+
modules << test_module_object_v1 if modules.empty?
|
79
|
+
Log.info "Creating '#{modules.length}' modules for inventory_id: #{inventory_id}"
|
80
|
+
coco.post "/v1/cc/inventory/#{inventory_id}/modules", modules
|
81
|
+
end
|
82
|
+
alias :update_modules_v1 :create_modules_v1
|
83
|
+
|
84
|
+
# create a batch of modules against some inventory
|
85
|
+
def create_modules_admin_v1 partner_id, inventory_id, modules=[]
|
86
|
+
modules << test_module_object_v1 if modules.empty?
|
87
|
+
Log.info "Admin creating '#{modules.length}' modules for inventory - partner_id: #{partner_id} - inventory_id: #{inventory_id}"
|
88
|
+
coco.post "/v1/cc/admin/#{partner_id}/#{inventory_id}/modules", modules
|
89
|
+
end
|
90
|
+
alias :update_modules_admin_v1 :create_modules_admin_v1
|
91
|
+
|
92
|
+
# get a inventory module
|
93
|
+
def get_inventory_module_v1 inventory_id, module_id
|
94
|
+
Log.info "Getting module - inventory_id: #{inventory_id} - module_id: #{module_id}"
|
95
|
+
coco.get "/v1/cc/inventory/#{URI.encode inventory_id}/module/#{URI.encode module_id}"
|
96
|
+
end
|
97
|
+
|
98
|
+
# get a single inventory module
|
99
|
+
def get_inventory_module_admin_v1 partner_id, inventory_id, module_id
|
100
|
+
Log.info "Admin getting module - partner_id: #{partner_id} - inventory_id: #{inventory_id} - module_id: #{module_id}"
|
101
|
+
coco.get "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/module/#{URI.encode module_id}"
|
102
|
+
end
|
103
|
+
|
104
|
+
# delete a module
|
105
|
+
def delete_module_v1 inventory_id, module_id
|
106
|
+
Log.info "Deleting inventory module - inventory_id: #{inventory_id} - module_id: #{module_id}"
|
107
|
+
coco.delete "/v1/cc/inventory/#{inventory_id}/module/#{URI.encode module_id}"
|
108
|
+
end
|
109
|
+
|
110
|
+
# delete a module as a knerd
|
111
|
+
def delete_module_admin_v1 partner_id, inventory_id, module_id
|
112
|
+
Log.info "Admin deleting inventory module - partner_id: #{partner_id} - inventory_id: #{inventory_id} - module_id: #{module_id}"
|
113
|
+
coco.do_request :delete, "/v1/cc/admin/#{partner_id}/#{inventory_id}/module/#{URI.encode module_id}", {}
|
114
|
+
end
|
115
|
+
|
116
|
+
# mark a module mapped
|
117
|
+
def mark_module_mapped_v1 partner_id, inventory_id, module_id, module_version
|
118
|
+
Log.info "Marking module mapped for inventory - partner_id: #{partner_id} - inventory_id: #{inventory_id} - module_id: #{module_id} - module_version: #{module_version}"
|
119
|
+
coco.put "/v1/cc/admin/#{partner_id}/#{inventory_id}/map", {
|
120
|
+
'module_id' => module_id,
|
121
|
+
'module_version' => module_version,
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
125
|
+
# this is a useful grift for testing purposes
|
126
|
+
# it will ensure an inventory has b/t 200 and 400 modules
|
127
|
+
# This is a good way to ensure that tests dont keep creating
|
128
|
+
# modules and never delete them
|
129
|
+
def attempt_to_set_number_of_test_modules partner_id, inventory_id, opts={}
|
130
|
+
opts = {
|
131
|
+
min: 150,
|
132
|
+
max: 300,
|
133
|
+
}.merge(opts)
|
134
|
+
|
135
|
+
as_account :knerd do
|
136
|
+
inv = get_inventory_admin_v1 partner_id, inventory_id
|
137
|
+
num_mods = inv['modules'].length
|
138
|
+
num_needed = opts[:min] - num_mods
|
139
|
+
num_to_delete = num_mods - opts[:max]
|
140
|
+
if num_needed > 0
|
141
|
+
mods = num_needed.times.map{ test_module_object_v1}
|
142
|
+
Log.info "Adding #{num_needed} modules to bring inventory to #{opts[:min]} modules"
|
143
|
+
mods.each_slice(50) do |slice|
|
144
|
+
create_modules_admin_v1 partner_id, inventory_id, slice
|
145
|
+
end
|
146
|
+
end
|
147
|
+
if num_to_delete > 0
|
148
|
+
Log.info "Deleting #{num_to_delete} modules to bring inventory to #{opts[:max]} modules"
|
149
|
+
mod_ids = inv['modules'].map{|m| m['module_id']}.shuffle
|
150
|
+
# lets be fast aboout it though and use concurrent requests...
|
151
|
+
connection_pool = Typhoeus::Hydra.new(:max_concurrency => 8)
|
152
|
+
responses = []
|
153
|
+
coco.conn.in_parallel(connection_pool) do
|
154
|
+
num_to_delete.times do |i|
|
155
|
+
responses << kapi.conn.send(:delete) do |request|
|
156
|
+
request.headers['Content-Type'] = 'application/json'
|
157
|
+
request.headers['Authorization'] = kapi.headers['Authorization']
|
158
|
+
request.url "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/module/#{URI.encode mod_ids[i]}"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
response_codes = responses.map{|r| r.status }
|
163
|
+
Log.debug "Responses:\n#{response_codes.join(', ')}"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
nil
|
167
|
+
end
|
168
|
+
|
169
|
+
def attempt_to_set_number_of_test_taxons partner_id, inventory_id, opts={}
|
170
|
+
opts = {
|
171
|
+
min: 150,
|
172
|
+
max: 300,
|
173
|
+
}.merge(opts)
|
174
|
+
|
175
|
+
as_account :knerd do
|
176
|
+
inv = get_inventory_taxons_admin_v1 partner_id, inventory_id
|
177
|
+
num_taxons = inv['taxons'].length
|
178
|
+
num_needed = opts[:min] - num_taxons
|
179
|
+
num_to_delete = num_taxons - opts[:max]
|
180
|
+
if num_needed > 0
|
181
|
+
taxons = num_needed.times.map{ test_taxon_object_v1 }
|
182
|
+
Log.info "Adding #{num_needed} taxons to bring inventory to #{opts[:min]} taxons"
|
183
|
+
taxons.each_slice(50) do |slice|
|
184
|
+
create_taxons_admin_v1 partner_id, inventory_id, slice
|
185
|
+
end
|
186
|
+
end
|
187
|
+
if num_to_delete > 0
|
188
|
+
Log.info "Deleting #{num_to_delete} taxons to bring inventory to #{opts[:max]} taxons"
|
189
|
+
taxon_ids = inv['taxons'].map{|m| m['taxon_id']}.shuffle
|
190
|
+
# lets be fast aboout it though and use concurrent requests...
|
191
|
+
connection_pool = Typhoeus::Hydra.new(:max_concurrency => 8)
|
192
|
+
responses = []
|
193
|
+
coco.conn.in_parallel(connection_pool) do
|
194
|
+
num_to_delete.times do |i|
|
195
|
+
responses << kapi.conn.send(:delete) do |request|
|
196
|
+
request.headers['Content-Type'] = 'application/json'
|
197
|
+
request.headers['Authorization'] = kapi.headers['Authorization']
|
198
|
+
request.url "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/taxon/#{URI.encode taxon_ids[i]}"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
response_codes = responses.map{|r| r.status }
|
203
|
+
Log.debug "Responses:\n#{response_codes.join(', ')}"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
nil
|
207
|
+
end
|
208
|
+
|
209
|
+
def attempt_to_set_number_of_test_containers partner_id, inventory_id, opts={}
|
210
|
+
opts = {
|
211
|
+
min: 150,
|
212
|
+
max: 300,
|
213
|
+
}.merge(opts)
|
214
|
+
|
215
|
+
as_account :knerd do
|
216
|
+
inv = get_inventory_containers_admin_v1 partner_id, inventory_id
|
217
|
+
num_containers = inv['containers'].length
|
218
|
+
num_needed = opts[:min] - num_containers
|
219
|
+
num_to_delete = num_containers - opts[:max]
|
220
|
+
if num_needed > 0
|
221
|
+
containers = num_needed.times.map{ test_container_object_v1 }
|
222
|
+
Log.info "Adding #{num_needed} containers to bring inventory to #{opts[:min]} containers"
|
223
|
+
containers.each_slice(50) do |slice|
|
224
|
+
create_containers_admin_v1 partner_id, inventory_id, slice
|
225
|
+
end
|
226
|
+
end
|
227
|
+
if num_to_delete > 0
|
228
|
+
Log.info "Deleting #{num_to_delete} containers to bring inventory to #{opts[:max]} containers"
|
229
|
+
container_ids = inv['containers'].map{|m| m['container_id']}.shuffle
|
230
|
+
# lets be fast aboout it though and use concurrent requests...
|
231
|
+
connection_pool = Typhoeus::Hydra.new(:max_concurrency => 8)
|
232
|
+
responses = []
|
233
|
+
coco.conn.in_parallel(connection_pool) do
|
234
|
+
num_to_delete.times do |i|
|
235
|
+
responses << kapi.conn.send(:delete) do |request|
|
236
|
+
request.headers['Content-Type'] = 'application/json'
|
237
|
+
request.headers['Authorization'] = kapi.headers['Authorization']
|
238
|
+
request.url "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/container/#{URI.encode container_ids[i]}"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
response_codes = responses.map{|r| r.status }
|
243
|
+
Log.debug "Responses:\n#{response_codes.join(', ')}"
|
244
|
+
end
|
245
|
+
end
|
246
|
+
nil
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
def test_taxon_object_v1 params={}
|
251
|
+
params = {
|
252
|
+
"taxon_id" => 'TEST_TAXON:Foo|' + random_uuid,
|
253
|
+
"taxon_name" => "TEST_TAXON_#{random_string}",
|
254
|
+
"modules" => [],
|
255
|
+
"containers" => []
|
256
|
+
}.merge(params)
|
257
|
+
end
|
258
|
+
|
259
|
+
def create_taxons_admin_v1 partner_id, inventory_id, taxons=[]
|
260
|
+
taxons << test_taxon_object_v1 if taxons.empty?
|
261
|
+
Log.info "Admin creating taxons - partner_id: #{partner_id} - inventory_id: #{inventory_id} - taxons: #{taxons}"
|
262
|
+
coco.post "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/taxons", taxons
|
263
|
+
end
|
264
|
+
alias :update_taxons_admin_v1 :create_taxons_admin_v1
|
265
|
+
|
266
|
+
def get_inventory_taxons_admin_v1 partner_id, inventory_id, query_params={}
|
267
|
+
Log.info "Admin getting taxons - partner_id: #{partner_id} - inventory_id: #{inventory_id}"
|
268
|
+
coco.get "/v1/cc/admin/#{partner_id}/#{inventory_id}/taxons?#{URI.encode_www_form query_params}"
|
269
|
+
end
|
270
|
+
|
271
|
+
def get_module_taxons_admin_v1 partner_id, inventory_id, module_id
|
272
|
+
Log.info "Admin getting taxons - partner_id: #{partner_id} - inventory_id: #{inventory_id} - module_id: #{module_id}"
|
273
|
+
coco.get "/v1/cc/admin/#{partner_id}/#{inventory_id}/taxons/#{URI.encode module_id}"
|
274
|
+
end
|
275
|
+
|
276
|
+
def delete_taxons_admin_v1 partner_id, inventory_id, taxon_id
|
277
|
+
Log.info "Admin deleting taxons - partner_id: #{partner_id} - inventory_id: #{inventory_id} - taxon_id: #{taxon_id}"
|
278
|
+
coco.delete "/v1/cc/admin/#{partner_id}/#{inventory_id}/taxon/#{URI.encode taxon_id}"
|
279
|
+
end
|
280
|
+
|
281
|
+
def create_taxons_v1 inventory_id, taxons=[]
|
282
|
+
taxons << test_taxon_object_v1 if taxons.empty?
|
283
|
+
Log.info "Partner creating taxons - inventory_id: #{inventory_id} - taxons: #{taxons}"
|
284
|
+
coco.post "/v1/cc/inventory/#{URI.encode inventory_id}/taxons", taxons
|
285
|
+
end
|
286
|
+
|
287
|
+
def delete_taxons_v1 inventory_id, taxon_id
|
288
|
+
Log.info "Partner deleting taxons - inventory_id: #{inventory_id} - taxon_id: #{taxon_id}"
|
289
|
+
coco.delete "/v1/cc/inventory/#{inventory_id}/taxon/#{URI.encode taxon_id}"
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_container_object_v1 params={}
|
293
|
+
params = {
|
294
|
+
"container_id" => 'TEST_CONTAINER_' + random_uuid,
|
295
|
+
"modules" => [],
|
296
|
+
"container_name" => nil,
|
297
|
+
"container_url" => "http://kgriftlms.com/#{random_string(rand(10))}",
|
298
|
+
"container_type" => ['presentation', 'target', 'both'].sample(),
|
299
|
+
"container_metadata" => []
|
300
|
+
}.merge(params)
|
301
|
+
end
|
302
|
+
|
303
|
+
def create_containers_admin_v1 partner_id, inventory_id, containers=[]
|
304
|
+
containers << test_container_object_v1 if containers.empty?
|
305
|
+
Log.info "Admin creating #{containers.length} containers - partner_id: #{partner_id} - inventory_id: #{inventory_id}"
|
306
|
+
coco.post "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/containers", containers
|
307
|
+
end
|
308
|
+
alias :update_containers_admin_v1 :create_containers_admin_v1
|
309
|
+
|
310
|
+
def delete_containers_admin_v1 partner_id, inventory_id, container_id
|
311
|
+
Log.info "Admin deleting containers - partner_id: #{partner_id} - inventory_id: #{inventory_id} - container_id: #{container_id}"
|
312
|
+
coco.delete "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/container/#{URI.encode container_id}"
|
313
|
+
end
|
314
|
+
|
315
|
+
def get_containers_admin_v1 partner_id, inventory_id, module_id
|
316
|
+
Log.info "Admin getting containers - partner_id: #{partner_id} - inventory_id: #{inventory_id} - module_id: #{module_id}"
|
317
|
+
coco.get "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/containers/#{URI.encode module_id}"
|
318
|
+
end
|
319
|
+
|
320
|
+
def create_containers_v1 inventory_id, containers=[]
|
321
|
+
containers << test_container_object_v1 if containers.empty?
|
322
|
+
Log.info "Partner creating #{containers.length} containers - inventory_id: #{inventory_id}"
|
323
|
+
coco.post "/v1/cc/inventory/#{URI.encode inventory_id}/containers", containers
|
324
|
+
end
|
325
|
+
|
326
|
+
def delete_containers_v1 inventory_id, container_id
|
327
|
+
Log.info "Partner deleting containers - inventory_id: #{inventory_id} - container_id: #{container_id}"
|
328
|
+
coco.delete "/v1/cc/inventory/#{URI.encode inventory_id}/container/#{URI.encode container_id}"
|
329
|
+
end
|
330
|
+
|
331
|
+
def get_inventory_containers_admin_v1 partner_id, inventory_id, query_params={}
|
332
|
+
Log.info "Admin getting containers - partner_id: #{partner_id} - inventory_id: #{inventory_id}"
|
333
|
+
coco.get "/v1/cc/admin/#{partner_id}/#{inventory_id}/containers?#{URI.encode_www_form query_params}"
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_learning_objective_object_v1 params={}
|
337
|
+
params = {
|
338
|
+
'learning_objective_id' => "TEST_OBJECTIVE_#{random_uuid}",
|
339
|
+
'learning_objective_name' => 'Test Learning Objective',
|
340
|
+
'learning_objective_description' => "Able to test learning objectives on Knewton Platform",
|
341
|
+
'modules' => [],
|
342
|
+
'reference_modules' => [],
|
343
|
+
}.merge(params)
|
344
|
+
end
|
345
|
+
|
346
|
+
def create_objectives_v1 inventory_id, objectives=[]
|
347
|
+
objectives << test_learning_objective_object_v1 if objectives.empty?
|
348
|
+
Log.info "Partner creating #{objectives.length} objectives - inventory_id: #{inventory_id}"
|
349
|
+
coco.post "/v1/cc/inventory/#{URI.encode inventory_id}/objectives", objectives
|
350
|
+
end
|
351
|
+
|
352
|
+
alias :update_objectives_v1 :create_objectives_v1
|
353
|
+
|
354
|
+
def create_objectives_admin_v1 partner_id, inventory_id, objectives=[]
|
355
|
+
objectives << test_learning_objective_object_v1 if objectives.empty?
|
356
|
+
Log.info "Partner creating #{objectives.length} objectives - inventory_id: #{inventory_id}"
|
357
|
+
coco.post "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/objectives", objectives
|
358
|
+
end
|
359
|
+
|
360
|
+
alias :update_objectives_admin_v1 :create_objectives_admin_v1
|
361
|
+
|
362
|
+
def get_objective_admin_v1 partner_id, inventory_id, objective_id
|
363
|
+
Log.info "Admin getting objective - inventory_id: #{inventory_id} - partner_id: #{partner_id} - objective_id: #{objective_id}"
|
364
|
+
coco.get "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/objective/#{objective_id}"
|
365
|
+
end
|
366
|
+
|
367
|
+
def get_objectives_admin_v1 partner_id, inventory_id
|
368
|
+
Log.info "Admin getting objectives - inventory_id: #{inventory_id} - partner_id: #{partner_id}"
|
369
|
+
coco.get "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/objectives"
|
370
|
+
end
|
371
|
+
|
372
|
+
def delete_objective_admin_v1 partner_id, inventory_id, objective_id
|
373
|
+
Log.info "Admin deleting objective - inventory_id: #{inventory_id} - partner_id: #{partner_id} - objective_id: #{objective_id}"
|
374
|
+
coco.delete "/v1/cc/admin/#{partner_id}/#{URI.encode inventory_id}/objective/#{objective_id}"
|
375
|
+
end
|
376
|
+
|
377
|
+
|
378
|
+
# get the transaction log of an inventory,
|
379
|
+
def get_inventory_log_v1 partner_id, inventory_id, params={}
|
380
|
+
params = {
|
381
|
+
'start' => days_from_now(-7),
|
382
|
+
'coalesce' => false,
|
383
|
+
}.merge(params)
|
384
|
+
# format the timestamp if we need to
|
385
|
+
if params['start'].respond_to? :utc
|
386
|
+
params['start'] = params['start'].utc.iso8601(3)
|
387
|
+
end
|
388
|
+
Log.info "Getting inventory log - partner_id: #{partner_id} - inventory_id: #{inventory_id}"
|
389
|
+
coco.post "/v1/cc/admin/#{partner_id}/#{inventory_id}/log", params
|
390
|
+
end
|
391
|
+
|
392
|
+
def ensure_inventory_does_not_exist_v1 partner_id, inventory_id
|
393
|
+
delete_inventory_admin_v1 partner_id, inventory_id
|
394
|
+
rescue Grifter::RequestException => e
|
395
|
+
# if the inventory does not an exist a 404 is returned. For our purposes, that is fine
|
396
|
+
# so we'll allow the request to fail if 404 comes back
|
397
|
+
raise e unless e.code.to_i == 404
|
398
|
+
end
|
399
|
+
|
400
|
+
# make an inventory complete with
|
401
|
+
# - modules
|
402
|
+
# - containers
|
403
|
+
# - taxons
|
404
|
+
# - coming soon: Learning objectives
|
405
|
+
def create_v1_test_inventory partner_id, options={}
|
406
|
+
options = {
|
407
|
+
inventory_id: "Intro_to_#{random_string}",
|
408
|
+
|
409
|
+
# concepts are not really made, but are used as an organizational element
|
410
|
+
num_concepts: 2,
|
411
|
+
# containers are made per concept
|
412
|
+
num_assessing_containers_per_concept: 1,
|
413
|
+
num_teaching_containers_per_concept: 2,
|
414
|
+
|
415
|
+
# modules are made per container
|
416
|
+
num_modules_per_assessing_container: 2,
|
417
|
+
num_modules_per_teaching_container: 3,
|
418
|
+
|
419
|
+
taxonomy_name: 'testtax',
|
420
|
+
num_taxons: 5,
|
421
|
+
num_modules_per_taxon: (3..20),
|
422
|
+
num_containers_per_taxon: (0..2),
|
423
|
+
|
424
|
+
# make this many modules|containers|taxons at a time
|
425
|
+
batch_size: 50
|
426
|
+
|
427
|
+
}.merge options
|
428
|
+
|
429
|
+
options[:partner_id] = partner_id
|
430
|
+
|
431
|
+
module_ids = nil
|
432
|
+
container_ids = nil
|
433
|
+
taxon_ids = nil
|
434
|
+
|
435
|
+
as_account :knerd do
|
436
|
+
|
437
|
+
inv_id = options[:inventory_id]
|
438
|
+
create_inventory_admin_v1 partner_id, options[:inventory_id]
|
439
|
+
|
440
|
+
containers = []
|
441
|
+
modules = []
|
442
|
+
|
443
|
+
options[:num_concepts].times do |concept_num|
|
444
|
+
concept_id = "concept_#{concept_num}"
|
445
|
+
|
446
|
+
# for each concept, setup the assessing and teaching containers
|
447
|
+
options[:num_assessing_containers_per_concept].times do |container_num|
|
448
|
+
container_id = "#{concept_id}_assess_cont_#{container_num}"
|
449
|
+
|
450
|
+
container_mods = []
|
451
|
+
options[:num_modules_per_assessing_container].times do |module_num|
|
452
|
+
module_id = "#{container_id}_module_#{module_num}"
|
453
|
+
container_mods << test_module_object_v1({ 'module_id' => module_id,
|
454
|
+
'module_type' => 'assessment' })
|
455
|
+
end
|
456
|
+
modules += container_mods
|
457
|
+
|
458
|
+
containers << test_container_object_v1({'container_id' => container_id,
|
459
|
+
'container_type' => 'target',
|
460
|
+
'modules' => container_mods.map{|m| m['module_id']} })
|
461
|
+
end
|
462
|
+
|
463
|
+
# for each concept, setup the assessing and teaching containers
|
464
|
+
options[:num_teaching_containers_per_concept].times do |container_num|
|
465
|
+
container_id = "#{concept_id}_teach_cont_#{container_num}"
|
466
|
+
|
467
|
+
container_mods = []
|
468
|
+
options[:num_modules_per_teaching_container].times do |module_num|
|
469
|
+
module_id = "#{container_id}_module_#{module_num}"
|
470
|
+
container_mods << test_module_object_v1({ 'module_id' => module_id,
|
471
|
+
'module_type' => 'instruction' })
|
472
|
+
end
|
473
|
+
modules += container_mods
|
474
|
+
|
475
|
+
containers << test_container_object_v1({'container_id' => container_id,
|
476
|
+
'container_type' => 'presentation',
|
477
|
+
'modules' => container_mods.map{|m| m['module_id']} })
|
478
|
+
end
|
479
|
+
|
480
|
+
end
|
481
|
+
|
482
|
+
module_ids = modules.map{|m| m['module_id']}
|
483
|
+
container_ids = containers.map{|c| c['container_id']}
|
484
|
+
|
485
|
+
taxons = []
|
486
|
+
options[:num_taxons].times do |taxon_num|
|
487
|
+
taxon_id = "#{options[:taxonomy_name]}:#{taxon_num}_#{random_string(8)}"
|
488
|
+
mods = module_ids.shuffle[0...rand(options[:num_modules_per_taxon])]
|
489
|
+
taxons << test_taxon_object_v1({ 'taxon_id' => taxon_id,
|
490
|
+
'modules' => mods })
|
491
|
+
end
|
492
|
+
|
493
|
+
taxon_ids = taxons.map{|t| t['taxon_id']}
|
494
|
+
|
495
|
+
# now make all the objects in an order that will work:
|
496
|
+
# - make all modules
|
497
|
+
# - make all containers, which reference modules
|
498
|
+
# - make all taxons, which reference modules and containers
|
499
|
+
modules.each_slice(options[:batch_size]) do |batch|
|
500
|
+
set_account :knerd # this protects against expiring token
|
501
|
+
create_modules_admin_v1 partner_id, inv_id, batch
|
502
|
+
end
|
503
|
+
|
504
|
+
containers.each_slice(options[:batch_size]) do |batch|
|
505
|
+
set_account :knerd # this protects against expiring token
|
506
|
+
create_containers_admin_v1 partner_id, inv_id, batch
|
507
|
+
end
|
508
|
+
|
509
|
+
taxons.each_slice(options[:batch_size]) do |batch|
|
510
|
+
set_account :knerd # this protects against expiring token
|
511
|
+
create_taxons_admin_v1 partner_id, inv_id, batch
|
512
|
+
end
|
513
|
+
|
514
|
+
end
|
515
|
+
# returning the options is good b/c
|
516
|
+
# it returns the partner_id and inventory_id in a Hash
|
517
|
+
# with some other keys too
|
518
|
+
options.merge 'module_ids' => module_ids,
|
519
|
+
'container_ids' => container_ids,
|
520
|
+
'taxon_ids' => taxon_ids
|
521
|
+
end
|