Commit e80430110ac3d8d72118e856b3578f59c7a6e9f5

Authored by Gabriela Navarro
1 parent 23cad8fe
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Add tests and helper for create new software.

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Signed-off-by: Parley Martins <parley@outlook.com>
test/functional/mpog_software_plugin_myprofile_controller_test.rb
1 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 2 require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_myprofile_controller'
3   -require File.dirname(__FILE__) + '/software_helper'
  3 +require File.dirname(__FILE__) + '/software_test_helper'
4 4  
5 5 class MpogSoftwarePluginMyprofileController; def rescue_action(e) raise e end;
6 6 end
7 7  
8 8 class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase
9   - include SoftwareHelper
  9 + include SoftwareTestHelper
10 10 def setup
11 11 @controller = MpogSoftwarePluginMyprofileController.new
12 12 @request = ActionController::TestRequest.new
... ... @@ -22,9 +22,9 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
22 22 OperatingSystemName.create(:name=>"Debian")
23 23  
24 24 login_as(@person.user.login)
25   - e = Environment.default
26   - e.enable_plugin('MpogSoftwarePlugin')
27   - e.save!
  25 + @e = Environment.default
  26 + @e.enable_plugin('MpogSoftwarePlugin')
  27 + @e.save!
28 28 end
29 29  
30 30 attr_accessor :person, :offer
... ... @@ -32,8 +32,9 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
32 32 should 'Add offer to admin in new software' do
33 33 @hash_list = software_fields
34 34 @software = create_software @hash_list
35   - @software.community.add_admin(@offer.person)
36   - assert_equal @offer.id, Community.last.admins.last.id
  35 + @software.community.add_admin(@offer.person)
  36 + @software.save
  37 + assert_equal @offer.id, @software.community.admins.last.id
37 38 end
38 39  
39 40 should 'search new offers while creating a new software' do
... ... @@ -62,52 +63,12 @@ class MpogSoftwarePluginMyprofileControllerTest &lt; ActionController::TestCase
62 63  
63 64 should 'create a new software with all fields filled in' do
64 65 fields = software_fields
65   - software = create_software(fields)
66   - assert software.save
67   - end
68   -
69   -private
70   -
71   - def software_fields
72 66  
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
  67 + post :new_software, :profile => person.identifier, :community => fields[6], :license_info => fields[5],
  68 + :software_info => fields[0], :library => fields[1], :database => fields[3],
  69 + :language => fields[2], :operating_system=> fields[4]
  70 + assert @response.success?
  71 + end
97 72  
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 73  
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
113 74 end
... ...
test/functional/software_helper.rb
... ... @@ -1,80 +0,0 @@
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
test/functional/software_test_helper.rb 0 → 100644