Commit 59b3e45831b0b211531c9be0f7aa0a7e17bd44cf
Committed by
Paulo Meireles
1 parent
af361266
Exists in
master
and in
23 other branches
[Mezuro] Fixed Fixture and writing test for project
Showing
4 changed files
with
66 additions
and
78 deletions
Show diff stats
plugins/mezuro/test/fixtures/project_fixtures.rb
| ... | ... | @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/repository_fixtures' |
| 3 | 3 | class ProjectFixtures |
| 4 | 4 | |
| 5 | 5 | def self.qt_calculator |
| 6 | - project = Kalibro::Entities::Project.new | |
| 6 | + project = Kalibro::Project.new | |
| 7 | 7 | project.name = 'Qt-Calculator' |
| 8 | 8 | project.license = 'GPL' |
| 9 | 9 | project.description = 'Calculator for Qt' | ... | ... |
plugins/mezuro/test/unit/kalibro/client/project_client_test.rb
| ... | ... | @@ -1,57 +0,0 @@ |
| 1 | -require "test_helper" | |
| 2 | - | |
| 3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | |
| 4 | - | |
| 5 | -class ProjectClientTest < ActiveSupport::TestCase | |
| 6 | - | |
| 7 | - def setup | |
| 8 | - @port = mock | |
| 9 | - Kalibro::Client::Port.expects(:new).with('Project').returns(@port) | |
| 10 | - @project = ProjectFixtures.qt_calculator | |
| 11 | - end | |
| 12 | - | |
| 13 | - should 'get project by name' do | |
| 14 | - request_body = {:project_name => @project.name} | |
| 15 | - response_hash = {:project => @project.to_hash} | |
| 16 | - @port.expects(:request).with(:get_project, request_body).returns(response_hash) | |
| 17 | - assert_equal @project, Kalibro::Client::ProjectClient.project(@project.name) | |
| 18 | - end | |
| 19 | - | |
| 20 | - should 'raise error when project doesnt exist' do | |
| 21 | - request_body = {:project_name => @project.name} | |
| 22 | - @port.expects(:request).with(:get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) | |
| 23 | - assert_nil Kalibro::Client::ProjectClient.project(@project.name) | |
| 24 | - end | |
| 25 | - | |
| 26 | - should 'save project' do | |
| 27 | - create_project_content_mock | |
| 28 | - @project.state = nil | |
| 29 | - @port.expects(:request).with(:save_project, {:project => @project.to_hash}) | |
| 30 | - Kalibro::Client::ProjectClient.save(@project_content) | |
| 31 | - end | |
| 32 | - | |
| 33 | - should 'remove existent project from service' do | |
| 34 | - @port.expects(:request).with(:get_project_names).returns({:project_name => @project.name}) | |
| 35 | - @port.expects(:request).with(:remove_project, {:project_name => @project.name}) | |
| 36 | - Kalibro::Client::ProjectClient.remove(@project.name) | |
| 37 | - end | |
| 38 | - | |
| 39 | - should 'not try to remove inexistent project from service' do | |
| 40 | - @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'}) | |
| 41 | - @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never | |
| 42 | - Kalibro::Client::ProjectClient.remove(@project.name) | |
| 43 | - end | |
| 44 | - | |
| 45 | - private | |
| 46 | - | |
| 47 | - def create_project_content_mock | |
| 48 | - @project_content = mock | |
| 49 | - @project_content.expects(:name).returns(@project.name) | |
| 50 | - @project_content.expects(:license).returns(@project.license) | |
| 51 | - @project_content.expects(:description).returns(@project.description) | |
| 52 | - @project_content.expects(:repository_type).returns(@project.repository.type) | |
| 53 | - @project_content.expects(:repository_url).returns(@project.repository.address) | |
| 54 | - @project_content.expects(:configuration_name).returns(@project.configuration_name) | |
| 55 | - end | |
| 56 | - | |
| 57 | -end |
plugins/mezuro/test/unit/kalibro/entities/project_test.rb
| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | -require "test_helper" | |
| 2 | - | |
| 3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | |
| 4 | - | |
| 5 | -class ProjectTest < ActiveSupport::TestCase | |
| 6 | - | |
| 7 | - def setup | |
| 8 | - @hash = ProjectFixtures.qt_calculator_hash | |
| 9 | - @project = ProjectFixtures.qt_calculator | |
| 10 | - end | |
| 11 | - | |
| 12 | - should 'create project from hash' do | |
| 13 | - assert_equal @project, Kalibro::Entities::Project.from_hash(@hash) | |
| 14 | - end | |
| 15 | - | |
| 16 | - should 'convert project to hash' do | |
| 17 | - assert_equal @hash, @project.to_hash | |
| 18 | - end | |
| 19 | - | |
| 20 | -end | |
| 21 | 0 | \ No newline at end of file |
| ... | ... | @@ -0,0 +1,65 @@ |
| 1 | +require "test_helper" | |
| 2 | + | |
| 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | |
| 4 | + | |
| 5 | +class ProjectTest < ActiveSupport::TestCase | |
| 6 | + | |
| 7 | + def setup | |
| 8 | + @hash = ProjectFixtures.qt_calculator_hash | |
| 9 | + @project = ProjectFixtures.qt_calculator | |
| 10 | + end | |
| 11 | + | |
| 12 | + should 'get project by name' do | |
| 13 | + request_body = {:project_name => @project.name} | |
| 14 | + response_hash = {:project => @hash} | |
| 15 | + Kalibro::Project.expects(:request).with(:get_project, request_body).returns(response_hash) | |
| 16 | + assert_equal @project, Kalibro::Project.find_by_name(@project.name) | |
| 17 | + end | |
| 18 | + | |
| 19 | +=begin | |
| 20 | + should 'raise error when project doesnt exist' do | |
| 21 | + request_body = {:project_name => @project.name} | |
| 22 | + @port.expects(:request).with(:get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) | |
| 23 | + assert_nil Kalibro::Client::ProjectClient.project(@project.name) | |
| 24 | + end | |
| 25 | + | |
| 26 | + should 'save project' do | |
| 27 | + create_project_content_mock | |
| 28 | + @project.state = nil | |
| 29 | + @port.expects(:request).with(:save_project, {:project => @project.to_hash}) | |
| 30 | + Kalibro::Client::ProjectClient.save(@project_content) | |
| 31 | + end | |
| 32 | + | |
| 33 | + should 'remove existent project from service' do | |
| 34 | + @port.expects(:request).with(:get_project_names).returns({:project_name => @project.name}) | |
| 35 | + @port.expects(:request).with(:remove_project, {:project_name => @project.name}) | |
| 36 | + Kalibro::Client::ProjectClient.remove(@project.name) | |
| 37 | + end | |
| 38 | + | |
| 39 | + should 'not try to remove inexistent project from service' do | |
| 40 | + @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'}) | |
| 41 | + @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never | |
| 42 | + Kalibro::Client::ProjectClient.remove(@project.name) | |
| 43 | + end | |
| 44 | + | |
| 45 | + private | |
| 46 | + | |
| 47 | + def create_project_content_mock | |
| 48 | + @project_content = mock | |
| 49 | + @project_content.expects(:name).returns(@project.name) | |
| 50 | + @project_content.expects(:license).returns(@project.license) | |
| 51 | + @project_content.expects(:description).returns(@project.description) | |
| 52 | + @project_content.expects(:repository_type).returns(@project.repository.type) | |
| 53 | + @project_content.expects(:repository_url).returns(@project.repository.address) | |
| 54 | + @project_content.expects(:configuration_name).returns(@project.configuration_name) | |
| 55 | + end | |
| 56 | + | |
| 57 | + should 'create project from hash' do | |
| 58 | + assert_equal @project, Kalibro::Project.new(@hash) | |
| 59 | + end | |
| 60 | + | |
| 61 | + should 'convert project to hash' do | |
| 62 | + assert_equal @hash, @project.to_hash | |
| 63 | + end | |
| 64 | +=end | |
| 65 | +end | ... | ... |