##// END OF EJS Templates
Adds tests for creating an issue with multiple uploads....
Jean-Philippe Lang -
r13409:9b082712a091
parent child
Show More
@@ -561,6 +561,63 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
561 561 assert_response :success
562 562 end
563 563
564 def test_create_issue_with_multiple_uploaded_files_as_xml
565 token1 = xml_upload('File content 1', credentials('jsmith'))
566 token2 = xml_upload('File content 2', credentials('jsmith'))
567
568 payload = <<-XML
569 <?xml version="1.0" encoding="UTF-8" ?>
570 <issue>
571 <project_id>1</project_id>
572 <tracker_id>1</tracker_id>
573 <subject>Issue with multiple attachments</subject>
574 <uploads type="array">
575 <upload>
576 <token>#{token1}</token>
577 <filename>test1.txt</filename>
578 </upload>
579 <upload>
580 <token>#{token2}</token>
581 <filename>test1.txt</filename>
582 </upload>
583 </uploads>
584 </issue>
585 XML
586
587 assert_difference 'Issue.count' do
588 post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith'))
589 assert_response :created
590 end
591 issue = Issue.order('id DESC').first
592 assert_equal 2, issue.attachments.count
593 end
594
595 def test_create_issue_with_multiple_uploaded_files_as_json
596 token1 = json_upload('File content 1', credentials('jsmith'))
597 token2 = json_upload('File content 2', credentials('jsmith'))
598
599 payload = <<-JSON
600 {
601 "issue": {
602 "project_id": "1",
603 "tracker_id": "1",
604 "subject": "Issue with multiple attachments",
605 "uploads": [
606 {"token": "#{token1}", "filename": "test1.txt"},
607 {"token": "#{token2}", "filename": "test2.txt"}
608 ]
609 }
610 }
611 JSON
612
613 assert_difference 'Issue.count' do
614 post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith'))
615 assert_response :created
616 end
617 issue = Issue.order('id DESC').first
618 assert_equal 2, issue.attachments.count
619 end
620
564 621 def test_update_issue_with_uploaded_file
565 622 set_tmp_attachments_directory
566 623 # upload the file
@@ -271,6 +271,45 module Redmine
271 271 def teardown
272 272 Setting.rest_api_enabled = '0'
273 273 end
274
275 # Uploads content using the XML API and returns the attachment token
276 def xml_upload(content, credentials)
277 upload('xml', content, credentials)
278 end
279
280 # Uploads content using the JSON API and returns the attachment token
281 def json_upload(content, credentials)
282 upload('json', content, credentials)
283 end
284
285 def upload(format, content, credentials)
286 set_tmp_attachments_directory
287 assert_difference 'Attachment.count' do
288 post "/uploads.#{format}", content, {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials)
289 assert_response :created
290 end
291 data = response_data
292 assert_kind_of Hash, data['upload']
293 token = data['upload']['token']
294 assert_not_nil token
295 token
296 end
297
298 # Parses the response body based on its content type
299 def response_data
300 unless response.content_type.to_s =~ /^application\/(.+)/
301 raise "Unexpected response type: #{response.content_type}"
302 end
303 format = $1
304 case format
305 when 'xml'
306 Hash.from_xml(response.body)
307 when 'json'
308 ActiveSupport::JSON.decode(response.body)
309 else
310 raise "Unknown response format: #{format}"
311 end
312 end
274 313 end
275 314
276 315 class Routing < Redmine::RoutingTest
General Comments 0
You need to be logged in to leave comments. Login now