canvas_sync 0.18.12 → 0.19.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  RSpec.describe CanvasSync do
4
4
  describe '.provisioning_sync' do
5
5
  it 'invokes the first job in the queue and passes on the rest of the job chain' do
6
- expected_job_chain = CanvasSync.default_provisioning_report_chain(['courses'], term_scope: nil).normalize![:parameters][0]
6
+ expected_job_chain = CanvasSync.default_provisioning_report_chain(['courses'], term_scope: nil).normalize![:args][0]
7
7
 
8
8
  expect(CanvasSync::Jobs::BeginSyncChainJob).to receive(:perform_later)
9
9
  .with(
@@ -32,17 +32,30 @@ RSpec.describe CanvasSync do
32
32
  })
33
33
  expect(chain.normalize!).to eq({
34
34
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
35
- :parameters => [[
36
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
37
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users"], :b=>2}},
38
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
39
- :term_scope=>"active",
40
- :sub_jobs=>[
41
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"], :c=>3}}
42
- ]
43
- }]}
44
- ]]}
45
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil, :d=>4}],
35
+ :args => [
36
+ [
37
+ {
38
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
39
+ :args=>[
40
+ [
41
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users"], :b=>2}},
42
+ {
43
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
44
+ :args=>[],
45
+ :kwargs=>{
46
+ :term_scope=>"active",
47
+ :sub_jobs=>[
48
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"], :c=>3}},
49
+ ],
50
+ },
51
+ },
52
+ ],
53
+ ],
54
+ :kwargs=>{},
55
+ },
56
+ ],
57
+ ],
58
+ :kwargs => {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil, :d=>4},
46
59
  })
47
60
  end
48
61
 
@@ -51,17 +64,28 @@ RSpec.describe CanvasSync do
51
64
  chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'], term_scope: :active)
52
65
  expect(chain.normalize!).to eq({
53
66
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
54
- :parameters => [[
55
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
56
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users"]}},
57
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
58
- :term_scope=>"active",
59
- :sub_jobs=>[
60
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
67
+ :args => [[
68
+ {
69
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
70
+ :args=>[
71
+ [
72
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users"]}},
73
+ {
74
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
75
+ :args=>[],
76
+ :kwargs=>{
77
+ :sub_jobs=>[
78
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
79
+ ],
80
+ :term_scope=>"active",
81
+ }
82
+ }
61
83
  ]
62
- }]}
63
- ]]}
64
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil}]
84
+ ],
85
+ :kwargs=>{},
86
+ }
87
+ ]],
88
+ :kwargs => {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil},
65
89
  })
66
90
  end
67
91
  end
@@ -71,16 +95,23 @@ RSpec.describe CanvasSync do
71
95
  chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'])
72
96
  expect(chain.normalize!).to eq({
73
97
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
74
- :parameters => [[
75
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
76
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
77
- :term_scope=>nil,
78
- :sub_jobs=>[
79
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "courses"]}}
80
- ]
81
- }]}
82
- ]]}
83
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil}],
98
+ :args => [[
99
+ {
100
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
101
+ :args=>[[
102
+ {
103
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
104
+ :args=>[],
105
+ :kwargs=>{
106
+ :sub_jobs=>[{:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "courses"]}}],
107
+ :term_scope=>nil,
108
+ }
109
+ }
110
+ ]],
111
+ :kwargs=>{}
112
+ }
113
+ ]],
114
+ :kwargs => {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil},
84
115
  })
85
116
  end
86
117
  end
@@ -90,17 +121,24 @@ RSpec.describe CanvasSync do
90
121
  chain = CanvasSync.default_provisioning_report_chain(['roles', 'courses'], term_scope: :active)
91
122
  expect(chain.normalize!).to eq({
92
123
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
93
- :parameters => [[
94
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
95
- {:job=>"CanvasSync::Jobs::SyncRolesJob", :options=>{}},
96
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
97
- :term_scope=>"active",
98
- :sub_jobs=>[
99
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
100
- ]
101
- }]}
102
- ]]}
103
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil}],
124
+ :args => [[
125
+ {
126
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
127
+ :args=>[[
128
+ {:job=>"CanvasSync::Jobs::SyncRolesJob", :options=>{}},
129
+ {
130
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
131
+ :args=>[],
132
+ :kwargs=>{
133
+ :sub_jobs=>[{:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}],
134
+ :term_scope=>"active",
135
+ }
136
+ },
137
+ ]],
138
+ :kwargs=>{}
139
+ }
140
+ ]],
141
+ :kwargs => {:batch_genre=>nil, :full_sync_every=>nil, :legacy_support=>false, :updated_after=>nil},
104
142
  })
105
143
  end
106
144
  end
@@ -110,17 +148,24 @@ RSpec.describe CanvasSync do
110
148
  chain = CanvasSync.default_provisioning_report_chain(['roles', 'courses'])
111
149
  expect(chain.normalize!).to eq({
112
150
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
113
- :parameters => [[
114
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
115
- {:job=>"CanvasSync::Jobs::SyncRolesJob", :options=>{}},
116
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
117
- :term_scope=>nil,
118
- :sub_jobs=>[
119
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
120
- ]
121
- }]}
122
- ]]}
123
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil}],
151
+ :args => [[
152
+ {
153
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
154
+ :args=>[[
155
+ {:job=>"CanvasSync::Jobs::SyncRolesJob", :options=>{}},
156
+ {
157
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
158
+ :args=>[],
159
+ :kwargs=>{
160
+ :sub_jobs=>[{:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}],
161
+ :term_scope=>nil,
162
+ }
163
+ }
164
+ ]],
165
+ :kwargs=>{}
166
+ }
167
+ ]],
168
+ :kwargs => {:batch_genre=>nil, :full_sync_every=>nil, :legacy_support=>false, :updated_after=>nil},
124
169
  })
125
170
  end
126
171
  end
@@ -130,17 +175,24 @@ RSpec.describe CanvasSync do
130
175
  chain = CanvasSync.default_provisioning_report_chain(['admins', 'courses'], term_scope: :active)
131
176
  expect(chain.normalize!).to eq({
132
177
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
133
- :parameters => [[
134
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
135
- {:job=>"CanvasSync::Jobs::SyncAdminsJob", :options=>{}},
136
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
137
- :term_scope=>"active",
138
- :sub_jobs=>[
139
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
140
- ]
141
- }]}
142
- ]]}
143
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil}],
178
+ :args => [[
179
+ {
180
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
181
+ :args=>[[
182
+ {:job=>"CanvasSync::Jobs::SyncAdminsJob", :options=>{}},
183
+ {
184
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
185
+ :args=>[],
186
+ :kwargs=>{
187
+ :sub_jobs=>[{:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}],
188
+ :term_scope=>"active"
189
+ }
190
+ }
191
+ ]],
192
+ :kwargs=>{}
193
+ }
194
+ ]],
195
+ :kwargs => {:batch_genre=>nil, :full_sync_every=>nil, :legacy_support=>false, :updated_after=>nil},
144
196
  })
145
197
  end
146
198
  end
@@ -150,17 +202,24 @@ RSpec.describe CanvasSync do
150
202
  chain = CanvasSync.default_provisioning_report_chain(['admins', 'courses'])
151
203
  expect(chain.normalize!).to eq({
152
204
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
153
- :parameters => [[
154
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
155
- {:job=>"CanvasSync::Jobs::SyncAdminsJob", :options=>{}},
156
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
157
- :term_scope=>nil,
158
- :sub_jobs=>[
159
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
160
- ]
161
- }]}
162
- ]]}
163
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil}],
205
+ :args => [[
206
+ {
207
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
208
+ :args=>[[
209
+ {:job=>"CanvasSync::Jobs::SyncAdminsJob", :options=>{}},
210
+ {
211
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
212
+ :args=>[],
213
+ :kwargs=>{
214
+ :sub_jobs=>[{:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}],
215
+ :term_scope=>nil
216
+ }
217
+ }
218
+ ]],
219
+ :kwargs=>{}
220
+ }
221
+ ]],
222
+ :kwargs => {:batch_genre=>nil, :full_sync_every=>nil, :legacy_support=>false, :updated_after=>nil},
164
223
  })
165
224
  end
166
225
  end
@@ -169,20 +228,29 @@ RSpec.describe CanvasSync do
169
228
  it "appends the SyncAssignmentsJob" do
170
229
  chain = CanvasSync.default_provisioning_report_chain(%w[users enrollments assignments])
171
230
 
172
- expect(chain.normalize!).to eq(
231
+ expect(chain.normalize!).to eq({
173
232
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
174
- :parameters => [[
175
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
176
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
177
- :term_scope=>nil,
178
- :sub_jobs=>[
179
- {:job=>"CanvasSync::Jobs::SyncAssignmentsJob", :options=>{}},
180
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "enrollments"]}}
181
- ]
182
- }]}
183
- ]]}
184
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil}],
185
- )
233
+ :args => [[
234
+ {
235
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
236
+ :args=>[[
237
+ {
238
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
239
+ :args=>[],
240
+ :kwargs=>{
241
+ :sub_jobs=>[
242
+ {:job=>"CanvasSync::Jobs::SyncAssignmentsJob", :options=>{}},
243
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "enrollments"]}}
244
+ ],
245
+ :term_scope=>nil
246
+ }
247
+ }
248
+ ]],
249
+ :kwargs=>{}
250
+ }
251
+ ]],
252
+ :kwargs => {:batch_genre=>nil, :full_sync_every=>nil, :legacy_support=>false, :updated_after=>nil},
253
+ })
186
254
  end
187
255
  end
188
256
 
@@ -190,20 +258,29 @@ RSpec.describe CanvasSync do
190
258
  it "appends the SyncSubmissionsJob" do
191
259
  chain = CanvasSync.default_provisioning_report_chain(%w[users enrollments submissions])
192
260
 
193
- expect(chain.normalize!).to eq(
261
+ expect(chain.normalize!).to eq({
194
262
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
195
- :parameters => [[
196
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
197
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
198
- :term_scope=>nil,
199
- :sub_jobs=>[
200
- {:job=>"CanvasSync::Jobs::SyncSubmissionsJob", :options=>{}},
201
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "enrollments"]}}
202
- ]
203
- }]}
204
- ]]}
205
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil}],
206
- )
263
+ :args => [[
264
+ {
265
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
266
+ :args=>[[
267
+ {
268
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
269
+ :args=>[],
270
+ :kwargs=>{
271
+ :sub_jobs=>[
272
+ {:job=>"CanvasSync::Jobs::SyncSubmissionsJob", :options=>{}},
273
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "enrollments"]}}
274
+ ],
275
+ :term_scope=>nil
276
+ }
277
+ }
278
+ ]],
279
+ :kwargs=>{}
280
+ }
281
+ ]],
282
+ :kwargs => {:batch_genre=>nil, :full_sync_every=>nil, :legacy_support=>false, :updated_after=>nil},
283
+ })
207
284
  end
208
285
  end
209
286
 
@@ -211,20 +288,29 @@ RSpec.describe CanvasSync do
211
288
  it "appends the SyncAssignmentGroupsJob" do
212
289
  chain = CanvasSync.default_provisioning_report_chain(%w[users enrollments assignment_groups])
213
290
 
214
- expect(chain.normalize!).to eq(
291
+ expect(chain.normalize!).to eq({
215
292
  :job => "CanvasSync::Jobs::BeginSyncChainJob",
216
- :parameters => [[
217
- {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
218
- {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
219
- :term_scope=>nil,
220
- :sub_jobs=>[
221
- {:job=>"CanvasSync::Jobs::SyncAssignmentGroupsJob", :options=>{}},
222
- {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "enrollments"]}}
223
- ]
224
- }]}
225
- ]]}
226
- ], {:legacy_support=>false, :updated_after=>nil, :full_sync_every=>nil, :batch_genre=>nil}],
227
- )
293
+ :args => [[
294
+ {
295
+ :job=>"CanvasSync::JobBatches::ConcurrentBatchJob",
296
+ :args=>[[
297
+ {
298
+ :job=>"CanvasSync::Jobs::SyncTermsJob",
299
+ :args=>[],
300
+ :kwargs=>{
301
+ :sub_jobs=>[
302
+ {:job=>"CanvasSync::Jobs::SyncAssignmentGroupsJob", :options=>{}},
303
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "enrollments"]}}
304
+ ],
305
+ :term_scope=>nil
306
+ }
307
+ }
308
+ ]],
309
+ :kwargs=>{}
310
+ }
311
+ ]],
312
+ :kwargs => {:batch_genre=>nil, :full_sync_every=>nil, :legacy_support=>false, :updated_after=>nil},
313
+ })
228
314
  end
229
315
  end
230
316
  end
@@ -31,52 +31,4 @@ RSpec.describe CanvasSync::Jobs::CanvasProcessWaiter do
31
31
  expect(CanvasSync::Jobs::CanvasProcessWaiter).to have_been_enqueued.once.with('/blah/', nil, interval: 13)
32
32
  end
33
33
  end
34
-
35
- describe 'InvokeCallbackWorker' do
36
- let!(:worker) { CanvasSync::Jobs::CanvasProcessWaiter::InvokeCallbackWorker.new }
37
-
38
- with_model :Model do
39
- table
40
- model do
41
- def wait_callback(*args); end
42
-
43
- def self.wait_callback(*args); end
44
- end
45
- end
46
-
47
- class CPW_TestWorker
48
- extend Sidekiq::Worker
49
- end
50
-
51
- it 'schedules a given job' do
52
- expect(CPW_TestWorker).to receive(:perform_async)
53
- worker.perform(
54
- job: 'CPW_TestWorker',
55
- args: [1, 2],
56
- )
57
- end
58
-
59
- it 'invokes a model method' do
60
- model = Model.create!
61
- expect(Model).to receive(:find_by).with(id: model.id).and_return(model)
62
- expect(model).to receive(:wait_callback).with(1, 2, a: 3, b: 4)
63
- worker.perform(
64
- model: Model.to_s,
65
- find_by: { id: model.id },
66
- method: :wait_callback,
67
- args: [1, 2],
68
- kwargs: { a: 3, b: 4 },
69
- )
70
- end
71
-
72
- it 'invokes a class method' do
73
- expect(Model).to receive(:wait_callback).with(1, 2, a: 3, b: 4)
74
- worker.perform(
75
- class: Model.to_s,
76
- method: :wait_callback,
77
- args: [1, 2],
78
- kwargs: { a: 3, b: 4 },
79
- )
80
- end
81
- end
82
34
  end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CanvasSync::MiscHelper do
4
+ describe ".invoke_task" do
5
+ with_model :Model do
6
+ table
7
+ model do
8
+ def wait_callback(*args); end
9
+
10
+ def self.wait_callback(*args); end
11
+ end
12
+ end
13
+
14
+ class CPW_TestWorker
15
+ extend Sidekiq::Worker
16
+ end
17
+
18
+ it 'schedules a given job' do
19
+ expect(CPW_TestWorker).to receive(:perform_async)
20
+ described_class.invoke_task(
21
+ job: 'CPW_TestWorker',
22
+ args: [1, 2],
23
+ )
24
+ end
25
+
26
+ it 'accepts a method string' do
27
+ expect(Model).to receive(:wait_callback).with(1, 2, a: 3, b: 4)
28
+ described_class.invoke_task(
29
+ method: "#{Model.to_s}.wait_callback",
30
+ args: [1, 2],
31
+ kwargs: { a: 3, b: 4 },
32
+ )
33
+ end
34
+
35
+ it 'invokes a model method' do
36
+ model = Model.create!
37
+ expect(Model).to receive(:find_by).with(id: model.id).and_return(model)
38
+ expect(model).to receive(:wait_callback).with(1, 2, a: 3, b: 4)
39
+ described_class.invoke_task(
40
+ model: Model.to_s,
41
+ find_by: { id: model.id },
42
+ method: :wait_callback,
43
+ args: [1, 2],
44
+ kwargs: { a: 3, b: 4 },
45
+ )
46
+ end
47
+
48
+ it 'invokes a class method' do
49
+ expect(Model).to receive(:wait_callback).with(1, 2, a: 3, b: 4)
50
+ described_class.invoke_task(
51
+ class: Model.to_s,
52
+ method: :wait_callback,
53
+ args: [1, 2],
54
+ kwargs: { a: 3, b: 4 },
55
+ )
56
+ end
57
+ end
58
+ end