rimesync 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,425 @@
1
+ class MockTimeSync
2
+ def authenticate
3
+ Hash['token' => 'TESTTOKEN']
4
+ end
5
+
6
+ def token_expiration_time
7
+ Time.new(2016, 1, 13, 11, 45, 34)
8
+ end
9
+
10
+ # Sends time to baseurl (TimeSync)
11
+ def create_time(p_dict)
12
+ p_dict['created_at'] = '2015-05-23'
13
+ p_dict['updated_at'] = nil
14
+ p_dict['deleted_at'] = nil
15
+ p_dict['uuid'] = '838853e3-3635-4076-a26f-7efr4e60981f'
16
+ p_dict['revision'] = 1
17
+ p_dict['notes'] = p_dict['notes'] ? p_dict['notes'] : nil
18
+ p_dict['issue_uri'] = p_dict['issue_uri'] ? p_dict['issue_uri'] : nil
19
+ p_dict
20
+ end
21
+
22
+ # rubocop:disable MethodLength
23
+ # rubocop:disable Metrics/AbcSize
24
+ # Updates time by uuid
25
+ def update_time(p_dict, uuid)
26
+ updated_param = Hash[
27
+ 'duration' => p_dict.key?('duration') ? p_dict['duration'] : 18,
28
+ 'user' => p_dict.key?('user') ? p_dict['user'] : 'example-user',
29
+ 'activities' => p_dict.key?('activities') ? p_dict['activities'] : ['qa'],
30
+ 'project' => p_dict.key?('project') ? p_dict['project'] : ['ganeti'],
31
+ 'notes' => p_dict.key?('notes') ? p_dict['notes'] : nil,
32
+ # 'issue_uri' => p_dict.key?('issue_uri') ? p_dict['issue_uri'] : 'https://github.com/osuosl/ganeti_webmgr/issues/56',
33
+ 'issue_uri' => if p_dict.key?('issue_uri') then p_dict['issue_uri']
34
+ else 'https://github.com/osuosl/ganeti_webmgr/issues/56'
35
+ end,
36
+ 'date_worked' => if p_dict.key?('date_worked') then p_dict['date_worked']
37
+ else '2015-08-07'
38
+ end,
39
+ 'created_at' => '2014-06-12',
40
+ 'updated_at' => '2015-10-18',
41
+ 'deleted_at' => nil,
42
+ 'uuid' => uuid,
43
+ 'revision' => 2
44
+ ]
45
+ updated_param
46
+ end
47
+
48
+ # Creates project
49
+ def create_project(p_dict)
50
+ p_dict['users'] = p_dict.key?('users') ? p_dict['users'] : Hash[
51
+ 'mrsj' => Hash['member' => true, 'spectator' => true,
52
+ 'manager' => true],
53
+ 'tschuy' => Hash['member' => true, 'spectator' => false,
54
+ 'manager' => false]
55
+ ]
56
+ p_dict['uuid'] = '309eae69-21dc-4538-9fdc-e6892a9c4dd4'
57
+ p_dict['revision'] = 1
58
+ p_dict['created_at'] = '2015-05-23'
59
+ p_dict['updated_at'] = nil
60
+ p_dict['deleted_at'] = nil
61
+ p_dict['uri'] = p_dict.key?('uri') ? p_dict['uri'] : nil
62
+ p_dict
63
+ end
64
+
65
+ # Updates project by slug
66
+ def update_project(p_dict, slug)
67
+ updated_param = Hash[
68
+ 'uri' => p_dict.key?('uri') ? p_dict['uri'] : nil,
69
+ 'name' => p_dict.key?('name') ? p_dict['name'] : 'TimeSync API',
70
+ 'slugs' => p_dict.key?('slugs') ? p_dict['slugs'] : [slug],
71
+ 'created_at' => '2014-04-16',
72
+ 'updated_at' => '2014-04-18',
73
+ 'deleted_at' => nil,
74
+ 'uuid' => '309eae69-21dc-4538-9fdc-e6892a9c4dd4',
75
+ 'revision' => 2,
76
+ 'users' => Hash[
77
+ 'members' => %w(patcht tschuy),
78
+ 'spectators' => [
79
+ 'tschuy'
80
+ ],
81
+ 'managers' => [
82
+ 'tschuy'
83
+ ]
84
+ ]
85
+ ]
86
+ updated_param
87
+ end
88
+
89
+ # Creates activity
90
+ def create_activity(p_dict)
91
+ p_dict['uuid'] = 'cfa07a4f-d446-4078-8d73-2f77560c35c0'
92
+ p_dict['created_at'] = '2013-07-27'
93
+ p_dict['updated_at'] = nil
94
+ p_dict['deleted_at'] = nil
95
+ p_dict['revision'] = 1
96
+ p_dict
97
+ end
98
+
99
+ # Updates activity by slug
100
+ def update_activity(p_dict, slug)
101
+ updated_param = Hash[
102
+ 'name' => p_dict.key?('name') ? p_dict['name'] : 'Testing Infra',
103
+ 'slug' => p_dict.key?('slug') ? p_dict['slug'] : slug,
104
+ 'uuid' => '3cf78d25-411c-4d1f-80c8-a09e5e12cae3',
105
+ 'created_at' => '2014-04-16',
106
+ 'updated_at' => '2014-04-17',
107
+ 'deleted_at' => nil,
108
+ 'revision' => 2
109
+ ]
110
+ updated_param
111
+ end
112
+
113
+ # Creates a user
114
+ def create_user(p_dict)
115
+ p_dict['active'] = true
116
+ p_dict['site_admin'] = if p_dict.key?('site_admin')
117
+ p_dict['site_admin']
118
+ else false
119
+ end
120
+ p_dict['site_manager'] = if p_dict.key?('site_manager')
121
+ p_dict['site_manager']
122
+ else false
123
+ end
124
+ p_dict['site_spectator'] = if p_dict.key?('site_spectator')
125
+ p_dict['site_spectator']
126
+ else false
127
+ end
128
+ p_dict['created_at'] = '2015-05-23'
129
+ p_dict['deleted_at'] = nil
130
+ p_dict.delete('password')
131
+ p_dict
132
+ end
133
+
134
+ # Updates user by username
135
+ def update_user(p_dict, username)
136
+ updated_param = Hash[
137
+ 'username' => p_dict.key?('username') ? p_dict['username'] : username,
138
+ 'display_name' => if p_dict.key?('display_name')
139
+ p_dict['display_name']
140
+ else 'Mr. Example'
141
+ end,
142
+ 'email' => if p_dict.key?('email')
143
+ p_dict['email']
144
+ else 'examplej@example.com'
145
+ end,
146
+ 'active' => true,
147
+ 'site_admin' => p_dict.key?('site_admin') ? p_dict['site_admin'] : false,
148
+ 'site_manager' => if p_dict.key?('site_manager')
149
+ p_dict['site_manager']
150
+ else false
151
+ end,
152
+ 'site_spectator' => if p_dict.key?('site_spectator')
153
+ p_dict['site_spectator']
154
+ else false
155
+ end,
156
+ 'created_at' => '2015-02-29',
157
+ 'deleted_at' => nil
158
+ ]
159
+ updated_param
160
+ end
161
+
162
+ # Get times from TimeSync
163
+ def get_times(uuid)
164
+ p_list = Array[
165
+ Hash[
166
+ 'duration' => 12,
167
+ 'user' => 'userone',
168
+ 'project' => %w(ganeti-webmgr gwm),
169
+ 'activities' => %w(docs planning),
170
+ 'notes' => 'Worked on documentation.',
171
+ 'issue_uri' => 'https://github.com/osuosl/ganeti_webmgr',
172
+ 'date_worked' => '2014-04-17',
173
+ 'revision' => 1,
174
+ 'created_at' => '2014-04-17',
175
+ 'updated_at' => nil,
176
+ 'deleted_at' => nil,
177
+ 'uuid' => uuid ? uuid : 'c3706e79-1c9a-4765-8d7f-89b4544cad56'
178
+ ]
179
+ ]
180
+ unless uuid
181
+ p_list.push(
182
+ Hash[
183
+ 'duration' => 13,
184
+ 'user' => 'usertwo',
185
+ 'project' => %w(ganeti-webmgr gwm),
186
+ 'activities' => %w(code planning),
187
+ 'notes' => 'Worked on coding',
188
+ 'issue_uri' => 'https://github.com/osuosl/ganeti_webmgr',
189
+ 'date_worked' => '2014-04-17',
190
+ 'revision' => 1,
191
+ 'created_at' => '2014-04-17',
192
+ 'updated_at' => nil,
193
+ 'deleted_at' => nil,
194
+ 'uuid' => '12345676-1c9a-rrrr-bbbb-89b4544cad56'
195
+ ]
196
+ )
197
+
198
+ p_list.push(
199
+ Hash[
200
+ 'duration' => 14,
201
+ 'user' => 'userthree',
202
+ 'project' => %w(timesync ts),
203
+ 'activities' => ['code'],
204
+ 'notes' => 'Worked on coding',
205
+ 'issue_uri' => 'https://github.com/osuosl/timesync',
206
+ 'date_worked' => '2014-04-17',
207
+ 'revision' => 1,
208
+ 'created_at' => '2014-04-17',
209
+ 'updated_at' => nil,
210
+ 'deleted_at' => nil,
211
+ 'uuid' => '12345676-1c9a-ssss-cccc-89b4544cad56'
212
+ ]
213
+ )
214
+ end
215
+ p_list
216
+ end
217
+
218
+ # Get project information from TimeSync
219
+ def get_projects(slug)
220
+ p_list = Array[
221
+ Hash[
222
+ 'uri' => 'https://code.osuosl.org/projects/ganeti-webmgr',
223
+ 'name' => 'Ganeti Web Manager',
224
+ 'slugs' => [slug ? slug : 'gwm'],
225
+ 'uuid' => 'a034806c-00db-4fe1-8de8-514575f31bfb',
226
+ 'revision' => 4,
227
+ 'created_at' => '2014-07-17',
228
+ 'deleted_at' => nil,
229
+ 'updated_at' => '2014-07-20',
230
+ 'users' => Hash[
231
+ 'members' => %w(patcht tschuy),
232
+ 'spectators' => [
233
+ 'tschuy'
234
+ ],
235
+ 'managers' => [
236
+ 'tschuy'
237
+ ]
238
+ ]
239
+ ]
240
+ ]
241
+ unless slug
242
+ p_list.push(
243
+ Hash[
244
+ 'uri' => 'https://code.osuosl.org/projects/timesync',
245
+ 'name' => 'TimeSync',
246
+ 'slugs' => %w(timesync ts),
247
+ 'uuid' => 'a034806c-rrrr-bbbb-8de8-514575f31bfb',
248
+ 'revision' => 2,
249
+ 'created_at' => '2014-07-17',
250
+ 'deleted_at' => nil,
251
+ 'updated_at' => '2014-07-20',
252
+ 'users' => Hash[
253
+ 'members' => %w(patcht tschuy mrsj),
254
+ 'spectators' => %w(tschuy mrsj),
255
+ 'managers' => [
256
+ 'tschuy'
257
+ ]
258
+ ]
259
+ ]
260
+ )
261
+
262
+ p_list.push(
263
+ Hash[
264
+ 'uri' => 'https://code.osuosl.org/projects/rimesync',
265
+ 'name' => 'rimesync',
266
+ 'slugs' => %w(rimesync rs),
267
+ 'uuid' => 'a034806c-ssss-cccc-8de8-514575f31bfb',
268
+ 'revision' => 1,
269
+ 'created_at' => '2014-07-17',
270
+ 'deleted_at' => nil,
271
+ 'updated_at' => '2014-07-20',
272
+ 'users' => Hash[
273
+ 'members' => %w(patcht tschuy mrsj MaraJade thai),
274
+ 'spectators' => %w(tschuy mrsj),
275
+ 'managers' => [
276
+ 'mrsj'
277
+ ]
278
+ ]
279
+ ]
280
+ )
281
+ end
282
+ p_list
283
+ end
284
+
285
+ # Get activity information from TimeSync
286
+ def get_activities(slug)
287
+ p_list = Array[
288
+ Hash[
289
+ 'name' => 'Documentation',
290
+ 'slug' => slug ? slug : 'docs',
291
+ 'uuid' => 'adf036f5-3d49-4a84-bef9-062b46380bbf',
292
+ 'revision' => 5,
293
+ 'created_at' => '2014-04-17',
294
+ 'deleted_at' => nil,
295
+ 'updated_at' => nil
296
+ ]
297
+ ]
298
+ unless slug
299
+ p_list.push(
300
+ Hash[
301
+ 'name' => 'Coding',
302
+ 'slug' => 'dev',
303
+ 'uuid' => 'adf036f5-3d49-bbbb-rrrr-062b46380bbf',
304
+ 'revision' => 1,
305
+ 'created_at' => '2014-04-17',
306
+ 'deleted_at' => nil,
307
+ 'updated_at' => nil
308
+ ]
309
+ )
310
+
311
+ p_list.push(
312
+ Hash[
313
+ 'name' => 'Planning',
314
+ 'slug' => 'plan',
315
+ 'uuid' => 'adf036f5-3d49-cccc-ssss-062b46380bbf',
316
+ 'revision' => 1,
317
+ 'created_at' => '2014-04-17',
318
+ 'deleted_at' => nil,
319
+ 'updated_at' => nil
320
+ ]
321
+ )
322
+ end
323
+ p_list
324
+ end
325
+
326
+ # Get user information from TimeSync
327
+ def get_users(username)
328
+ if username
329
+ p_dict = Array[
330
+ Hash[
331
+ 'username' => username,
332
+ 'display_name' => 'X. Ample User',
333
+ 'email' => 'example@example.com',
334
+ 'active' => true,
335
+ 'site_admin' => if username == 'admin'
336
+ true
337
+ else
338
+ false
339
+ end,
340
+ 'site_spectator' => if username == 'spectator'
341
+ true
342
+ else
343
+ false
344
+ end,
345
+ 'site_manager' => if username == 'manager'
346
+ true
347
+ else
348
+ false
349
+ end,
350
+ 'created_at' => '2015-02-29',
351
+ 'deleted_at' => nil
352
+ ]
353
+ ]
354
+ else
355
+ p_dict = Array[
356
+ Hash[
357
+ 'username' => 'userone',
358
+ 'display_name' => 'One Is The Loneliest Number',
359
+ 'email' => 'exampleone@example.com',
360
+ 'active' => true,
361
+ 'site_admin' => false,
362
+ 'site_manager' => false,
363
+ 'site_spectator' => false,
364
+ 'created_at' => '2015-02-29',
365
+ 'deleted_at' => nil
366
+ ],
367
+ Hash[
368
+ 'username' => 'usertwo',
369
+ 'display_name' => 'Two Can Be As Bad As One',
370
+ 'email' => 'exampletwo@example.com',
371
+ 'active' => true,
372
+ 'site_admin' => false,
373
+ 'site_manager' => false,
374
+ 'site_spectator' => false,
375
+ 'created_at' => '2015-02-29',
376
+ 'deleted_at' => nil
377
+ ],
378
+ Hash[
379
+ 'username' => 'userthree',
380
+ 'display_name' => 'Yes It is The Saddest Experience',
381
+ 'email' => 'examplethree@example.com',
382
+ 'active' => true,
383
+ 'site_admin' => false,
384
+ 'site_manager' => false,
385
+ 'site_spectator' => false,
386
+ 'created_at' => '2015-02-29',
387
+ 'deleted_at' => nil
388
+ ],
389
+ Hash[
390
+ 'username' => 'userfour',
391
+ 'display_name' => 'You will Ever Do',
392
+ 'email' => 'examplefour@example.com',
393
+ 'active' => true,
394
+ 'site_admin' => false,
395
+ 'site_manager' => false,
396
+ 'site_spectator' => false,
397
+ 'created_at' => '2015-02-29',
398
+ 'deleted_at' => nil
399
+ ]
400
+ ]
401
+ end
402
+ p_dict
403
+ end
404
+
405
+ # Delete an object from TimeSync
406
+ def delete_object
407
+ Array[Hash['status' => 200]]
408
+ end
409
+
410
+ # Return list of users and permissions from TimeSync
411
+ def project_users
412
+ users = Hash[
413
+ 'malcolm' => %w(member manager),
414
+ 'jayne' => ['member'],
415
+ 'kaylee' => ['member'],
416
+ 'zoe' => ['member'],
417
+ 'hoban' => ['member'],
418
+ 'simon' => ['spectator'],
419
+ 'river' => ['spectator'],
420
+ 'derrial' => ['spectator'],
421
+ 'inara' => ['spectator']
422
+ ]
423
+ users
424
+ end
425
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rimesync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - OSU Open Source Lab
8
+ - Chaitanya Gupta
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bcrypt
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 3.1.11
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 3.1.11
28
+ - !ruby/object:Gem::Dependency
29
+ name: rest-client
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 1.8.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.8.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: webmock
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 2.1.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 2.1.0
56
+ description: A ruby Gem to interface with the TimeSync API.
57
+ email:
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/rimesync.rb
63
+ - lib/rimesync/mock_rimesync.rb
64
+ homepage: https://github.com/osuosl/rimesync
65
+ licenses:
66
+ - Apache-2
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.2.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.5.1
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: A ruby Gem to interface with the TimeSync API.
88
+ test_files: []