add tests for deploy envs

This commit is contained in:
Anton Chuchkalov 2014-11-26 16:45:33 +04:00
parent 81521ee52b
commit 0cb4fe9214
7 changed files with 110 additions and 12 deletions

View File

@ -64,12 +64,8 @@ class DevopsService < Sinatra::Base
begin begin
mongo.key provider.ssh_key, Key::SYSTEM mongo.key provider.ssh_key, Key::SYSTEM
rescue RecordNotFound => e rescue RecordNotFound => e
begin k = Key.new({"id" => provider.ssh_key, "path" => provider.certificate_path, "scope" => Key::SYSTEM})
k = Key.new({"id" => provider.ssh_key, "path" => provider.certificate_path, "scope" => Key::SYSTEM}) mongo.key_insert k
mongo.key_insert k
rescue InvalidRecord => e
puts "ERROR: an error occured during inserting #{provider.name} key"
end
end end
end end
end end

View File

@ -515,7 +515,7 @@ module Version2_0
private private
def create_roles project_id, envs, logger def create_roles project_id, envs, logger
all_roles = KnifeCommands.roles all_roles = KnifeCommands.roles
return "Can't get roles list" if all_roles.nil? return " Can't get roles list" if all_roles.nil?
roles = {:new => [], :error => [], :exist => []} roles = {:new => [], :error => [], :exist => []}
envs.each do |e| envs.each do |e|
role_name = KnifeCommands.role_name(project_id, e.identifier) role_name = KnifeCommands.role_name(project_id, e.identifier)
@ -543,11 +543,14 @@ module Version2_0
end end
def create_roles_response roles def create_roles_response roles
info = "" if roles.is_a?(String)
info += " Project roles '#{roles[:new].join("', '")}' have been automaticaly created" unless roles[:new].empty? roles
info += " Project roles '#{roles[:exist].join("', '")}' weren't created because they exist" unless roles[:exist].empty? else
info += " Project roles '#{roles[:error].join("', '")}' weren't created because of internal error" unless roles[:error].empty? info = ""
info info += " Project roles '#{roles[:new].join("', '")}' have been automaticaly created" unless roles[:new].empty?
info += " Project roles '#{roles[:exist].join("', '")}' weren't created because they exist" unless roles[:exist].empty?
info += " Project roles '#{roles[:error].join("', '")}' weren't created because of internal error" unless roles[:error].empty?
end
end end
end end
end end

View File

@ -65,6 +65,7 @@ templates = {
"templates/api_v2/10_create/10_image.feature.erb" => "features/api_v2/10_create/10_image.feature", "templates/api_v2/10_create/10_image.feature.erb" => "features/api_v2/10_create/10_image.feature",
"templates/api_v2/10_create/20_project.feature.erb" => "features/api_v2/10_create/20_project.feature", "templates/api_v2/10_create/20_project.feature.erb" => "features/api_v2/10_create/20_project.feature",
"templates/api_v2/10_create/30_script.feature.erb" => "features/api_v2/10_create/30_script.feature", "templates/api_v2/10_create/30_script.feature.erb" => "features/api_v2/10_create/30_script.feature",
"templates/api_v2/10_create/40_deploy_env.feature.erb" => "features/api_v2/10_create/40_deploy_env.feature",
"templates/api_v2/10_create/00_user.feature.erb" => "features/api_v2/10_create/00_user.feature", "templates/api_v2/10_create/00_user.feature.erb" => "features/api_v2/10_create/00_user.feature",
#update #update
@ -73,6 +74,7 @@ templates = {
#delete #delete
"templates/api_v2/90_delete/10_script.feature.erb" => "features/api_v2/90_delete/10_script.feature", "templates/api_v2/90_delete/10_script.feature.erb" => "features/api_v2/90_delete/10_script.feature",
"templates/api_v2/90_delete/20_deploy_env.feature.erb" => "features/api_v2/90_delete/20_deploy_env.feature",
"templates/api_v2/90_delete/80_project.feature.erb" => "features/api_v2/90_delete/80_project.feature", "templates/api_v2/90_delete/80_project.feature.erb" => "features/api_v2/90_delete/80_project.feature",
"templates/api_v2/90_delete/90_image.feature.erb" => "features/api_v2/90_delete/90_image.feature", "templates/api_v2/90_delete/90_image.feature.erb" => "features/api_v2/90_delete/90_image.feature",
"templates/api_v2/90_delete/99_filter.feature.erb" => "features/api_v2/90_delete/99_filter.feature", "templates/api_v2/90_delete/99_filter.feature.erb" => "features/api_v2/90_delete/99_filter.feature",

View File

@ -56,3 +56,25 @@ Feature: create project
} }
""" """
Then response should be '201' Then response should be '201'
@static
Scenario: Create project <%= @config["static"]["project"]["name"] %>
When I send POST '/v2.0/project' query with JSON body
"""
{
"deploy_envs": [
{
"identifier": "<%= @config["static"]["project"]["env"] %>",
"run_list": [],
"expires": null,
"provider": "static",
"users": [
"<%= @config["username"] %>"
]
}
],
"name": "<%= @config["static"]["project"]["name"] %>"
}
"""
Then response should be '201'

View File

@ -0,0 +1,25 @@
@project @deploy_env
Feature: Delete deploy env
@static
<% project_name = @config["static"]["project"]["name"] %>
Scenario: Delete deploy env for project <%= project_name %>
When I send PUT '/v2.0/project/<%= project_name %>' query with JSON body
"""
{
"deploy_envs": [
{
"identifier": "test",
"run_list": [],
"expires": null,
"provider": "static",
"users": [
"test"
]
}
],
"name": "<%= project_name %>"
}
"""
Then response should be '200'

View File

@ -0,0 +1,25 @@
@project @deploy_env
Feature: Delete deploy env
@static
<% project_name = @config["static"]["project"]["name"] %>
Scenario: Delete deploy env for project <%= project_name %>
When I send PUT '/v2.0/project/<%= project_name %>' query with JSON body
"""
{
"deploy_envs": [
{
"identifier": "test",
"run_list": [],
"expires": null,
"provider": "static",
"users": [
"test"
]
}
],
"name": "<%= project_name %>"
}
"""
Then response should be '200'

View File

@ -47,6 +47,31 @@ Feature: delete project
} }
""" """
@static
Scenario: Delete static project with user without privileges
When I send DELETE '/v2.0/project/<%= @config["static"]["project"]["name"] %>' query with user without privileges
Then response should be '401'
@static
Scenario: Delete static project without header 'Accept'
When I send DELETE '/v2.0/project/<%= @config["static"]["project"]["name"] %>' query without header 'Accept'
Then response should be '406'
@static
Scenario: Delete static project
When I send DELETE '/v2.0/project/<%= @config["static"]["project"]["name"] %>' query
Then response should be '200'
And the Content-Type header should include 'application/json'
And the JSON response should be an object
And response should be JSON object like:
"""
{
"message" : "Project '<%= @config["static"]["project"]["name"] %>' is deleted"
}
"""
Scenario: Delete unknown project Scenario: Delete unknown project
When I send DELETE '/v2.0/project/foo' query When I send DELETE '/v2.0/project/foo' query
Then response should be '404' Then response should be '404'