bearcat 1.0.0 → 1.5.24

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.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/bearcat.gemspec +15 -5
  3. data/lib/badgrcat/api_array.rb +25 -0
  4. data/lib/badgrcat/client/methods.rb +54 -0
  5. data/lib/badgrcat/client.rb +53 -0
  6. data/lib/badgrcat/version.rb +3 -0
  7. data/lib/bearcat/api_array.rb +132 -65
  8. data/lib/bearcat/client/account_reports.rb +6 -14
  9. data/lib/bearcat/client/accounts.rb +18 -6
  10. data/lib/bearcat/client/analytics.rb +12 -0
  11. data/lib/bearcat/client/assignment_groups.rb +15 -0
  12. data/lib/bearcat/client/assignments.rb +17 -9
  13. data/lib/bearcat/client/blueprint_courses.rb +25 -0
  14. data/lib/bearcat/client/calendar_events.rb +9 -17
  15. data/lib/bearcat/client/canvas_files.rb +0 -2
  16. data/lib/bearcat/client/conferences.rb +3 -8
  17. data/lib/bearcat/client/content_exports.rb +39 -0
  18. data/lib/bearcat/client/content_migrations.rb +54 -0
  19. data/lib/bearcat/client/conversations.rb +3 -8
  20. data/lib/bearcat/client/courses.rb +25 -14
  21. data/lib/bearcat/client/custom_gradebook_columns.rb +21 -0
  22. data/lib/bearcat/client/discussions.rb +10 -4
  23. data/lib/bearcat/client/enrollments.rb +9 -25
  24. data/lib/bearcat/client/external_tools.rb +18 -0
  25. data/lib/bearcat/client/file_helper.rb +36 -30
  26. data/lib/bearcat/client/files.rb +9 -0
  27. data/lib/bearcat/client/folders.rb +24 -0
  28. data/lib/bearcat/client/graph_ql.rb +17 -0
  29. data/lib/bearcat/client/group_categories.rb +18 -0
  30. data/lib/bearcat/client/group_memberships.rb +14 -0
  31. data/lib/bearcat/client/groups.rb +10 -2
  32. data/lib/bearcat/client/learning_outcomes.rb +17 -0
  33. data/lib/bearcat/client/logins.rb +20 -0
  34. data/lib/bearcat/client/module_items.rb +18 -0
  35. data/lib/bearcat/client/modules.rb +12 -7
  36. data/lib/bearcat/client/o_auth2.rb +18 -9
  37. data/lib/bearcat/client/outcome_groups.rb +2 -4
  38. data/lib/bearcat/client/outcome_imports.rb +48 -0
  39. data/lib/bearcat/client/outcomes.rb +4 -7
  40. data/lib/bearcat/client/pages.rb +15 -0
  41. data/lib/bearcat/client/progresses.rb +9 -0
  42. data/lib/bearcat/client/quizzes.rb +13 -9
  43. data/lib/bearcat/client/reports.rb +37 -17
  44. data/lib/bearcat/client/roles.rb +15 -0
  45. data/lib/bearcat/client/rubric.rb +17 -0
  46. data/lib/bearcat/client/rubric_assessment.rb +13 -0
  47. data/lib/bearcat/client/rubric_association.rb +13 -0
  48. data/lib/bearcat/client/search.rb +9 -0
  49. data/lib/bearcat/client/sections.rb +10 -17
  50. data/lib/bearcat/client/sis_imports.rb +6 -12
  51. data/lib/bearcat/client/submissions.rb +53 -21
  52. data/lib/bearcat/client/tabs.rb +12 -0
  53. data/lib/bearcat/client/users.rb +32 -13
  54. data/lib/bearcat/client.rb +111 -45
  55. data/lib/bearcat/client_module.rb +103 -0
  56. data/lib/bearcat/rate_limiting/increment_bucket.lua +33 -0
  57. data/lib/bearcat/rate_limiting/redis_script.rb +164 -0
  58. data/lib/bearcat/rate_limiting.rb +69 -0
  59. data/lib/bearcat/redis_connection.rb +106 -0
  60. data/lib/bearcat/spec_helpers.rb +125 -0
  61. data/lib/bearcat/version.rb +1 -1
  62. data/lib/bearcat.rb +49 -0
  63. data/lib/catalogcat/api_array.rb +22 -0
  64. data/lib/catalogcat/client/catalogs.rb +21 -0
  65. data/lib/catalogcat/client/certificates.rb +17 -0
  66. data/lib/catalogcat/client/courses.rb +25 -0
  67. data/lib/catalogcat/client/email_domain_sets.rb +17 -0
  68. data/lib/catalogcat/client/enrollments.rb +25 -0
  69. data/lib/catalogcat/client/orders.rb +13 -0
  70. data/lib/catalogcat/client/user_registrations.rb +9 -0
  71. data/lib/catalogcat/client.rb +26 -0
  72. data/lib/catalogcat/version.rb +3 -0
  73. data/lib/catalogcat.rb +14 -0
  74. data/spec/bearcat/api_array_spec.rb +112 -0
  75. data/spec/bearcat/client/accounts_spec.rb +71 -1
  76. data/spec/bearcat/client/analytics_spec.rb +22 -0
  77. data/spec/bearcat/client/assignment_groups_spec.rb +47 -0
  78. data/spec/bearcat/client/assignments_spec.rb +43 -0
  79. data/spec/bearcat/client/blueprint_courses_spec.rb +43 -0
  80. data/spec/bearcat/client/canvas_files_spec.rb +1 -2
  81. data/spec/bearcat/client/content_exports_spec.rb +68 -0
  82. data/spec/bearcat/client/content_migrations_spec.rb +94 -0
  83. data/spec/bearcat/client/courses_spec.rb +81 -2
  84. data/spec/bearcat/client/custom_gradebook_columns_spec.rb +66 -0
  85. data/spec/bearcat/client/discussions_spec.rb +73 -0
  86. data/spec/bearcat/client/enrollments_spec.rb +10 -0
  87. data/spec/bearcat/client/external_tools_spec.rb +106 -0
  88. data/spec/bearcat/client/files_spec.rb +15 -0
  89. data/spec/bearcat/client/folders_spec.rb +18 -0
  90. data/spec/bearcat/client/graph_ql_spec.rb +35 -0
  91. data/spec/bearcat/client/group_categories_spec.rb +45 -0
  92. data/spec/bearcat/client/group_membership_spec.rb +14 -0
  93. data/spec/bearcat/client/group_memberships_spec.rb +36 -0
  94. data/spec/bearcat/client/groups_spec.rb +46 -0
  95. data/spec/bearcat/client/learning_outcomes_spec.rb +25 -0
  96. data/spec/bearcat/client/module_items_spec.rb +60 -0
  97. data/spec/bearcat/client/modules_spec.rb +38 -1
  98. data/spec/bearcat/client/o_auth2_spec.rb +3 -3
  99. data/spec/bearcat/client/pages_spec.rb +17 -0
  100. data/spec/bearcat/client/quizzes_spec.rb +41 -4
  101. data/spec/bearcat/client/reports_spec.rb +40 -1
  102. data/spec/bearcat/client/roles_spec.rb +24 -0
  103. data/spec/bearcat/client/rubric_assessment_spec.rb +47 -0
  104. data/spec/bearcat/client/rubric_association_spec.rb +39 -0
  105. data/spec/bearcat/client/rubric_spec.rb +45 -0
  106. data/spec/bearcat/client/search_spec.rb +16 -0
  107. data/spec/bearcat/client/sections_spec.rb +12 -0
  108. data/spec/bearcat/client/submissions_spec.rb +47 -2
  109. data/spec/bearcat/client/users_spec.rb +43 -0
  110. data/spec/bearcat/client_spec.rb +1 -4
  111. data/spec/bearcat/rate_limiting_spec.rb +62 -0
  112. data/spec/bearcat/stub_bearcat_spec.rb +15 -0
  113. data/spec/fixtures/access_token.json +3 -0
  114. data/spec/fixtures/account_admin_create.json +14 -0
  115. data/spec/fixtures/account_admin_delete.json +15 -0
  116. data/spec/fixtures/account_admins.json +54 -0
  117. data/spec/fixtures/account_courses.json +48 -0
  118. data/spec/fixtures/account_grading_standards.json +20 -0
  119. data/spec/fixtures/account_groups.json +42 -0
  120. data/spec/fixtures/account_role.json +34 -0
  121. data/spec/fixtures/account_roles.json +35 -0
  122. data/spec/fixtures/account_sis_imports.json +39 -0
  123. data/spec/fixtures/account_sub_accounts.json +17 -0
  124. data/spec/fixtures/accounts.json +13 -0
  125. data/spec/fixtures/assignment.json +32 -0
  126. data/spec/fixtures/assignment_group.json +7 -0
  127. data/spec/fixtures/assignment_groups.json +16 -0
  128. data/spec/fixtures/blueprint_migration.json +12 -0
  129. data/spec/fixtures/blueprint_subscriptions.json +5 -0
  130. data/spec/fixtures/blueprint_template.json +7 -0
  131. data/spec/fixtures/blueprint_update_assocations_success.json +3 -0
  132. data/spec/fixtures/communication_channels.json +10 -0
  133. data/spec/fixtures/content_export.json +9 -0
  134. data/spec/fixtures/content_migration_files/content_migration.json +13 -0
  135. data/spec/fixtures/course_copy.json +18 -0
  136. data/spec/fixtures/course_files.json +38 -0
  137. data/spec/fixtures/course_folder.json +21 -0
  138. data/spec/fixtures/course_folders.json +44 -0
  139. data/spec/fixtures/course_grading_standards.json +20 -0
  140. data/spec/fixtures/course_settings.json +33 -0
  141. data/spec/fixtures/create_course_discussion.json +44 -0
  142. data/spec/fixtures/created_group.json +37 -0
  143. data/spec/fixtures/created_group_category.json +15 -0
  144. data/spec/fixtures/created_group_membership.json +8 -0
  145. data/spec/fixtures/created_module.json +13 -0
  146. data/spec/fixtures/custom_gradebook_columns/column_data.json +4 -0
  147. data/spec/fixtures/custom_gradebook_columns/custom_gradebook_column.json +7 -0
  148. data/spec/fixtures/custom_gradebook_columns/custom_gradebook_columns.json +16 -0
  149. data/spec/fixtures/custom_gradebook_columns/gradebook_column_progress.json +14 -0
  150. data/spec/fixtures/dashboard.json +6 -0
  151. data/spec/fixtures/delete_course.json +3 -0
  152. data/spec/fixtures/delete_group_category.json +3 -0
  153. data/spec/fixtures/deleted_group.json +37 -0
  154. data/spec/fixtures/department_level_participation.json +73 -0
  155. data/spec/fixtures/department_level_statistics.json +10 -0
  156. data/spec/fixtures/discussion_entries.json +21 -0
  157. data/spec/fixtures/discussion_entry_replies.json +21 -0
  158. data/spec/fixtures/discussion_topic.json +49 -0
  159. data/spec/fixtures/discussion_topics.json +51 -0
  160. data/spec/fixtures/edited_group.json +129 -0
  161. data/spec/fixtures/edited_group_category.json +15 -0
  162. data/spec/fixtures/enrollment_terms.json +1 -1
  163. data/spec/fixtures/external_tool.json +55 -0
  164. data/spec/fixtures/external_tools.json +57 -0
  165. data/spec/fixtures/file.csv +5 -0
  166. data/spec/fixtures/gradebook_history.json +52 -0
  167. data/spec/fixtures/graph_ql_scores.json +33 -0
  168. data/spec/fixtures/group.json +15 -0
  169. data/spec/fixtures/group_categories.json +28 -0
  170. data/spec/fixtures/group_category.json +13 -0
  171. data/spec/fixtures/group_category_groups.json +20 -0
  172. data/spec/fixtures/group_membership.json +7 -0
  173. data/spec/fixtures/learning_outcome.json +32 -0
  174. data/spec/fixtures/merge_user.json +8 -0
  175. data/spec/fixtures/module.json +15 -0
  176. data/spec/fixtures/module_item.json +15 -0
  177. data/spec/fixtures/module_items.json +47 -0
  178. data/spec/fixtures/ok.json +3 -0
  179. data/spec/fixtures/outcome_result.json +13 -0
  180. data/spec/fixtures/pages.json +40 -0
  181. data/spec/fixtures/progress.json +13 -0
  182. data/spec/fixtures/quizzes/course_quiz_questions.json +59 -0
  183. data/spec/fixtures/quizzes/quiz_assignment_override.json +31 -0
  184. data/spec/fixtures/reactivate_enrollment.json +20 -0
  185. data/spec/fixtures/rubric.json +13 -0
  186. data/spec/fixtures/rubric_assessment.json +32 -0
  187. data/spec/fixtures/rubric_association.json +13 -0
  188. data/spec/fixtures/search_find_recipients.json +10 -0
  189. data/spec/fixtures/update_section.json +1 -1
  190. data/spec/fixtures/user_details.json +16 -0
  191. data/spec/fixtures/user_logins.json +9 -0
  192. data/spec/helper.rb +2 -0
  193. metadata +336 -43
@@ -0,0 +1,21 @@
1
+ module Catalogcat
2
+ class Client < Footrest::Client
3
+ module Catalogs
4
+ def list_catalogs(params = {})
5
+ get('/api/v1/catalogs', params)
6
+ end
7
+
8
+ def applicants(params = {})
9
+ get('/api/v1/applicants', params)
10
+ end
11
+
12
+ def completed_certificates(params = {})
13
+ get('/api/v1/completed_certificates', params)
14
+ end
15
+
16
+ def get_order(id, params = {})
17
+ get("/api/v1/orders/#{id}", params)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module Catalogcat
2
+ class Client < Footrest::Client
3
+ module Certificates
4
+ def listing_certificate(listing_id, params = {})
5
+ get("/api/v1/certificates?certificate[listing_id]=#{listing_id}", params)
6
+ end
7
+
8
+ def create_certificate(params = {})
9
+ post('/api/v1/certificates', params)
10
+ end
11
+
12
+ def list_completed_certificates(params = {})
13
+ get("/api/v1/completed_certificates", params)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module Catalogcat
2
+ class Client < Footrest::Client
3
+ module Courses
4
+ def list_courses(page = 1, params = {})
5
+ get("/api/v1/courses?page=#{page}&per_page=100", params)
6
+ end
7
+
8
+ def create_course(params = {})
9
+ post('/api/v1/courses', params)
10
+ end
11
+
12
+ def update_course(id, params = {})
13
+ put("/api/v1/courses/#{id}", params)
14
+ end
15
+
16
+ def get_course(id, params = {})
17
+ get("/api/v1/courses/#{id}", params)
18
+ end
19
+
20
+ def delete_course(course)
21
+ delete("/api/v1/courses/#{course}")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module Catalogcat
2
+ class Client < Footrest::Client
3
+ module EmailDomainSets
4
+ def list_email_domain_sets(page = 1, params = {})
5
+ get("/api/v1/email_domain_sets?page=#{page}&per_page=100", params)
6
+ end
7
+
8
+ def update_email_domain_set(id, params = {})
9
+ put("/api/v1/email_domain_sets/#{id}", params)
10
+ end
11
+
12
+ def get_email_domain_set(id, params = {})
13
+ get("/api/v1/email_domain_sets/#{id}", params)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module Catalogcat
2
+ class Client < Footrest::Client
3
+ module Enrollments
4
+ def list_enrollments(page = 1, params = {})
5
+ get("/api/v1/enrollments?page=#{page}&per_page=100", params)
6
+ end
7
+
8
+ def create_enrollment(params = {})
9
+ post('api/v1/enrollments', params)
10
+ end
11
+
12
+ def update_enrollment(id, params = {})
13
+ put("/api/v1/enrollments/#{id}", params)
14
+ end
15
+
16
+ def get_enrollment(id, params = {})
17
+ get("/api/v1/enrollments/#{id}", params)
18
+ end
19
+
20
+ def delete_enrollment(enrollment)
21
+ delete("/api/v1/enrollments/#{enrollment}")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module Catalogcat
2
+ class Client < Footrest::Client
3
+ module Orders
4
+ def list_orders(params = {})
5
+ get("api/v1/orders", params)
6
+ end
7
+
8
+ def get_order(id, params = {})
9
+ get("api/v1/orders/#{id}", params)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Catalogcat
2
+ class Client < Footrest::Client
3
+ module UserRegistrations
4
+ def list_user_registrations(params = {})
5
+ get("/api/v1/user_registrations", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ require 'footrest/client'
2
+
3
+ module Catalogcat
4
+ class Client < Footrest::Client
5
+ require 'catalogcat/api_array' # monkey patch
6
+
7
+ Dir[File.join(__dir__, 'client', '*.rb')].each do |mod|
8
+ mname = File.basename(mod, '.*').camelize
9
+ require mod
10
+ include "Catalogcat::Client::#{mname}".constantize
11
+ end
12
+
13
+ # Override Footrest connection to use Token authorization
14
+ def set_connection(config)
15
+ super
16
+ connection.headers[:authorization].sub! 'Bearer', 'Token'
17
+ end
18
+
19
+ # Override Footrest request for ApiArray support
20
+ def request(method, &block)
21
+ response = connection.send(method, &block)
22
+
23
+ Catalogcat::ApiArray.process_response(response, self)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Catalogcat
2
+ VERSION = 'bearcat' unless defined?(Catalogcat::VERSION)
3
+ end
data/lib/catalogcat.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'catalogcat/client'
2
+
3
+ module Catalogcat
4
+ class << self
5
+ require 'logger'
6
+
7
+ def logger
8
+ return @logger if defined? @logger
9
+ @logger = Logger.new(STDOUT)
10
+ @logger.level = Logger::DEBUG
11
+ @logger
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,112 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::ApiArray do
4
+ let(:api_client) { double }
5
+ let(:response_headers) { { } }
6
+ let(:response_env) { { url: "https://fake.com" } }
7
+ let(:response_body) { @response_body || [] }
8
+ let(:original_response) do
9
+ double(
10
+ body: response_body,
11
+ status: 200,
12
+ headers: Faraday::Utils::Headers.new(response_headers),
13
+ env: Faraday::Env.from(response_env)
14
+ )
15
+ end
16
+
17
+ describe 'get_page' do
18
+ let(:api_array) { described_class.process_response(original_response, api_client) }
19
+ let(:connection) { double }
20
+ let(:request) { double }
21
+
22
+ before :each do
23
+ api_array.instance_variable_set('@page_count', nil)
24
+ allow(api_client).to receive(:connection).and_return connection
25
+ allow(connection).to receive(:send) do |&block|
26
+ block.call(request)
27
+ end
28
+ end
29
+
30
+ it 'gets a page of results' do
31
+ expect(request).to receive(:url).with('https://fake.com', 'page' => '2')
32
+ api_array.send(:get_page, 'https://fake.com?page=2', {})
33
+ end
34
+
35
+ it 'merges additonal params to the url query' do
36
+ expect(request).to receive(:url).with('https://fake.com', 'test' => 'param', 'page' => 2)
37
+ api_array.send(:get_page, 'https://fake.com?test=param', 'page' => 2)
38
+ end
39
+
40
+ it 'handles array parameters' do
41
+ expect(request).to receive(:url).with('https://fake.com', 'test' => ['param'], 'second' => ['param'])
42
+ api_array.send(:get_page, 'https://fake.com?test%5B%5D=param', 'second' => ['param'])
43
+ end
44
+
45
+ it 'sets the per_page parameter if not already set and @page_count has a value' do
46
+ api_array.instance_variable_set('@page_count', 50)
47
+
48
+ expect(request).to receive(:url).with('https://fake.com', 'per_page' => 50)
49
+ api_array.send(:get_page, 'https://fake.com?', {})
50
+ end
51
+
52
+ it 'does not set the per_page parameter if @page_count is not available' do
53
+ api_array.instance_variable_set('@page_count', nil)
54
+
55
+ expect(request).to receive(:url).with('https://fake.com', {})
56
+ api_array.send(:get_page, 'https://fake.com?', {})
57
+ end
58
+
59
+ it 'does not set the per_page parameter if it is already set' do
60
+ api_array.instance_variable_set('@page_count', 50)
61
+
62
+ expect(request).to receive(:url).with('https://fake.com', 'per_page' => 10)
63
+ api_array.send(:get_page, 'https://fake.com?', 'per_page' => 10)
64
+ end
65
+ end
66
+
67
+ describe '#iterate_pages' do
68
+ let(:api_array) { described_class.process_response(original_response, api_client) }
69
+
70
+ let(:original_response) do
71
+ super().tap do |s|
72
+ s.headers['Link'] = [
73
+ '<https://fake.com?page=1>; rel="first"'
74
+ ].join(', ')
75
+ end
76
+ end
77
+
78
+ it 're-requests the first-page if per_page has changed' do
79
+ expect(api_array).to receive(:get_page).and_return(original_response)
80
+ api_array.send(:iterate_pages, 10).to_a
81
+ end
82
+
83
+ it 'yields existing first-page if per_page is unchanged' do
84
+ expect(api_array).not_to receive(:get_page)
85
+ api_array.send(:iterate_pages, nil).to_a
86
+ end
87
+ end
88
+
89
+ context 'makes returned values indifferent' do
90
+ it 'makes a Hash response indifferent' do
91
+ @response_body = { something: 1 }
92
+ result = described_class.process_response(original_response, api_client)
93
+ expect(result[:something]).to eq 1
94
+ expect(result['something']).to eq 1
95
+ end
96
+
97
+ it 'makes an Array response indifferent' do
98
+ @response_body = [{ something: 1 }]
99
+ result = described_class.process_response(original_response, api_client)
100
+ expect(result[0][:something]).to eq 1
101
+ expect(result[0]['something']).to eq 1
102
+ end
103
+
104
+ it 'makes a single-key Hash response indifferent' do
105
+ @response_body = { 'something' => [ { foo: 1 } ] }
106
+ allow(described_class).to receive(:array_key).and_return('something')
107
+ result = described_class.process_response(original_response, api_client)
108
+ expect(result[0][:foo]).to eq 1
109
+ expect(result[0]['foo']).to eq 1
110
+ end
111
+ end
112
+ end
@@ -5,6 +5,29 @@ describe Bearcat::Client::Accounts do
5
5
  @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
6
6
  end
7
7
 
8
+ it 'returns a list of all the accounts the user belongs to' do
9
+ stub_get(@client, "/api/v1/accounts").to_return(json_response("accounts.json"))
10
+ accounts = @client.list_accounts
11
+ accounts.count.should == 1
12
+ accounts.first['name'].should == 'Local Testing'
13
+ end
14
+
15
+ it 'returns a list of all of the accounts admins' do
16
+ stub_get(@client, "/api/v1/accounts/1/admins").to_return(json_response("account_admins.json"))
17
+ account_admins = @client.account_admins(1)
18
+ account_admins.count.should == 4
19
+ account_admins.first['id'].should == 3
20
+ account_admins.last['role'].should == 'Custom Admin'
21
+ end
22
+
23
+ it 'returns a list of all sub-accounts' do
24
+ stub_get(@client, "/api/v1/accounts/1/sub_accounts").to_return(json_response("account_sub_accounts.json"))
25
+ account_sub_accounts = @client.list_sub_accounts(1)
26
+ account_sub_accounts.count.should == 1
27
+ account_sub_accounts.first['id'].should == 2
28
+ account_sub_accounts.first['name'].should == "Manually-Created Courses"
29
+ end
30
+
8
31
  it "returns a single account" do
9
32
  stub_get(@client, "/api/v1/accounts/1").to_return(json_response("single_account.json"))
10
33
  account = @client.account(1)
@@ -15,10 +38,57 @@ describe Bearcat::Client::Accounts do
15
38
  it "returns enrollment terms for an account" do
16
39
  stub_get(@client, "/api/v1/accounts/1/terms").to_return(json_response("enrollment_terms.json"))
17
40
  account = @client.terms(1)
18
- terms = account['enrollment_terms']
41
+ terms = account.members
19
42
  terms.count.should == 1
20
43
  terms.first['id'].should == 4
21
44
  terms.first['name'].should == 'Term 1'
22
45
  end
23
46
 
47
+ it "returns the roles for an account" do
48
+ stub_get(@client, "/api/v1/accounts/1/roles").to_return(json_response("account_roles.json"))
49
+ account = @client.account_roles(1)
50
+ roles = account.members
51
+ roles.count.should == 1
52
+ roles.first['id'].should == 1
53
+ roles.first['role'].should == 'AccountAdmin'
54
+ roles.first['permissions'].count.should == 4
55
+ roles.first['permissions']['manage_catalog']['enabled'].should == true
56
+ end
57
+
58
+ it 'returns courses for an account' do
59
+ stub_get(@client, "/api/v1/accounts/1/courses").to_return(json_response("account_courses.json"))
60
+ courses = @client.account_courses(1)
61
+ courses.count.should == 2
62
+ courses.first['id'].should == 1
63
+ courses.first['name'].should == 'Sub1 Course1'
64
+ end
65
+
66
+ it 'gets account grading_standards' do
67
+ stub_get(@client, "/api/v1/accounts/1/grading_standards").to_return(json_response("account_grading_standards.json"))
68
+ grading_standards = @client.account_grading_standards(1)
69
+ expect(grading_standards['id']).to eq 1
70
+ expect(grading_standards['title']).to eq 'account grading scheme'
71
+ end
72
+
73
+ it 'creates an account admin' do
74
+ stub_post(@client, "/api/v1/accounts/1/admins").to_return(json_response("account_admin_create.json"))
75
+ account_admin = @client.create_account_admin(1, {role_id:1, user_id: "sis_user_id:user1_sis_id"})
76
+ expect(account_admin['id']).to eq 99
77
+ expect(account_admin['role']).to eq 'AccountAdmin'
78
+ end
79
+
80
+ it 'deletes an account admin' do
81
+ stub_delete(@client, "/api/v1/accounts/1/admins/sis_user_id:user1_sis_id?role_id=1").to_return(json_response("account_admin_delete.json"))
82
+ account_admin = @client.delete_account_admin(1, "sis_user_id:user1_sis_id", {role_id:1})
83
+ expect(account_admin['id']).to eq 99
84
+ expect(account_admin['status']).to eq 'deleted'
85
+ end
86
+
87
+ it 'returns a list of sis_imports' do
88
+ stub_get(@client, "/api/v1/accounts/1/sis_imports").to_return(json_response("account_sis_imports.json"))
89
+ sis_imports = @client.account_sis_imports(1)['sis_imports']
90
+ expect(sis_imports.first['id']).to eq 30
91
+ expect(sis_imports.first['workflow_state']).to eq 'imported'
92
+ end
93
+
24
94
  end
@@ -0,0 +1,22 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::Analytics do
4
+ before do
5
+ @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
6
+ end
7
+
8
+ it 'returns page view data' do
9
+ stub_get(@client, "/api/v1/accounts/1/analytics/terms/1/activity").to_return(json_response("department_level_participation.json"))
10
+ result = @client.department_level_participation(1, 1)
11
+ result['by_date'].count.should == 3
12
+ result['by_category'].count.should == 13
13
+ result['by_category'].any? {|h| h['category'] == 'assignments'}.should be_truthy
14
+ end
15
+
16
+ it 'returns department level statistics' do
17
+ stub_get(@client, "/api/v1/accounts/1/analytics/terms/1/statistics").to_return(json_response("department_level_statistics.json"))
18
+ result = @client.department_level_statistics(1, 1)
19
+ result.count.should == 8
20
+ result['subaccounts'].should == 8
21
+ end
22
+ end
@@ -0,0 +1,47 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::AssignmentGroups do
4
+ before do
5
+ @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
6
+ end
7
+
8
+ it "returns all assignment groups for a course" do
9
+ stub_get(@client, "/api/v1/courses/1/assignment_groups").to_return(json_response("assignment_groups.json"))
10
+ assignment_groups = @client.list_assignment_groups(1)
11
+ assignment_groups.count.should == 2
12
+ assignment_groups.first["group_weight"].should == 500
13
+ assignment_groups.first["id"].should == 2
14
+ assignment_groups.first["name"].should == 'Quizzes'
15
+ end
16
+
17
+ it 'returns a single assignment_group' do
18
+ stub_get(@client, '/api/v1/courses/2/assignment_groups/1').to_return(json_response("assignment_group.json"))
19
+ assignment_group = @client.assignment_group(2, 1)
20
+ assignment_group["group_weight"].should == 500
21
+ assignment_group["id"].should == 2
22
+ assignment_group["name"].should == 'Quizzes'
23
+ end
24
+
25
+ it 'creates an assignment_group' do
26
+ params = {'name' => 'New Assignment Group'}
27
+ stub_post(@client, "/api/v1/courses/2/assignment_groups").with(body: params).to_return(json_response("assignment_group.json"))
28
+ new_assignment_group = @client.create_assignment_group(2, params)
29
+ expect(new_assignment_group['name']).to eq('Quizzes')
30
+ end
31
+
32
+ it 'updates an assignment_group' do
33
+ params = {'name' => 'Quizzes'}
34
+ stub_put(@client, "/api/v1/courses/2/assignment_groups/1").with(body: params)
35
+ .to_return(json_response("assignment_group.json"))
36
+ updated_assignment_group = @client.update_assignment_group(2, 1, params)
37
+ expect(updated_assignment_group['name']).to eq('Quizzes')
38
+ end
39
+
40
+ it 'deletes an assignment_group' do
41
+ params = {'id' => '1'}
42
+ stub_delete(@client, "/api/v1/courses/2/assignment_groups/2").to_return(json_response("assignment_group.json"))
43
+ deleted_assignment_group = @client.delete_assignment_group(2, 2)
44
+ deleted_assignment_group["id"].should == 2
45
+ end
46
+
47
+ end
@@ -14,6 +14,14 @@ describe Bearcat::Client::Assignments do
14
14
  assignments.first["due_at"].should == nil
15
15
  end
16
16
 
17
+ it "returns an individual assignment for a course" do
18
+ stub_get(@client, "/api/v1/courses/3/assignments/1").to_return(json_response("assignment.json"))
19
+ assignment = @client.assignment(3, 1)
20
+ assignment["assignment_group_id"].should == 53
21
+ assignment["id"].should == 1
22
+ assignment["due_at"].should == nil
23
+ end
24
+
17
25
  it "creates an assignment override for a section" do
18
26
  stub_post(@client, "/api/v1/courses/310/assignments/123/overrides")
19
27
  .with(:body => {"assignment_override"=>{"course_section_id"=>"74", "due_at"=>"2013-06-27T21:08:46Z"}})
@@ -28,6 +36,11 @@ describe Bearcat::Client::Assignments do
28
36
  override["course_section_id"].should == 74
29
37
  end
30
38
 
39
+ it "deletes assignment overrides" do
40
+ stub_delete(@client, "/api/v1/courses/3/assignments/1/overrides/2").to_return({})
41
+ @client.delete_assignment_override(3, 1, 2)
42
+ end
43
+
31
44
  it "creates a new assignment" do
32
45
  name = "new assignment"
33
46
  stub_post(@client, "/api/v1/courses/1/assignments").with(body: {"assignment" => {"name" => name}}).to_return(json_response("created_assignment.json"))
@@ -36,4 +49,34 @@ describe Bearcat::Client::Assignments do
36
49
  assignment["id"].should == 1
37
50
  end
38
51
 
52
+ it "deletes an assignment" do
53
+ stub_delete(@client, "/api/v1/courses/3/assignments/1").to_return(json_response("assignment.json"))
54
+ assignment = @client.delete_assignment(3, 1)
55
+ assignment["id"].should == 1
56
+ end
57
+
58
+ it "allows batch retrieval of all overrides in a course" do
59
+ stub_get(@client, "/api/v1/courses/3/assignments/overrides").to_return(json_response("assignment_section_override.json"))
60
+ @client.all_assignment_overrides(3)
61
+ end
62
+
63
+ it "allows batch creation of assignment overrides" do
64
+ stub_post(@client, "/api/v1/courses/310/assignments/overrides")
65
+ .with(:body => {"assignment_override"=>{"course_section_id"=>"74", "due_at"=>"2013-06-27T21:08:46Z"}})
66
+ .to_return(json_response("assignment_section_override.json"))
67
+ @client.batch_create_assignment_overrides(310, {
68
+ "assignment_override[course_section_id]" => 74,
69
+ "assignment_override[due_at]" => "2013-06-27T21:08:46Z"
70
+ })
71
+ end
72
+
73
+ it "allows batch updating of assignment overrides" do
74
+ stub_put(@client, "/api/v1/courses/310/assignments/overrides")
75
+ .with(:body => {"assignment_override"=>{"course_section_id"=>"74", "due_at"=>"2013-06-27T21:08:46Z"}})
76
+ .to_return(json_response("assignment_section_override.json"))
77
+ @client.batch_update_assignment_overrides(310, {
78
+ "assignment_override[course_section_id]" => 74,
79
+ "assignment_override[due_at]" => "2013-06-27T21:08:46Z"
80
+ })
81
+ end
39
82
  end
@@ -0,0 +1,43 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::BlueprintCourses do
4
+ before do
5
+ @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
6
+ end
7
+
8
+ it 'returns a list of blueprint subscriptions for the given course' do
9
+ stub_get(@client, "/api/v1/courses/1/blueprint_subscriptions").to_return(json_response("blueprint_subscriptions.json"))
10
+ subs = @client.blueprint_subscriptions(1)
11
+ expect(subs['id']).to eq 101
12
+ expect(subs['template_id']).to eq 1
13
+ expect(subs['blueprint_course']).to be_present
14
+ end
15
+
16
+ it 'returns a blueprint template for the given course' do
17
+ stub_get(@client, "/api/v1/courses/2/blueprint_templates/default").to_return(json_response("blueprint_template.json"))
18
+ template = @client.blueprint_template(2)
19
+ expect(template['id']).to eq 1
20
+ expect(template['course_id']).to eq 2
21
+ end
22
+
23
+ it 'updates assocations for a blueprint course' do
24
+ stub_put(@client, "/api/v1/courses/2/blueprint_templates/default/update_associations").to_return(json_response("blueprint_update_assocations_success.json"))
25
+ result = @client.blueprint_update_associations(2, 'default', course_ids_to_add: [123])
26
+ expect(result['success']).to eq true
27
+ end
28
+
29
+ it 'starts a migration for a blueprint course' do
30
+ stub_post(@client, "/api/v1/courses/2/blueprint_templates/default/migrations").to_return(json_response("blueprint_migration.json"))
31
+ migration = @client.start_blueprint_migration(2, 'default', {
32
+ comment: 'An optional comment to be included in the sync history.',
33
+ send_notification: false,
34
+ copy_settings: true
35
+ })
36
+ expect(migration['id']).to eq 1
37
+ expect(migration['template_id']).to eq 2
38
+ expect(migration['subscription_id']).to eq 101
39
+ expect(migration['user_id']).to eq 3
40
+ expect(migration['workflow_state']).to eq 'running'
41
+ end
42
+
43
+ end
@@ -13,8 +13,7 @@ describe Bearcat::Client::CanvasFiles do
13
13
  stub_request(:post, "https://upload-url.invalid/").
14
14
  to_return(status: 302, headers: {'Location' => 'https://confirm-upload.invalid/confirm?param=true'})
15
15
 
16
- stub_post(@client, "/confirm").
17
- with(:body => {"param" => ["true"]}).to_return(json_response('canvas_files', 'upload_success.json'))
16
+ stub_get(@client, '/confirm').with(query: { param: true }).to_return(json_response('canvas_files', 'upload_success.json'))
18
17
 
19
18
  response = @client.upload_file('my/upload/path', fixture('bearcat.jpg'))
20
19
  expect(response['id']).to eq 123
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+
3
+ describe Bearcat::Client::ContentExports do
4
+ before do
5
+ @client = Bearcat::Client.new(prefix: "http://canvas.instructure.com", token: "test_token")
6
+ end
7
+
8
+ describe 'create_course_export' do
9
+ it "creates a course export" do
10
+ stub_post(@client, "/api/v1/courses/3/content_exports").to_return(json_response("content_export.json"))
11
+ course = @client.create_course_export(3)
12
+ course['export_type'].should == 'common_cartridge'
13
+ course['attachment'].should == {"url" => "https://example.com/api/v1/attachments/789?download_frd=1&verifier=bG9sY2F0cyEh"}
14
+ course['progress_url'].should == "https://example.com/api/v1/progress/4"
15
+ end
16
+ end
17
+
18
+ describe 'create_group_export' do
19
+ it "creates a group export" do
20
+ stub_post(@client, "/api/v1/groups/3/content_exports").to_return(json_response("content_export.json"))
21
+ group = @client.create_group_export(3)
22
+ group['export_type'].should == 'common_cartridge'
23
+ group['attachment'].should == {"url" => "https://example.com/api/v1/attachments/789?download_frd=1&verifier=bG9sY2F0cyEh"}
24
+ group['progress_url'].should == "https://example.com/api/v1/progress/4"
25
+ end
26
+ end
27
+
28
+ describe 'create_user_export' do
29
+ it "creates a user export" do
30
+ stub_post(@client, "/api/v1/users/3/content_exports").to_return(json_response("content_export.json"))
31
+ user = @client.create_user_export(3)
32
+ user['export_type'].should == 'common_cartridge'
33
+ user['attachment'].should == {"url" => "https://example.com/api/v1/attachments/789?download_frd=1&verifier=bG9sY2F0cyEh"}
34
+ user['progress_url'].should == "https://example.com/api/v1/progress/4"
35
+ end
36
+ end
37
+
38
+ describe 'get_course_export' do
39
+ it "gets a course export" do
40
+ stub_get(@client, "/api/v1/courses/3/content_exports/1").to_return(json_response("content_export.json"))
41
+ course = @client.get_course_export(3, 1)
42
+ course['export_type'].should == 'common_cartridge'
43
+ course['attachment'].should == {"url" => "https://example.com/api/v1/attachments/789?download_frd=1&verifier=bG9sY2F0cyEh"}
44
+ course['progress_url'].should == "https://example.com/api/v1/progress/4"
45
+ end
46
+ end
47
+
48
+ describe 'get_group_export' do
49
+ it "gets a group export" do
50
+ stub_get(@client, "/api/v1/groups/3/content_exports/1").to_return(json_response("content_export.json"))
51
+ group = @client.get_group_export(3, 1)
52
+ group['export_type'].should == 'common_cartridge'
53
+ group['attachment'].should == {"url" => "https://example.com/api/v1/attachments/789?download_frd=1&verifier=bG9sY2F0cyEh"}
54
+ group['progress_url'].should == "https://example.com/api/v1/progress/4"
55
+ end
56
+ end
57
+
58
+ describe 'get_user_export' do
59
+ it "gets a user export" do
60
+ stub_get(@client, "/api/v1/users/3/content_exports/1").to_return(json_response("content_export.json"))
61
+ user = @client.get_user_export(3, 1)
62
+ user['export_type'].should == 'common_cartridge'
63
+ user['attachment'].should == {"url" => "https://example.com/api/v1/attachments/789?download_frd=1&verifier=bG9sY2F0cyEh"}
64
+ user['progress_url'].should == "https://example.com/api/v1/progress/4"
65
+ end
66
+ end
67
+
68
+ end