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.
- checksums.yaml +7 -0
- data/bearcat.gemspec +15 -5
- data/lib/badgrcat/api_array.rb +25 -0
- data/lib/badgrcat/client/methods.rb +54 -0
- data/lib/badgrcat/client.rb +53 -0
- data/lib/badgrcat/version.rb +3 -0
- data/lib/bearcat/api_array.rb +132 -65
- data/lib/bearcat/client/account_reports.rb +6 -14
- data/lib/bearcat/client/accounts.rb +18 -6
- data/lib/bearcat/client/analytics.rb +12 -0
- data/lib/bearcat/client/assignment_groups.rb +15 -0
- data/lib/bearcat/client/assignments.rb +17 -9
- data/lib/bearcat/client/blueprint_courses.rb +25 -0
- data/lib/bearcat/client/calendar_events.rb +9 -17
- data/lib/bearcat/client/canvas_files.rb +0 -2
- data/lib/bearcat/client/conferences.rb +3 -8
- data/lib/bearcat/client/content_exports.rb +39 -0
- data/lib/bearcat/client/content_migrations.rb +54 -0
- data/lib/bearcat/client/conversations.rb +3 -8
- data/lib/bearcat/client/courses.rb +25 -14
- data/lib/bearcat/client/custom_gradebook_columns.rb +21 -0
- data/lib/bearcat/client/discussions.rb +10 -4
- data/lib/bearcat/client/enrollments.rb +9 -25
- data/lib/bearcat/client/external_tools.rb +18 -0
- data/lib/bearcat/client/file_helper.rb +36 -30
- data/lib/bearcat/client/files.rb +9 -0
- data/lib/bearcat/client/folders.rb +24 -0
- data/lib/bearcat/client/graph_ql.rb +17 -0
- data/lib/bearcat/client/group_categories.rb +18 -0
- data/lib/bearcat/client/group_memberships.rb +14 -0
- data/lib/bearcat/client/groups.rb +10 -2
- data/lib/bearcat/client/learning_outcomes.rb +17 -0
- data/lib/bearcat/client/logins.rb +20 -0
- data/lib/bearcat/client/module_items.rb +18 -0
- data/lib/bearcat/client/modules.rb +12 -7
- data/lib/bearcat/client/o_auth2.rb +18 -9
- data/lib/bearcat/client/outcome_groups.rb +2 -4
- data/lib/bearcat/client/outcome_imports.rb +48 -0
- data/lib/bearcat/client/outcomes.rb +4 -7
- data/lib/bearcat/client/pages.rb +15 -0
- data/lib/bearcat/client/progresses.rb +9 -0
- data/lib/bearcat/client/quizzes.rb +13 -9
- data/lib/bearcat/client/reports.rb +37 -17
- data/lib/bearcat/client/roles.rb +15 -0
- data/lib/bearcat/client/rubric.rb +17 -0
- data/lib/bearcat/client/rubric_assessment.rb +13 -0
- data/lib/bearcat/client/rubric_association.rb +13 -0
- data/lib/bearcat/client/search.rb +9 -0
- data/lib/bearcat/client/sections.rb +10 -17
- data/lib/bearcat/client/sis_imports.rb +6 -12
- data/lib/bearcat/client/submissions.rb +53 -21
- data/lib/bearcat/client/tabs.rb +12 -0
- data/lib/bearcat/client/users.rb +32 -13
- data/lib/bearcat/client.rb +111 -45
- data/lib/bearcat/client_module.rb +103 -0
- data/lib/bearcat/rate_limiting/increment_bucket.lua +33 -0
- data/lib/bearcat/rate_limiting/redis_script.rb +164 -0
- data/lib/bearcat/rate_limiting.rb +69 -0
- data/lib/bearcat/redis_connection.rb +106 -0
- data/lib/bearcat/spec_helpers.rb +125 -0
- data/lib/bearcat/version.rb +1 -1
- data/lib/bearcat.rb +49 -0
- data/lib/catalogcat/api_array.rb +22 -0
- data/lib/catalogcat/client/catalogs.rb +21 -0
- data/lib/catalogcat/client/certificates.rb +17 -0
- data/lib/catalogcat/client/courses.rb +25 -0
- data/lib/catalogcat/client/email_domain_sets.rb +17 -0
- data/lib/catalogcat/client/enrollments.rb +25 -0
- data/lib/catalogcat/client/orders.rb +13 -0
- data/lib/catalogcat/client/user_registrations.rb +9 -0
- data/lib/catalogcat/client.rb +26 -0
- data/lib/catalogcat/version.rb +3 -0
- data/lib/catalogcat.rb +14 -0
- data/spec/bearcat/api_array_spec.rb +112 -0
- data/spec/bearcat/client/accounts_spec.rb +71 -1
- data/spec/bearcat/client/analytics_spec.rb +22 -0
- data/spec/bearcat/client/assignment_groups_spec.rb +47 -0
- data/spec/bearcat/client/assignments_spec.rb +43 -0
- data/spec/bearcat/client/blueprint_courses_spec.rb +43 -0
- data/spec/bearcat/client/canvas_files_spec.rb +1 -2
- data/spec/bearcat/client/content_exports_spec.rb +68 -0
- data/spec/bearcat/client/content_migrations_spec.rb +94 -0
- data/spec/bearcat/client/courses_spec.rb +81 -2
- data/spec/bearcat/client/custom_gradebook_columns_spec.rb +66 -0
- data/spec/bearcat/client/discussions_spec.rb +73 -0
- data/spec/bearcat/client/enrollments_spec.rb +10 -0
- data/spec/bearcat/client/external_tools_spec.rb +106 -0
- data/spec/bearcat/client/files_spec.rb +15 -0
- data/spec/bearcat/client/folders_spec.rb +18 -0
- data/spec/bearcat/client/graph_ql_spec.rb +35 -0
- data/spec/bearcat/client/group_categories_spec.rb +45 -0
- data/spec/bearcat/client/group_membership_spec.rb +14 -0
- data/spec/bearcat/client/group_memberships_spec.rb +36 -0
- data/spec/bearcat/client/groups_spec.rb +46 -0
- data/spec/bearcat/client/learning_outcomes_spec.rb +25 -0
- data/spec/bearcat/client/module_items_spec.rb +60 -0
- data/spec/bearcat/client/modules_spec.rb +38 -1
- data/spec/bearcat/client/o_auth2_spec.rb +3 -3
- data/spec/bearcat/client/pages_spec.rb +17 -0
- data/spec/bearcat/client/quizzes_spec.rb +41 -4
- data/spec/bearcat/client/reports_spec.rb +40 -1
- data/spec/bearcat/client/roles_spec.rb +24 -0
- data/spec/bearcat/client/rubric_assessment_spec.rb +47 -0
- data/spec/bearcat/client/rubric_association_spec.rb +39 -0
- data/spec/bearcat/client/rubric_spec.rb +45 -0
- data/spec/bearcat/client/search_spec.rb +16 -0
- data/spec/bearcat/client/sections_spec.rb +12 -0
- data/spec/bearcat/client/submissions_spec.rb +47 -2
- data/spec/bearcat/client/users_spec.rb +43 -0
- data/spec/bearcat/client_spec.rb +1 -4
- data/spec/bearcat/rate_limiting_spec.rb +62 -0
- data/spec/bearcat/stub_bearcat_spec.rb +15 -0
- data/spec/fixtures/access_token.json +3 -0
- data/spec/fixtures/account_admin_create.json +14 -0
- data/spec/fixtures/account_admin_delete.json +15 -0
- data/spec/fixtures/account_admins.json +54 -0
- data/spec/fixtures/account_courses.json +48 -0
- data/spec/fixtures/account_grading_standards.json +20 -0
- data/spec/fixtures/account_groups.json +42 -0
- data/spec/fixtures/account_role.json +34 -0
- data/spec/fixtures/account_roles.json +35 -0
- data/spec/fixtures/account_sis_imports.json +39 -0
- data/spec/fixtures/account_sub_accounts.json +17 -0
- data/spec/fixtures/accounts.json +13 -0
- data/spec/fixtures/assignment.json +32 -0
- data/spec/fixtures/assignment_group.json +7 -0
- data/spec/fixtures/assignment_groups.json +16 -0
- data/spec/fixtures/blueprint_migration.json +12 -0
- data/spec/fixtures/blueprint_subscriptions.json +5 -0
- data/spec/fixtures/blueprint_template.json +7 -0
- data/spec/fixtures/blueprint_update_assocations_success.json +3 -0
- data/spec/fixtures/communication_channels.json +10 -0
- data/spec/fixtures/content_export.json +9 -0
- data/spec/fixtures/content_migration_files/content_migration.json +13 -0
- data/spec/fixtures/course_copy.json +18 -0
- data/spec/fixtures/course_files.json +38 -0
- data/spec/fixtures/course_folder.json +21 -0
- data/spec/fixtures/course_folders.json +44 -0
- data/spec/fixtures/course_grading_standards.json +20 -0
- data/spec/fixtures/course_settings.json +33 -0
- data/spec/fixtures/create_course_discussion.json +44 -0
- data/spec/fixtures/created_group.json +37 -0
- data/spec/fixtures/created_group_category.json +15 -0
- data/spec/fixtures/created_group_membership.json +8 -0
- data/spec/fixtures/created_module.json +13 -0
- data/spec/fixtures/custom_gradebook_columns/column_data.json +4 -0
- data/spec/fixtures/custom_gradebook_columns/custom_gradebook_column.json +7 -0
- data/spec/fixtures/custom_gradebook_columns/custom_gradebook_columns.json +16 -0
- data/spec/fixtures/custom_gradebook_columns/gradebook_column_progress.json +14 -0
- data/spec/fixtures/dashboard.json +6 -0
- data/spec/fixtures/delete_course.json +3 -0
- data/spec/fixtures/delete_group_category.json +3 -0
- data/spec/fixtures/deleted_group.json +37 -0
- data/spec/fixtures/department_level_participation.json +73 -0
- data/spec/fixtures/department_level_statistics.json +10 -0
- data/spec/fixtures/discussion_entries.json +21 -0
- data/spec/fixtures/discussion_entry_replies.json +21 -0
- data/spec/fixtures/discussion_topic.json +49 -0
- data/spec/fixtures/discussion_topics.json +51 -0
- data/spec/fixtures/edited_group.json +129 -0
- data/spec/fixtures/edited_group_category.json +15 -0
- data/spec/fixtures/enrollment_terms.json +1 -1
- data/spec/fixtures/external_tool.json +55 -0
- data/spec/fixtures/external_tools.json +57 -0
- data/spec/fixtures/file.csv +5 -0
- data/spec/fixtures/gradebook_history.json +52 -0
- data/spec/fixtures/graph_ql_scores.json +33 -0
- data/spec/fixtures/group.json +15 -0
- data/spec/fixtures/group_categories.json +28 -0
- data/spec/fixtures/group_category.json +13 -0
- data/spec/fixtures/group_category_groups.json +20 -0
- data/spec/fixtures/group_membership.json +7 -0
- data/spec/fixtures/learning_outcome.json +32 -0
- data/spec/fixtures/merge_user.json +8 -0
- data/spec/fixtures/module.json +15 -0
- data/spec/fixtures/module_item.json +15 -0
- data/spec/fixtures/module_items.json +47 -0
- data/spec/fixtures/ok.json +3 -0
- data/spec/fixtures/outcome_result.json +13 -0
- data/spec/fixtures/pages.json +40 -0
- data/spec/fixtures/progress.json +13 -0
- data/spec/fixtures/quizzes/course_quiz_questions.json +59 -0
- data/spec/fixtures/quizzes/quiz_assignment_override.json +31 -0
- data/spec/fixtures/reactivate_enrollment.json +20 -0
- data/spec/fixtures/rubric.json +13 -0
- data/spec/fixtures/rubric_assessment.json +32 -0
- data/spec/fixtures/rubric_association.json +13 -0
- data/spec/fixtures/search_find_recipients.json +10 -0
- data/spec/fixtures/update_section.json +1 -1
- data/spec/fixtures/user_details.json +16 -0
- data/spec/fixtures/user_logins.json +9 -0
- data/spec/helper.rb +2 -0
- 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,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
|
data/lib/catalogcat.rb
ADDED
@@ -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
|
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
|
-
|
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
|