mpog_software_plugin_myprofile_controller_test.rb
7.91 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
require File.dirname(__FILE__) + '/../../../../test/test_helper'
require File.dirname(__FILE__) + '/../helpers/software_test_helper'
require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
require(
File.dirname(__FILE__) +
'/../../controllers/software_communities_plugin_myprofile_controller'
)
class SoftwareCommunitiesPluginMyprofileController; def rescue_action(e) raise e end;
end
class SoftwareCommunitiesPluginMyprofileControllerTest < ActionController::TestCase
include SoftwareTestHelper
def setup
@controller = SoftwareCommunitiesPluginMyprofileController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@person = create_user('person').person
@offer = create_user('Angela Silva')
@offer_1 = create_user('Ana de Souza')
@offer_2 = create_user('Angelo Roberto')
LicenseInfo.create(
:version=>"CC-GPL-V2",
:link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
)
ProgrammingLanguage.create(:name =>"language")
DatabaseDescription.create(:name => "database")
OperatingSystemName.create(:name=>"Debian")
login_as(@person.user_login)
@environment = Environment.default
@environment.enable_plugin('SoftwareCommunitiesPlugin')
@environment.save!
end
attr_accessor :person, :offer
should 'Add offer to admin in new software' do
@hash_list = software_fields
@software = create_software @hash_list
@software.community.add_admin(@offer.person)
@software.save
assert_equal @offer.person.id, @software.community.admins.last.id
end
should 'search new offers while creating a new software' do
offer_token = "An"
post :search_offerers, :profile => person.identifier,:q => offer_token
response = JSON.parse(@response.body)
response.sort!{|a, b| a["name"] <=> b["name"]}
assert_equal "Ana de Souza",response[0]["name"]
assert_equal "Angela Silva",response[1]["name"]
assert_equal "Angelo Roberto",response[2]["name"]
end
should 'make search for Ang for offerer in software creation' do
offer_token = "Ang"
post :search_offerers, :profile => person.identifier,:q => offer_token
response = JSON.parse(@response.body)
response.sort!{|a, b| a["name"] <=> b["name"]}
assert_equal "Angela Silva",response[0]["name"]
assert_equal "Angelo Roberto",response[1]["name"]
end
should 'not find any offerer for software creation' do
offer_token = "Jos"
post :search_offerers, :profile => person.identifier,:q => offer_token
response = JSON.parse(@response.body)
assert response.count == 0
end
should 'create a new software with all fields filled in' do
fields = software_fields
@environment.add_admin(@person)
post(
:new_software,
:profile => @person.identifier,
:community => fields[1],
:license_info => fields[0],
:software_info => fields[2]
)
assert_equal SoftwareInfo.last.community.name, "Debian"
end
should 'edit a new software adding basic information' do
fields_software = software_fields
fields = software_edit_basic_fields
software = create_software fields_software
post(
:edit_software,
:profile => software.community.identifier,
:license => fields[1],
:software => fields[0],
:library => {},
:operating_system => {},
:language => {},
:database => {}
)
assert_equal SoftwareInfo.last.repository_link, "www.github.com/test"
end
should 'edit a new software adding specific information' do
fields_software = software_fields
fields = software_edit_specific_fields
software = create_software fields_software
post(
:edit_software,
:profile => software.community.identifier,
:library => fields[0],
:language => fields[1],
:database => fields[2],
:operating_system => fields[3],
:software => fields[4],
:license => fields[5]
)
assert_equal SoftwareInfo.last.acronym, "test"
end
should 'upgrade a generic software to a public software' do
fields_software = software_fields
fields = software_edit_specific_fields
fields[4]['public_software'] = true
software = create_software fields_software
post(
:edit_software,
:profile => software.community.identifier,
:library => fields[0],
:language => fields[1],
:database => fields[2],
:operating_system => fields[3],
:software => fields[4],
:license => fields[5]
)
assert_equal true, SoftwareInfo.last.public_software?
end
should "user edit its community institution" do
govPower = GovernmentalPower.create(:name=>"Some Gov Power")
govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
juridical_nature = JuridicalNature.create(:name => "Autarquia")
institution = InstitutionTestHelper.create_public_institution(
"Ministerio Publico da Uniao",
"MPU",
"BR",
"DF",
"Gama",
juridical_nature,
govPower,
govSphere,
"12.345.678/9012-45"
)
identifier = institution.community.identifier
fields = InstitutionTestHelper.generate_form_fields(
"institution new name",
"BR",
"DF",
"Gama",
"12.345.678/9012-45",
"PrivateInstitution"
)
post(
:edit_institution,
:profile=>institution.community.identifier,
:community=>fields[:community],
:institutions=>fields[:institutions]
)
institution = Community[identifier].institution
assert_not_equal "Ministerio Publico da Uniao", institution.community.name
end
should "not user edit its community institution with wrong values" do
govPower = GovernmentalPower.create(:name=>"Some Gov Power")
govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
juridical_nature = JuridicalNature.create(:name => "Autarquia")
institution = InstitutionTestHelper.create_public_institution(
"Ministerio Publico da Uniao",
"MPU",
"BR",
"DF",
"Gama",
juridical_nature,
govPower,
govSphere,
"12.345.678/9012-45"
)
identifier = institution.community.identifier
fields = InstitutionTestHelper.generate_form_fields(
"",
"BR",
"DF",
"Gama",
"6465465465",
"PrivateInstitution"
)
post(
:edit_institution,
:profile=>institution.community.identifier,
:community=>fields[:community],
:institutions=>fields[:institutions]
)
institution = Community[identifier].institution
assert_equal "Ministerio Publico da Uniao", institution.community.name
assert_equal "12.345.678/9012-45", institution.cnpj
end
should "create software_info with existing license_info" do
@environment.add_admin(@person)
post(
:new_software,
:community => {:name =>"New Software"},
:software_info => {:finality => "", :repository_link => ""},
:license_info =>{:id => LicenseInfo.last.id},
:profile => @person.identifier
)
assert_equal SoftwareInfo.last.license_info, LicenseInfo.last
end
should "create software_info with 'Another' license_info" do
license_another = LicenseInfo.create(:version => "Another", :link => "#")
@environment.add_admin(@person)
another_license_version = "Different License"
another_license_link = "http://diferent.link"
post(
:new_software,
:community => { :name =>"New Software" },
:software_info => { :finality => "", :repository_link => "" },
:license_info =>{ :id => license_another.id },
:license => { :version => another_license_version,
:link => another_license_link },
:profile => @person.identifier
)
assert_equal SoftwareInfo.last.license_info_id, license_another.id
assert_equal SoftwareInfo.last.license_info.id, nil
assert_equal SoftwareInfo.last.license_info.version, another_license_version
assert_equal SoftwareInfo.last.license_info.link, another_license_link
end
end