project_test.rb
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require "test_helper"
require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures"
class ProjectTest < ActiveSupport::TestCase
def setup
@hash = ProjectFixtures.project_hash
@project = ProjectFixtures.project
@project_content = ProjectFixtures.project_content
end
should 'get all project names' do
response_hash = {:project_name => [@project.name]}
Kalibro::Project.expects(:request).with("Project", :get_project_names).returns(response_hash)
assert_equal response_hash[:project_name], Kalibro::Project.all_names
end
should 'find project by name' do
request_body = {:project_name => @project.name}
response_hash = {:project => @hash}
Kalibro::Project.expects(:new).with(@hash).returns(@project)
Kalibro::Project.expects(:request).with("Project", :get_project, request_body).returns(response_hash)
assert_equal @project, Kalibro::Project.find_by_name(@project.name)
end
should 'raise error when project doesnt exist' do
request_body = {:project_name => @project.name}
Kalibro::Project.expects(:request).with("Project", :get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name))
assert_raise Exception do Kalibro::Project.find_by_name(@project.name) end
end
should 'return true when project is saved successfully' do
Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash})
assert @project.save
end
should 'return false when project is not saved successfully' do
Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}).raises(Exception.new)
assert !(@project.save)
end
should 'remove existent project from service' do
Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name})
@project.destroy
end
should 'initialize new project from hash' do
project = Kalibro::Project.new @hash
assert_equal @project.name, project.name
assert_equal @project.repository.type, project.repository.type
end
should 'convert project to hash' do
hash = @project.to_hash
assert_equal @hash[:name], hash[:name]
assert_equal @hash[:configuration_name], hash[:configuration_name]
assert_equal @hash[:repository], hash[:repository]
assert_equal @hash[:state], hash[:state]
end
should 'process project without days' do
Kalibro::Project.expects(:request).with('Kalibro', :process_project, {:project_name => @project.name})
@project.process_project
end
should 'process project with days' do
Kalibro::Project.expects(:request).with('Kalibro', :process_periodically, {:project_name => @project.name, :period_in_days => "1"})
@project.process_project "1"
end
should 'process period' do
Kalibro::Project.expects(:request).with('Kalibro', :get_process_period, {:project_name => @project.name}).returns({:period => "1"})
assert_equal "1", @project.process_period
end
should 'cancel periodic process' do
Kalibro::Project.expects(:request).with("Kalibro", :cancel_periodic_process, {:project_name => @project.name})
@project.cancel_periodic_process
end
end