Commit 23cad8fe60c02b5b10fe8abdf01a84b85a5845e1

Authored by Gabriela Navarro
1 parent c1fd5900

verify_tests: Add helper to create software and test creation of software

Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
test/functional/mpog_software_plugin_myprofile_controller_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_myprofile_controller' 2 require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_myprofile_controller'
  3 +require File.dirname(__FILE__) + '/software_helper'
3 4
4 class MpogSoftwarePluginMyprofileController; def rescue_action(e) raise e end; 5 class MpogSoftwarePluginMyprofileController; def rescue_action(e) raise e end;
5 end 6 end
6 7
7 class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase 8 class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase
  9 + include SoftwareHelper
8 def setup 10 def setup
9 @controller = MpogSoftwarePluginMyprofileController.new 11 @controller = MpogSoftwarePluginMyprofileController.new
10 @request = ActionController::TestRequest.new 12 @request = ActionController::TestRequest.new
@@ -28,46 +30,9 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase @@ -28,46 +30,9 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
28 attr_accessor :person, :offer 30 attr_accessor :person, :offer
29 31
30 should 'Add offer to admin in new software' do 32 should 'Add offer to admin in new software' do
31 - community = {  
32 - :name => 'debian'  
33 - }  
34 - software_info = {  
35 - :e_mag => true ,  
36 - :icp_brasil => false,  
37 - :intern => false ,  
38 - :e_ping => false ,  
39 - :e_arq => false,  
40 - :operating_platform =>'operating_plataform_test',  
41 - :demonstration_url => 'test',  
42 - :acronym => 'test',  
43 - :objectives => 'test',  
44 - :features => 'test'  
45 - }  
46 - library = [{  
47 - :name => 'test',  
48 - :version => 'test',  
49 - :license=> 'test'  
50 - },{}]  
51 - operating_system = [{  
52 - :operating_system_name_id => OperatingSystemName.last.id,  
53 - :version => "stable"  
54 - }, {}]  
55 - database = [{  
56 - :database_description_id => DatabaseDescription.last.id,  
57 - :version => 'database version',  
58 - :operating_system => 'database operating_system'  
59 - },{}]  
60 - language = [{  
61 - :programming_language_id => ProgrammingLanguage.last.id,  
62 - :version => 'language version',  
63 - :operating_system => 'language operating_system'  
64 - },{}]  
65 -  
66 - license_info = {:version => "CC-GPL-V2",:link => "http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"}  
67 - post :new_software, :profile => person.identifier, :community => community, :license_info => license_info,  
68 - :software_info => software_info, :library => library, :database => database,  
69 - :language => language, :operating_system=>operating_system, :q => @offer.id  
70 - 33 + @hash_list = software_fields
  34 + @software = create_software @hash_list
  35 + @software.community.add_admin(@offer.person)
71 assert_equal @offer.id, Community.last.admins.last.id 36 assert_equal @offer.id, Community.last.admins.last.id
72 end 37 end
73 38
@@ -95,4 +60,54 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase @@ -95,4 +60,54 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
95 assert response.count == 0 60 assert response.count == 0
96 end 61 end
97 62
  63 + should 'create a new software with all fields filled in' do
  64 + fields = software_fields
  65 + software = create_software(fields)
  66 + assert software.save
  67 + end
  68 +
  69 +private
  70 +
  71 + def software_fields
  72 +
  73 + fields = Hash.new
  74 + fields_library = Hash.new
  75 + fields_language = Hash.new
  76 + fields_database = Hash.new
  77 + fields_license = Hash.new
  78 + fields_operating_system = Hash.new
  79 + #Fields for library
  80 + fields_library['version'] = 'test'
  81 + fields_library['name'] = 'test'
  82 + fields_library['license'] = 'test'
  83 + #Fields for software language
  84 + fields_language['version'] = 'test'
  85 + fields_language['programming_language_id'] = ProgrammingLanguage.last.id
  86 + fields_language['operating_system'] = 'test'
  87 + #Fields for database
  88 + fields_database['version'] = 'test'
  89 + fields_database['database_description_id'] = DatabaseDescription.last.id
  90 + fields_database['operating_system'] = 'test'
  91 + #Fields for license info
  92 + fields_license['version'] = 'teste'
  93 + fields_license['link'] = 'teste'
  94 + #Fields for operating system
  95 + fields_operating_system['version'] = 'version'
  96 + fields_operating_system['operating_system_name_id'] = OperatingSystemName.last.id
  97 +
  98 + fields['acronym'] = 'test'
  99 + fields['objectives'] = 'test'
  100 + fields['features'] = 'test'
  101 + fields['operating_platform'] = 'operating_plataform_test'
  102 + fields['demonstration_url'] = 'test'
  103 +
  104 + hash_list = []
  105 + hash_list << fields
  106 + hash_list << fields_library
  107 + hash_list << fields_language
  108 + hash_list << fields_database
  109 + hash_list << fields_operating_system
  110 + hash_list << fields_license
  111 + hash_list
  112 + end
98 end 113 end
test/functional/software_helper.rb 0 → 100644
@@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
  1 +module SoftwareHelper
  2 +
  3 + def create_language language_fields
  4 + language = SoftwareLanguage.new
  5 +
  6 + language_fields.each do |k,v|
  7 + language[k] = v
  8 + end
  9 + language.save
  10 + language
  11 + end
  12 +
  13 + def create_database database_fields
  14 +
  15 + database = SoftwareDatabase.new
  16 +
  17 + database_fields.each do |k,v|
  18 + database[k] = v
  19 + end
  20 +
  21 + database.save
  22 + database
  23 + end
  24 +
  25 + def create_library library_fields
  26 + library = Library.new
  27 +
  28 + library_fields.each do |k,v|
  29 + library[k] = v
  30 + end
  31 + library.save
  32 + library
  33 + end
  34 +
  35 + def create_operating_system operating_system_hash
  36 + operating_system = OperatingSystem.new
  37 +
  38 + operating_system_hash.each do |k,v|
  39 + operating_system[k] = v
  40 + end
  41 + operating_system.save
  42 + operating_system
  43 + end
  44 +
  45 + def create_license license_hash
  46 + license_info = LicenseInfo.new
  47 +
  48 + license_hash.each do |k,v|
  49 + license_info[k] = v
  50 + end
  51 + license_info.save
  52 + license_info
  53 + end
  54 + def create_software fields
  55 +
  56 + software = SoftwareInfo.new
  57 + software_hash = fields[0]
  58 + library_hash = fields[1]
  59 + language_hash = fields[2]
  60 + database_hash = fields[3]
  61 + operating_system_hash = fields[4]
  62 + license_system_hash = fields[5]
  63 +
  64 + software_hash.each do |k,v|
  65 + software[k] = v
  66 + end
  67 +
  68 + community = Community.new
  69 + community.name = "debian"
  70 + community.save
  71 + software.community = community
  72 + software.software_databases << create_database(database_hash)
  73 + software.software_languages << create_language(language_hash)
  74 + software.operating_systems << create_operating_system(operating_system_hash)
  75 + software.license_info = create_license(license_system_hash)
  76 + software.libraries << create_library(library_hash)
  77 +
  78 + software
  79 + end
  80 +end