1515# You should have received a copy of the GNU Affero General Public License along
1616# with this program. If not, see <http://www.gnu.org/licenses/>.
1717#
18+ module LtiSpecHelper
19+ def create_tool_proxy ( opts = { } )
1820
19- def create_tool_proxy ( opts = { } )
20- default_opts = {
21- context : account ,
22- shared_secret : 'shared_secret' ,
23- guid : SecureRandom . uuid ,
24- product_version : '1.0beta' ,
25- lti_version : 'LTI-2p0' ,
26- product_family : find_or_create_product_family ,
27- workflow_state : 'active' ,
28- raw_data : 'some raw data' ,
29- name : ( 0 ...8 ) . map { ( 65 + rand ( 26 ) ) . chr } . join ,
30- }
31- Lti ::ToolProxy . create! ( default_opts . merge ( opts ) )
32- end
21+ default_opts = {
22+ shared_secret : 'shared_secret' ,
23+ guid : SecureRandom . uuid ,
24+ product_version : '1.0beta' ,
25+ lti_version : 'LTI-2p0' ,
26+ product_family : find_or_create_product_family ,
27+ workflow_state : 'active' ,
28+ raw_data : 'some raw data' ,
29+ name : ( 0 ...8 ) . map { ( 65 + rand ( 26 ) ) . chr } . join ,
30+ }
31+ combined_opts = default_opts . merge ( opts )
32+ combined_opts [ :context ] = Account . create! ( name : 'Test Account' ) unless combined_opts . has_key? ( :context )
33+ combined_opts [ :product_family ] = find_or_create_product_family ( combined_opts [ :context ] ) unless combined_opts . has_key? ( :product_family )
34+ Lti ::ToolProxy . create! ( combined_opts )
35+ end
3336
34- def find_or_create_product_family ( opts = { } )
35- default_opts = { vendor_code : '123' , product_code : 'abc' , vendor_name : 'acme' , root_account_id : account . id }
36- Lti ::ProductFamily . where ( default_opts . merge ( opts ) ) . first_or_create
37- end
37+ def find_or_create_product_family ( opts = { } )
38+ default_opts = { vendor_code : '123' , product_code : 'abc' , vendor_name : 'acme' }
39+ default_opts [ :root_account_id ] = Account . create! ( name : 'Test Account' ) unless opts . has_key? ( :root_account_id )
40+ Lti ::ProductFamily . where ( default_opts . merge ( opts ) ) . first_or_create
41+ end
3842
39- def create_resource_handler ( tool_proxy , opts = { } )
40- default_opts = { resource_type_code : 'code' , name : ( 0 ...8 ) . map { ( 65 + rand ( 26 ) ) . chr } . join , tool_proxy : tool_proxy }
41- Lti ::ResourceHandler . create ( default_opts . merge ( opts ) )
42- end
43+ def create_resource_handler ( tool_proxy , opts = { } )
44+ default_opts = { resource_type_code : 'code' , name : ( 0 ...8 ) . map { ( 65 + rand ( 26 ) ) . chr } . join , tool_proxy : tool_proxy }
45+ Lti ::ResourceHandler . create ( default_opts . merge ( opts ) )
46+ end
4347
44- def create_message_handler ( resource_handler , opts = { } )
45- default_ops = { message_type : 'basic-lti-launch-request' , launch_path : 'https://samplelaunch/blti' , resource_handler : resource_handler }
46- Lti ::MessageHandler . create ( default_ops . merge ( opts ) )
47- end
48+ def create_message_handler ( resource_handler , opts = { } )
49+ default_ops = {
50+ message_type : 'basic-lti-launch-request' ,
51+ launch_path : 'https://samplelaunch/blti' ,
52+ resource_handler : resource_handler
53+ }
54+ Lti ::MessageHandler . create ( default_ops . merge ( opts ) )
55+ end
4856
49- def new_valid_external_tool ( context , resource_selection = false )
50- tool = context . context_external_tools . new ( :name => ( 0 ...8 ) . map { ( 65 + rand ( 26 ) ) . chr } . join ,
51- :consumer_key => "key" ,
52- :shared_secret => "secret" )
53- tool . url = "http://www.example.com/basic_lti"
54- tool . resource_selection = { :url => "http://example.com/selection_test" , :selection_width => 400 , :selection_height => 400 } if resource_selection
55- tool . save!
56- tool
57+ def new_valid_external_tool ( context , resource_selection = false )
58+ tool = context . context_external_tools . new ( :name => ( 0 ...8 ) . map { ( 65 + rand ( 26 ) ) . chr } . join ,
59+ :consumer_key => "key" ,
60+ :shared_secret => "secret" )
61+ tool . url = "http://www.example.com/basic_lti"
62+ tool . resource_selection = {
63+ :url => "http://example.com/selection_test" ,
64+ :selection_width => 400 ,
65+ :selection_height => 400
66+ } if resource_selection
67+ tool . save!
68+ tool
69+ end
5770end
0 commit comments