2011-05-31 23:07:20 +02:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2007-03-30 04:36:52 +00:00
|
|
|
|
|
|
|
|
class ProjectXmlApiTest < ActionController::IntegrationTest
|
|
|
|
|
@@project_name = "My New Project"
|
2012-04-27 14:22:16 +02:00
|
|
|
@@valid_postdata = "<project><name>#{@@project_name}</name></project>"
|
2011-10-06 17:32:39 +02:00
|
|
|
|
|
|
|
|
def test_retrieve_project
|
2012-04-27 14:22:16 +02:00
|
|
|
authenticated_get_xml "/projects/1.xml", users(:admin_user).login, 'abracadabra', {}
|
2011-10-06 17:32:39 +02:00
|
|
|
assert_tag :tag => "project"
|
|
|
|
|
assert_tag :tag => "project", :child => {:tag => "not_done" }
|
|
|
|
|
assert_tag :tag => "project", :child => {:tag => "deferred" }
|
|
|
|
|
assert_tag :tag => "project", :child => {:tag => "pending" }
|
|
|
|
|
assert_tag :tag => "project", :child => {:tag => "done" }
|
|
|
|
|
assert_response 200
|
|
|
|
|
end
|
2009-12-08 12:36:00 -05:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def test_fails_with_invalid_xml_format
|
2008-11-29 12:00:06 -05:00
|
|
|
#Fails too hard for test to catch
|
|
|
|
|
# authenticated_post_xml_to_project_create "<foo></bar>"
|
|
|
|
|
# assert_equal 500, @integration_session.status
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_fails_with_invalid_xml_format2
|
|
|
|
|
authenticated_post_xml_to_project_create "<request><project></project></request>"
|
2012-04-27 14:22:16 +02:00
|
|
|
assert_responses_with_error 'Name project must have a name'
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_xml_simple_param_parsing
|
|
|
|
|
authenticated_post_xml_to_project_create
|
2012-04-27 14:22:16 +02:00
|
|
|
assert @controller.params.has_key?(:project)
|
|
|
|
|
assert @controller.params[:project].has_key?(:name)
|
|
|
|
|
assert_equal @@project_name, @controller.params[:project][:name]
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2012-04-27 14:22:16 +02:00
|
|
|
def test_fails_with_401_if_not_authorized_user
|
2011-10-06 21:13:31 +02:00
|
|
|
authenticated_post_xml_to_project_create @@valid_postdata, 'nobody', 'nohow'
|
|
|
|
|
assert_response 401
|
|
|
|
|
end
|
|
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def test_fails_with_too_long_name
|
2012-04-27 14:22:16 +02:00
|
|
|
invalid_with_long_name_postdata = "<project><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></project>"
|
2007-03-30 04:36:52 +00:00
|
|
|
authenticated_post_xml_to_project_create invalid_with_long_name_postdata
|
2012-04-27 14:22:16 +02:00
|
|
|
assert_responses_with_error 'Name context name must be less than 256 characters'
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2007-04-06 03:30:20 +00:00
|
|
|
def test_fails_with_comma_in_name
|
2012-04-27 14:22:16 +02:00
|
|
|
authenticated_post_xml_to_project_create "<project><name>foo,bar</name></project>"
|
2011-09-01 21:05:19 -05:00
|
|
|
assert_response :created
|
2013-02-27 11:50:49 +01:00
|
|
|
project1 = Project.where(:name => "foo,bar").first
|
2011-09-01 21:05:19 -05:00
|
|
|
assert_not_nil project1, "expected project 'foo,bar' to be created"
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_creates_new_project
|
2009-12-07 18:41:23 -05:00
|
|
|
assert_difference 'Project.count' do
|
2007-12-04 06:24:23 +00:00
|
|
|
authenticated_post_xml_to_project_create
|
|
|
|
|
assert_response :created
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
2013-02-27 11:50:49 +01:00
|
|
|
project1 = Project.where(:name => @@project_name).first
|
2007-03-30 04:36:52 +00:00
|
|
|
assert_not_nil project1, "expected project '#{@@project_name}' to be created"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def authenticated_post_xml_to_project_create(postdata = @@valid_postdata, user = users(:other_user).login, password = 'sesame')
|
2012-04-27 14:22:16 +02:00
|
|
|
authenticated_post_xml "/projects.xml", user, password, postdata
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def assert_404_invalid_xml
|
2012-04-27 14:22:16 +02:00
|
|
|
assert_response_and_body 404, "Expected post format is valid xml like so: <project><name>project name</name></project>."
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2009-12-07 18:41:23 -05:00
|
|
|
end
|