gooddata 0.6.11 → 0.6.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.travis.yml +5 -0
  4. data/CHANGELOG.md +34 -1
  5. data/CLI.md +1 -1
  6. data/authors.sh +4 -0
  7. data/lib/gooddata.rb +1 -1
  8. data/lib/gooddata/cli/commands/api_cmd.rb +0 -2
  9. data/lib/gooddata/cli/commands/auth_cmd.rb +0 -3
  10. data/lib/gooddata/cli/commands/console_cmd.rb +1 -2
  11. data/lib/gooddata/cli/commands/domain_cmd.rb +0 -2
  12. data/lib/gooddata/cli/commands/process_cmd.rb +0 -2
  13. data/lib/gooddata/cli/commands/project_cmd.rb +0 -2
  14. data/lib/gooddata/cli/commands/projects_cmd.rb +0 -2
  15. data/lib/gooddata/cli/commands/run_ruby_cmd.rb +2 -3
  16. data/lib/gooddata/cli/commands/scaffold_cmd.rb +0 -3
  17. data/lib/gooddata/cli/commands/user_cmd.rb +0 -2
  18. data/lib/gooddata/cli/shared.rb +1 -2
  19. data/lib/gooddata/commands/datawarehouse.rb +24 -0
  20. data/lib/gooddata/commands/process.rb +0 -1
  21. data/lib/gooddata/commands/project.rb +1 -1
  22. data/lib/gooddata/commands/scaffold.rb +0 -1
  23. data/lib/gooddata/core/connection.rb +376 -0
  24. data/lib/gooddata/core/logging.rb +13 -0
  25. data/lib/gooddata/core/rest.rb +40 -16
  26. data/lib/gooddata/exceptions/user_in_different_domain.rb +11 -0
  27. data/lib/gooddata/extensions/enumerable.rb +8 -0
  28. data/lib/gooddata/goodzilla/goodzilla.rb +24 -0
  29. data/lib/gooddata/helpers/global_helpers.rb +126 -12
  30. data/lib/gooddata/mixins/author.rb +11 -5
  31. data/lib/gooddata/mixins/is_dimension.rb +13 -0
  32. data/lib/gooddata/mixins/md_object_indexer.rb +17 -1
  33. data/lib/gooddata/mixins/md_object_query.rb +10 -2
  34. data/lib/gooddata/mixins/md_relations.rb +2 -2
  35. data/lib/gooddata/mixins/rest_resource.rb +1 -0
  36. data/lib/gooddata/models/data_result.rb +0 -1
  37. data/lib/gooddata/models/datawarehouse.rb +90 -0
  38. data/lib/gooddata/models/domain.rb +202 -76
  39. data/lib/gooddata/models/execution.rb +11 -0
  40. data/lib/gooddata/models/from_wire.rb +4 -4
  41. data/lib/gooddata/models/invitation.rb +0 -5
  42. data/lib/gooddata/models/membership.rb +121 -91
  43. data/lib/gooddata/models/metadata.rb +1 -2
  44. data/lib/gooddata/models/metadata/attribute.rb +7 -0
  45. data/lib/gooddata/models/metadata/dashboard.rb +1 -1
  46. data/lib/gooddata/models/metadata/dimension.rb +52 -0
  47. data/lib/gooddata/models/metadata/fact.rb +1 -1
  48. data/lib/gooddata/models/metadata/label.rb +21 -7
  49. data/lib/gooddata/models/metadata/metric.rb +1 -23
  50. data/lib/gooddata/models/metadata/report.rb +2 -2
  51. data/lib/gooddata/models/metadata/report_definition.rb +22 -2
  52. data/lib/gooddata/models/metadata/variable.rb +81 -0
  53. data/lib/gooddata/models/model.rb +2 -1
  54. data/lib/gooddata/models/process.rb +3 -4
  55. data/lib/gooddata/models/profile.rb +50 -82
  56. data/lib/gooddata/models/project.rb +170 -213
  57. data/lib/gooddata/models/project_blueprint.rb +14 -5
  58. data/lib/gooddata/models/project_creator.rb +2 -2
  59. data/lib/gooddata/models/schedule.rb +10 -8
  60. data/lib/gooddata/models/to_wire.rb +2 -2
  61. data/lib/gooddata/models/user_filters/mandatory_user_filter.rb +67 -0
  62. data/lib/gooddata/models/user_filters/user_filter.rb +96 -0
  63. data/lib/gooddata/models/user_filters/user_filter_builder.rb +409 -0
  64. data/lib/gooddata/{rest/connections/connections.rb → models/user_filters/user_filters.rb} +1 -0
  65. data/lib/gooddata/models/user_filters/variable_user_filter.rb +14 -0
  66. data/lib/gooddata/rest/client.rb +32 -21
  67. data/lib/gooddata/rest/connection.rb +283 -11
  68. data/lib/gooddata/rest/connections/rest_client_connection.rb +47 -109
  69. data/lib/gooddata/version.rb +1 -1
  70. data/spec/data/column_based_permissions.csv +7 -0
  71. data/spec/data/column_based_permissions2.csv +6 -0
  72. data/spec/data/hello_world_process/hello_world.rb +3 -1
  73. data/spec/data/line_based_permissions.csv +3 -0
  74. data/spec/data/m_n_model/blueprint.json +76 -0
  75. data/spec/data/{model_view.json → wire_models/model_view.json} +0 -0
  76. data/spec/data/wire_models/nu_model.json +3046 -0
  77. data/spec/helpers/process_helper.rb +2 -2
  78. data/spec/helpers/project_helper.rb +29 -0
  79. data/spec/helpers/schedule_helper.rb +1 -1
  80. data/spec/integration/command_datawarehouse_spec.rb +32 -0
  81. data/spec/integration/create_project_spec.rb +0 -1
  82. data/spec/integration/full_process_schedule_spec.rb +13 -5
  83. data/spec/integration/full_project_spec.rb +2 -1
  84. data/spec/integration/over_to_user_filters_spec.rb +92 -0
  85. data/spec/integration/project_spec.rb +233 -0
  86. data/spec/integration/rest_spec.rb +209 -0
  87. data/spec/integration/user_filters_spec.rb +193 -0
  88. data/spec/integration/variables_spec.rb +196 -0
  89. data/spec/unit/commands/command_auth_spec.rb +0 -7
  90. data/spec/unit/commands/command_process_spec.rb +10 -13
  91. data/spec/unit/core/connection_spec.rb +0 -19
  92. data/spec/unit/helpers/global_helpers_spec.rb +57 -0
  93. data/spec/unit/models/domain_spec.rb +80 -40
  94. data/spec/unit/models/from_wire_spec.rb +8 -1
  95. data/spec/unit/models/params_spec.rb +6 -6
  96. data/spec/unit/models/profile_spec.rb +23 -22
  97. data/spec/unit/models/project_blueprint_spec.rb +1 -6
  98. data/spec/unit/models/project_spec.rb +331 -286
  99. data/spec/unit/models/schedule_spec.rb +39 -14
  100. data/spec/unit/models/user_filters_spec.rb +89 -0
  101. data/spec/unit/models/variable_spec.rb +259 -0
  102. metadata +31 -7
  103. data/lib/gooddata/rest/connections/dummy_connection.rb +0 -52
  104. data/spec/unit/core/rest_spec.rb +0 -106
@@ -64,7 +64,6 @@ describe GoodData::Model::ProjectBlueprint do
64
64
  d.add_attribute("id", :title => "My Id")
65
65
  d.add_fact("amount", :title => "Amount")
66
66
  end
67
-
68
67
  bp1 = GoodData::Model::ProjectBlueprint.new(builder)
69
68
  bp1.valid?.should == true
70
69
 
@@ -90,7 +89,7 @@ describe GoodData::Model::ProjectBlueprint do
90
89
  end
91
90
 
92
91
  it 'should be able to tell me if ceratain dataset by name is in the blueprint' do
93
- @blueprint.dataset?('devs').should be_true
92
+ @blueprint.dataset?('devs').should be_truthy
94
93
  end
95
94
 
96
95
  it 'should tell you it has anchor when it does' do
@@ -237,8 +236,4 @@ describe GoodData::Model::ProjectBlueprint do
237
236
  merged1 = @blueprint.merge(dataset)
238
237
  merged2 = dataset.merge(@blueprint)
239
238
  end
240
-
241
- it "should generate manifest" do
242
- m = GoodData::Model::ToManifest.to_manifest(@blueprint.to_hash)
243
- end
244
239
  end
@@ -1,65 +1,39 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'pmap'
4
-
5
4
  require 'gooddata'
6
5
 
7
- describe GoodData::Project do
8
- before(:each) do
6
+ describe GoodData::Project, :constraint => 'slow' do
7
+ before(:all) do
9
8
  @client = ConnectionHelper::create_default_connection
9
+ @project = ProjectHelper.get_default_project(:client => @client)
10
+ @domain = @client.domain(ConnectionHelper::DEFAULT_DOMAIN)
10
11
  end
11
12
 
12
- after(:each) do
13
+ after(:all) do
13
14
  @client.disconnect
14
15
  end
15
16
 
16
- def load_users_from_csv
17
- GoodData::Helpers::Csv.read(:path => CsvHelper::CSV_PATH_IMPORT, :header => true) do |row|
18
- json = {
19
- 'user' => {
20
- 'content' => {
21
- 'email' => row[2],
22
- 'login' => row[2],
23
- 'firstname' => row[0],
24
- 'lastname' => row[1],
25
-
26
- # Following lines are ugly hack
27
- 'role' => row[6],
28
- 'password' => CryptoHelper.generate_password,
29
- 'domain' => row[9],
30
-
31
- # And following lines are even much more ugly hack
32
- # 'sso_provider' => '',
33
- # 'authentication_modes' => ['sso', 'password']
34
- },
35
- 'meta' => {}
36
- }
37
- }
38
-
39
- GoodData::Membership.new(json)
40
- end
41
- end
42
-
43
- describe '#[]' do
44
- it 'Accepts :all parameter' do
45
- projects = GoodData::Project[:all, :client => @client]
46
- projects.should_not be_nil
47
- projects.should be_a_kind_of(Array)
17
+ describe 'projects' do
18
+ it 'Can get all projects' do
19
+ projects = @client.projects
20
+ expect(projects).to_not be_nil
21
+ expect(projects).to be_a_kind_of(Array)
48
22
  projects.pmap do |project|
49
23
  expect(project).to be_an_instance_of(GoodData::Project)
50
24
  end
51
25
  end
52
26
 
53
27
  it 'Returns project if ID passed' do
54
- project = GoodData::Project[ProjectHelper::PROJECT_ID, :client => @client]
55
- project.should_not be_nil
56
- project.should be_a_kind_of(GoodData::Project)
28
+ expect(@project).to_not be_nil
29
+ expect(@project).to be_a_kind_of(GoodData::Project)
30
+ expect(@project.pid).to eq @project.pid
57
31
  end
58
32
 
59
33
  it 'Returns project if URL passed' do
60
- project = GoodData::Project[ProjectHelper::PROJECT_URL, :client => @client]
61
- project.should_not be_nil
62
- project.should be_a_kind_of(GoodData::Project)
34
+ expect(@project).to_not be_nil
35
+ expect(@project).to be_a_kind_of(GoodData::Project)
36
+ expect(@project.pid).to eq @project.pid
63
37
  end
64
38
 
65
39
  it 'Throws an exception when invalid format of URL passed' do
@@ -71,120 +45,123 @@ describe GoodData::Project do
71
45
  describe '#all' do
72
46
  it 'Returns all projects' do
73
47
  projects = GoodData::Project.all(:client => @client)
74
- projects.should_not be_nil
75
- projects.should be_a_kind_of(Array)
48
+ expect(projects).to_not be_nil
49
+ expect(projects).to be_a_kind_of(Array)
76
50
  end
77
51
  end
78
52
 
79
53
  describe '#get_role_by_identifier' do
80
54
  it 'Looks up for role by identifier' do
81
- project = ProjectHelper.get_default_project(:client => @client)
82
- role = project.get_role_by_identifier('readOnlyUserRole')
83
- role.should_not be_nil
84
- role.should be_a_kind_of(GoodData::ProjectRole)
55
+ role = @project.get_role_by_identifier('readOnlyUserRole')
56
+ expect(role).to_not be_nil
57
+ expect(role).to be_a_kind_of(GoodData::ProjectRole)
85
58
  end
86
59
  end
87
60
 
88
61
  describe '#get_role_by_summary' do
89
62
  it 'Looks up for role by summary' do
90
- project = ProjectHelper.get_default_project(:client => @client)
91
- role = project.get_role_by_summary('read only user role')
92
- role.should_not be_nil
93
- role.should be_a_kind_of(GoodData::ProjectRole)
63
+ role = @project.get_role_by_summary('read only user role')
64
+ expect(role).to_not be_nil
65
+ expect(role).to be_a_kind_of(GoodData::ProjectRole)
94
66
  end
95
67
  end
96
68
 
97
69
  describe '#get_role_by_title' do
98
70
  it 'Looks up for role by title' do
99
- project = ProjectHelper.get_default_project(:client => @client)
100
- role = project.get_role_by_title('Viewer')
101
- role.should_not be_nil
102
- role.should be_a_kind_of(GoodData::ProjectRole)
71
+ role = @project.get_role_by_title('Viewer')
72
+ expect(role).to_not be_nil
73
+ expect(role).to be_a_kind_of(GoodData::ProjectRole)
103
74
  end
104
75
  end
105
76
 
106
77
  describe "#member" do
107
- it 'Returns GoodData::Membership when looking for existing user using email' do
108
- project = ProjectHelper.get_default_project(:client => @client)
109
- res = project.member('svarovsky+gem_tester@gooddata.com')
78
+ it 'Returns GoodData::Membership when looking for existing user using login' do
79
+ res = @project.get_user('svarovsky+gem_tester@gooddata.com')
110
80
  expect(res).to be_instance_of(GoodData::Membership)
111
81
  end
112
82
 
113
83
  it 'Returns GoodData::Membership when looking for existing user using URL' do
114
- project = ProjectHelper.get_default_project(:client => @client)
115
- res = project.member(ConnectionHelper::DEFAULT_USER_URL)
84
+ res = @project.get_user(ConnectionHelper::DEFAULT_USER_URL)
116
85
  expect(res).to be_instance_of(GoodData::Membership)
117
86
  end
118
87
 
119
88
  it 'Returns GoodData::Membership when looking for existing user using GoodData::Profile' do
120
- project = ProjectHelper.get_default_project(:client => @client)
121
- user = project.members.first
122
- res = project.member(user)
89
+ user = @project.members.first
90
+ res = @project.get_user(user)
123
91
  expect(res).to be_instance_of(GoodData::Membership)
124
92
  end
125
93
 
126
94
  it 'Returns null for non-existing user' do
127
- project = ProjectHelper.get_default_project(:client => @client)
128
- res = project.member('jan.kokotko@gooddata.com')
129
- res.should be_nil
95
+ res = @project.get_user('john.doe@gooddata.com')
96
+ expect(res).to be_nil
130
97
  end
131
98
  end
132
99
 
133
100
  describe "#member?" do
134
- it 'Returns true when looking for existing user using email' do
135
- project = ProjectHelper.get_default_project(:client => @client)
136
- res = project.member?('svarovsky+gem_tester@gooddata.com')
137
- res.should be_true
101
+ it 'Returns true when looking for existing user using login' do
102
+ res = @project.member?('svarovsky+gem_tester@gooddata.com')
103
+ expect(res).to be_truthy
138
104
  end
139
105
 
140
106
  it 'Returns true when looking for existing user using URL' do
141
- project = ProjectHelper.get_default_project(:client => @client)
142
- res = project.member?(ConnectionHelper::DEFAULT_USER_URL)
143
- res.should be_true
107
+ res = @project.member?(ConnectionHelper::DEFAULT_USER_URL)
108
+ expect(res).to be_truthy
144
109
  end
145
110
 
146
111
  it 'Returns true when looking for existing user using GoodData::Profile' do
147
- project = ProjectHelper.get_default_project(:client => @client)
148
- user = project.members.first
149
- res = project.member?(user)
150
- res.should be_true
112
+ user = @project.members.first
113
+ res = @project.member?(user)
114
+ expect(res).to be_truthy
151
115
  end
152
116
 
153
117
  it 'Returns false for non-existing user' do
154
- project = ProjectHelper.get_default_project(:client => @client)
155
- res = project.member?('jan.kokotko@gooddata.com')
156
- res.should be_false
118
+ res = @project.member?('john.doe@gooddata.com')
119
+ expect(res).to be_falsey
157
120
  end
158
121
 
159
122
  it 'Returns true for existing user when using optional list' do
160
- project = ProjectHelper.get_default_project(:client => @client)
161
- list = project.members
162
- res = project.member?('svarovsky+gem_tester@gooddata.com', list)
163
- res.should be_true
123
+ list = @project.members
124
+ res = @project.member?('svarovsky+gem_tester@gooddata.com', list)
125
+ expect(res).to be_truthy
164
126
  end
165
127
 
166
128
  it 'Returns false for non-existing user when using optional list' do
167
- project = ProjectHelper.get_default_project(:client => @client)
168
129
  list = []
169
- res = project.member?('svarovsky+gem_tester@gooddata.com', list)
170
- res.should be_false
130
+ res = @project.member?('svarovsky+gem_tester@gooddata.com', list)
131
+ expect(res).to be_falsey
171
132
  end
172
133
  end
173
134
 
174
- describe '#processes' do
175
- it 'Returns the processes' do
135
+ describe '#members?' do
136
+ it 'Returns array of bools when looking for existing users using GoodData::Profile' do
137
+ users = @project.members.take(10)
138
+ res = @project.members?(users)
139
+ expect(res.all?).to be_truthy
140
+ end
176
141
 
177
- project = GoodData::Project[ProjectHelper::PROJECT_ID, {:client => @client}]
178
- processes = project.processes
179
- expect(processes).to be_a_kind_of(Array)
142
+ it 'Support variety of inputs' do
143
+ users = @project.members.take(1)
144
+ res = @project.members?(users + ['john.doe@gooddata.com'])
145
+ expect(res).to eq [true, false]
180
146
  end
181
147
  end
182
148
 
149
+ # describe '#processes' do
150
+ # it 'Returns the processes' do
151
+ # @project.deploy_process('./spec/data/ruby_process',
152
+ # type: 'RUBY',
153
+ # name: 'Test ETL Process')
154
+ # processes = @project.processes
155
+ # expect(processes).to be_a_kind_of(Array)
156
+ # binding.pry
157
+ # expect(processes.count).to eq 1
158
+ # expect(processes.map(&:project).uniq).to eq [@project]
159
+ # end
160
+ # end
161
+
183
162
  describe '#roles' do
184
163
  it 'Returns array of GoodData::ProjectRole' do
185
- pending 'Investigate why is this soo slooow'
186
- project = ProjectHelper.get_default_project(:client => @client)
187
- roles = project.roles
164
+ roles = @project.roles
188
165
  expect(roles).to be_instance_of(Array)
189
166
 
190
167
  roles.each do |role|
@@ -193,193 +170,261 @@ describe GoodData::Project do
193
170
  end
194
171
  end
195
172
 
196
- describe '#users' do
197
- it 'Returns array of GoodData::Users' do
198
- pending 'Investigate why is this soo slooow'
199
-
200
- project = GoodData::Project[ProjectHelper::PROJECT_ID, {:client => @client}]
201
-
202
- invitations = project.invitations
203
- invitations.should_not be_nil
204
- expect(invitations).to be_instance_of(Array)
205
-
206
- users = project.users
207
- expect(users).to be_instance_of(Array)
208
-
209
- users.each do |user|
210
- expect(user).to be_instance_of(GoodData::Membership)
211
-
212
- roles = user.roles
213
- roles.should_not be_nil
214
- expect(roles).to be_instance_of(Array)
215
-
216
- roles.each do |role|
217
- expect(role).to be_instance_of(GoodData::ProjectRole)
218
- end
219
-
220
- permissions = user.permissions
221
- permissions.should_not be_nil
222
- permissions.should_not be_nil
223
- expect(permissions).to be_instance_of(Hash)
224
-
225
- # invitations = user.invitations
226
- # invitations.should_not be_nil
227
-
228
- if (user.email == 'tomas.korcak@gooddata.com')
229
- projects = user.projects
230
- projects.should_not be_nil
231
- expect(projects).to be_instance_of(Array)
232
-
233
- projects.each do |project|
234
- expect(project).to be_instance_of(GoodData::Project)
235
- end
236
- end
237
- end
238
- end
239
- end
240
-
241
- describe '#users_create' do
242
- it 'Creates new users' do
243
- project = ProjectHelper.get_default_project(:client => @client)
244
-
245
- users = (0...10).map do |i|
246
- num = rand(1e6)
247
- login = "gemtest#{num}@gooddata.com"
248
-
249
- json = {
250
- 'user' => {
251
- 'content' => {
252
- 'email' => login,
253
- 'login' => login,
254
- 'firstname' => 'the',
255
- 'lastname' => num.to_s,
256
-
257
- # Following lines are ugly hack
258
- 'role' => 'admin',
259
- 'password' => CryptoHelper.generate_password,
260
- 'domain' => ConnectionHelper::DEFAULT_DOMAIN,
261
-
262
- # And following lines are even much more ugly hack
263
- # 'sso_provider' => '',
264
- # 'authentication_modes' => ['sso', 'password']
265
- },
266
- 'meta' => {}
267
- }
268
- }
269
-
270
- GoodData::Membership.new(json)
271
- end
272
-
273
- project = GoodData::Project[ProjectHelper::PROJECT_ID, {:client => @client}]
274
- res = GoodData::Domain.users_create(users, nil, {:client => @client, :project => project})
275
-
276
- project.users_create(users)
277
-
278
- expect(res).to be_an_instance_of(Array)
279
- res.each do |r|
280
- expect(r).to be_an_instance_of(GoodData::Profile)
281
- r.delete
282
- end
283
- end
284
- end
285
-
286
- describe '#users_import' do
287
- it 'Import users from CSV' do
288
-
289
- project = GoodData::Project[ProjectHelper::PROJECT_ID, {:client => @client}]
290
-
291
- new_users = load_users_from_csv
292
-
293
- project.users_import(new_users)
294
- end
295
- end
296
-
297
- describe '#set_user_roles' do
298
- it 'Properly updates user roles as needed' do
299
- project = ProjectHelper.get_default_project(:client => @client)
300
-
301
- project.set_user_roles(ConnectionHelper::DEFAULT_USERNAME, 'admin')
302
- end
303
- end
304
-
305
- describe '#set_users_roles' do
306
- it 'Properly updates user roles as needed for bunch of users' do
307
- project = ProjectHelper.get_default_project(:client => @client)
308
-
309
- list = load_users_from_csv
310
-
311
- # Create domain users
312
- domain_users = GoodData::Domain.users_create(list, ConnectionHelper::DEFAULT_DOMAIN, :client => @client, :project => project)
313
- expect(domain_users.length).to equal(list.length)
314
-
315
- # Create list with user, desired_roles hashes
316
- domain_users.each_with_index do |user, index|
317
- list[index] = {
318
- :user => user,
319
- :roles => list[index].json['user']['content']['role'].split(' ').map { |r| r.downcase }.sort
320
- }
321
- end
322
-
323
- begin
324
- res = project.set_users_roles(list)
325
- rescue Exception => e
326
- puts e.inspect
327
- end
328
-
329
- expect(res.length).to equal(list.length)
330
- res.each do |update_result|
331
- expect(update_result[:result]['projectUsersUpdateResult']['successful'][0]).to include(update_result[:user].uri)
332
- end
333
-
334
- domain_users.each do |user|
335
- user.delete if user.email != ConnectionHelper::DEFAULT_USERNAME
336
- end
337
- end
338
-
339
- it 'Properly updates user roles when user specified by email and :roles specified as array of string with role names' do
340
- project = ProjectHelper.get_default_project(:client => @client)
341
-
342
- list = [
343
- {
344
- :user => ConnectionHelper::DEFAULT_USERNAME,
345
- :roles => ['admin']
346
- }
347
- ]
348
-
349
- res = project.set_users_roles(list)
350
- expect(res.length).to equal(list.length)
351
- end
352
-
353
- it 'Properly updates user roles when user specified by email and :roles specified as string with role name' do
354
- project = ProjectHelper.get_default_project(:client => @client)
355
-
356
- list = [
357
- {
358
- :user => ConnectionHelper::DEFAULT_USERNAME,
359
- :roles => 'admin'
360
- }
361
- ]
362
-
363
- res = project.set_users_roles(list)
364
- expect(res.length).to equal(list.length)
365
- end
366
- end
367
-
368
- describe '#summary' do
369
- it 'Properly gets title of project' do
370
- project = ProjectHelper.get_default_project(:client => @client)
371
-
372
- res = project.summary
373
- expect(res).to include(ProjectHelper::PROJECT_SUMMARY)
374
- end
375
- end
376
-
377
- describe '#title' do
378
- it 'Properly gets title of project' do
379
- project = ProjectHelper.get_default_project(:client => @client)
380
-
381
- res = project.title
382
- expect(res).to include(ProjectHelper::PROJECT_TITLE)
383
- end
384
- end
385
- end
173
+ # describe '#users' do
174
+ # it 'Returns array of GoodData::Users' do
175
+ #
176
+ # invitations = @project.invitations
177
+ # expect(invitations).to_not be_nil
178
+ # expect(invitations).to be_instance_of(Array)
179
+ #
180
+ # users = @project.users
181
+ # expect(users).to be_instance_of(Array)
182
+ #
183
+ # users.each do |user|
184
+ # expect(user).to be_instance_of(GoodData::Membership)
185
+ #
186
+ # roles = user.roles
187
+ # expect(roles).to_not be_nil
188
+ # expect(roles).to be_instance_of(Array)
189
+ #
190
+ # roles.each do |role|
191
+ # expect(role).to be_instance_of(GoodData::ProjectRole)
192
+ # end
193
+ #
194
+ # permissions = user.permissions
195
+ # expect(permissions).to_not be_nil
196
+ # expect(permissions).to_not be_nil
197
+ # expect(permissions).to be_instance_of(Hash)
198
+ #
199
+ # # invitations = user.invitations
200
+ # # invitations.should_not be_nil
201
+ #
202
+ # if (user.email == 'tomas.korcak@gooddata.com')
203
+ # projects = user.projects
204
+ # expect(projects).to_not be_nil
205
+ # expect(projects).to be_instance_of(Array)
206
+ #
207
+ # projects.each do |project|
208
+ # expect(project).to be_instance_of(GoodData::Project)
209
+ # end
210
+ # end
211
+ # end
212
+ # end
213
+ # end
214
+ #
215
+ # describe '#add_user' do
216
+ # it 'Adding user without domain should fail if it is not in the project' do
217
+ # user = ProjectHelper.create_random_user(@client)
218
+ # expect do
219
+ # @project.add_user(user, 'Admin')
220
+ # end.to raise_exception(ArgumentError)
221
+ # end
222
+ #
223
+ # it 'Adding user with domain should be added to a project' do
224
+ # user = ProjectHelper.create_random_user(@client)
225
+ # @domain.create_users([user])
226
+ # res = @project.add_user(user, 'Admin', domain: @domain)
227
+ # expect(@project.member?(res['projectUsersUpdateResult']['successful'].first)).to be_truthy
228
+ # end
229
+ # end
230
+ #
231
+ # describe '#add_users' do
232
+ # it 'Adding user without domain should fail if it is not in the project' do
233
+ # users = (1..5).to_a.map do |x|
234
+ # {
235
+ # user: ProjectHelper.create_random_user(@client),
236
+ # role: 'Admin'
237
+ # }
238
+ # end
239
+ # res = @project.add_users(users)
240
+ # expect(res.all? { |x| x[:type] == :error }).to eq true
241
+ # end
242
+ #
243
+ # it 'Adding users with domain should pass and users should be added to domain' do
244
+ # users = (1..5).to_a.map do |x|
245
+ # {
246
+ # user: ProjectHelper.create_random_user(@client),
247
+ # role: 'Admin'
248
+ # }
249
+ # end
250
+ # @domain.create_users(users.map {|u| u[:user]})
251
+ # res = @project.add_users(users, domain: @domain)
252
+ # links = res.map {|i| i[:result]['projectUsersUpdateResult']['successful'].first}
253
+ # expect(@project.members?(links).all?).to be_truthy
254
+ # # users.map { |r| r[:user] }.each { |u| u.delete }
255
+ # end
256
+ # end
257
+ #
258
+ # describe '#import_users' do
259
+ # it "Updates user's name and surname and removes the users" do
260
+ # users = (1..2).to_a.map { |x| ProjectHelper.create_random_user(@client) }
261
+ # @project.import_users(users, domain: @domain, whitelists: [/gem_tester@gooddata.com/])
262
+ # expect(@domain.members?(users)).to be_truthy
263
+ # expect(@project.members?(users)).to be_truthy
264
+ # expect(@project.members.count).to eq 3
265
+ # # update some user stuff
266
+ # bill = users[0]
267
+ # bill.first_name = 'buffalo'
268
+ # bill.last_name = 'bill'
269
+ # # import
270
+ # @project.import_users(users, domain: @domain, whitelists: [/gem_tester@gooddata.com/])
271
+ # # it should be updated
272
+ # bill_changed = @domain.get_user(bill)
273
+ # expect(bill_changed.first_name).to eql('buffalo')
274
+ # expect(bill_changed.last_name).to eql('bill')
275
+ # expect(@project.members?(users)).to be_truthy
276
+ # expect(@project.members.count).to eq 3
277
+ # expect(@project.member?(bill_changed)).to be_truthy
278
+ #
279
+ # # remove everybody but buffalo bill.
280
+ # @project.import_users([bill], domain: @domain, whitelists: [/gem_tester@gooddata.com/])
281
+ # expect(@project.members.count).to eq 2
282
+ # expect(@project.member?(bill)).to be_truthy
283
+ # expect(@project.members?(users - [bill]).any?).to be_falsey
284
+ #
285
+ # # Add additional user while changing Buffalos surname and role.
286
+ # bill.last_name = 'Billie'
287
+ # other_guy = ProjectHelper.create_random_user(@client)
288
+ #
289
+ # additional_batch = [bill, other_guy].map { |u| {user: u, role: u.role} }
290
+ # @project.import_users(additional_batch, domain: @domain, whitelists: [/gem_tester@gooddata.com/])
291
+ # expect(@project.members.count).to eq 3
292
+ # expect(@project.member?(bill)).to be_truthy
293
+ # expect(@project.members?(users - additional_batch.map {|x| x[:user]}).any?).to be_falsey
294
+ # end
295
+ #
296
+ # it "Updates user's role in a project" do
297
+ # users = (1..5).to_a.map { |x| ProjectHelper.create_random_user(@client).to_hash }
298
+ # @project.import_users(users, domain: @domain, whitelists: [/gem_tester@gooddata.com/])
299
+ #
300
+ # expect(@project.members?(users)).to be_truthy
301
+ # user_role_changed = users[1]
302
+ # users_unchanged = users - [user_role_changed]
303
+ # new_role = users[1][:role] = users[1][:role] == "admin" ? "editor" : "admin"
304
+ # @project.import_users(users, domain: @domain, whitelists: [/gem_tester@gooddata.com/])
305
+ # expect(@project.get_user(user_role_changed).role.identifier).to eql("#{new_role}Role")
306
+ # expect(users_unchanged.map {|u| @project.get_user(u)}.map(&:role).map(&:title).uniq).to eq ['Editor']
307
+ # end
308
+ #
309
+ # it "ignores user from both project and end state batch when whitelisted" do
310
+ # u = @project.get_user(ConnectionHelper::DEFAULT_USERNAME)
311
+ # uh = u.to_hash
312
+ # uh[:role] = 'editor'
313
+ #
314
+ # users = (1..5).to_a.map { |x| ProjectHelper.create_random_user(@client).to_hash } + [uh]
315
+ # expect(@project.member?(u)).to be_truthy
316
+ # expect(u.role.title).to eq 'Admin'
317
+ # @project.import_users(users, domain: @domain, whitelists: [/gem_tester@gooddata.com/])
318
+ # expect(@project.member?(u)).to be_truthy
319
+ # expect(@project.members?(users).all?).to be_truthy
320
+ # expect(@project.get_user(ConnectionHelper::DEFAULT_USERNAME).role.title).to eq 'Admin'
321
+ # end
322
+ #
323
+ # end
324
+ #
325
+ # describe '#set_user_roles' do
326
+ # it 'Properly updates user roles as needed' do
327
+ # users_to_import = @domain.users.sample(5).map {|u| { user: u, role: 'admin' }}
328
+ # @project.import_users(users_to_import, domain: @domain, whitelists: [/gem_tester@gooddata.com/])
329
+ # users_without_owner = @project.users.reject { |u| u.login == ConnectionHelper::DEFAULT_USERNAME }.pselect { |u| u.role.title == 'Admin' }
330
+ #
331
+ # user_to_change = users_without_owner.sample
332
+ # @project.set_user_roles(user_to_change, 'editor')
333
+ # expect(user_to_change.role.title).to eq 'Editor'
334
+ # @project.set_user_roles(user_to_change, 'admin')
335
+ # expect(user_to_change.role.title).to eq 'Admin'
336
+ #
337
+ # # Try different notation
338
+ # @project.set_users_roles([user: user_to_change, role: 'editor'])
339
+ # expect(user_to_change.role.title).to eq 'Editor'
340
+ # @project.set_users_roles([user: user_to_change, role: 'admin'])
341
+ # expect(user_to_change.role.title).to eq 'Admin'
342
+ # end
343
+ #
344
+ # it 'Properly updates user roles when user specified by email and :roles specified as array of string with role names' do
345
+ # # pick non deleted users that are not owner and have other roles than admin or editor
346
+ # users = @project.users
347
+ # users_without_owner = users
348
+ # .reject { |u| u.login == ConnectionHelper::DEFAULT_USERNAME }
349
+ # .reject { |u| u.login =~ /^deleted/ }
350
+ # .pselect { |u| u.role.title =~ /^(Admin|Editor)/ }
351
+ #
352
+ # # take 10 users that we will exercise
353
+ # users_to_change = users_without_owner.sample(10)
354
+ #
355
+ # # alternate roles and prepare structure
356
+ # logins = users_to_change.map(&:login)
357
+ # roles = users_to_change.map { |u| u.role.title == 'Admin' ? ['Editor'] : ['Admin'] }
358
+ #
359
+ # list = users_to_change.map do |u|
360
+ # {
361
+ # :user => u.login,
362
+ # :roles => u.role.title == 'Admin' ? ['Editor'] : ['Admin']
363
+ # }
364
+ # end
365
+ #
366
+ # # set the roles
367
+ # res = @project.set_users_roles(list)
368
+ # expect(res.length).to equal(list.length)
369
+ # expect(logins.map {|l| users.find {|u| u.login == l}}.pmap {|u| u.role.title}).to eq roles.flatten
370
+ # end
371
+ #
372
+ # it 'Properly updates user roles when user specified by email and :roles specified as string with role name' do
373
+ # users = @project.users
374
+ # users_without_owner = users
375
+ # .reject { |u| u.login == ConnectionHelper::DEFAULT_USERNAME }
376
+ # .reject(&:deleted?)
377
+ # .pselect { |u| u.role.title =~ /^(Admin|Editor)/ }
378
+ #
379
+ # users_to_change = users_without_owner.sample(10)
380
+ #
381
+ # logins = users_to_change.map(&:login)
382
+ # roles = users_to_change.map { |u| u.role.title == 'Admin' ? 'Editor' : 'Admin' }
383
+ #
384
+ # list = users_to_change.map do |u|
385
+ # {
386
+ # :user => u.login,
387
+ # :roles => u.role.title == 'Admin' ? 'Editor' : 'Admin'
388
+ # }
389
+ # end
390
+ #
391
+ # res = @project.set_users_roles(list)
392
+ # expect(res.length).to equal(list.length)
393
+ # expect(logins.map {|l| users.find {|u| u.login == l}}.pmap {|u| u.role.title}).to eq roles.flatten
394
+ #
395
+ # end
396
+ # end
397
+ #
398
+ # describe '#summary' do
399
+ # it 'Properly gets summary of project' do
400
+ # res = @project.summary
401
+ # expect(res).to include(ProjectHelper::PROJECT_SUMMARY)
402
+ # end
403
+ # end
404
+ #
405
+ # describe '#title' do
406
+ # it 'Properly gets title of project' do
407
+ # res = @project.title
408
+ # expect(res).to include(ProjectHelper::PROJECT_TITLE)
409
+ # end
410
+ # end
411
+ #
412
+ # describe 'enabling and disabling users' do
413
+ # it 'should be able to enable and disable a user' do
414
+ # users_without_owner = @project.users
415
+ # .reject { |u| u.login == ConnectionHelper::DEFAULT_USERNAME }
416
+ # .reject(&:deleted?)
417
+ # .select(&:enabled?)
418
+ # user = users_without_owner.sample
419
+ # expect(user.enabled?).to be_truthy
420
+ # expect(user.disabled?).to be_falsey
421
+ # user.disable
422
+ # expect(user.disabled?).to be_truthy
423
+ # expect(user.enabled?).to be_falsey
424
+ # user.enable
425
+ # expect(user.enabled?).to be_truthy
426
+ # expect(user.disabled?).to be_falsey
427
+ # expect(user.project).not_to be_nil
428
+ # end
429
+ # end
430
+ end