-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
610 lines (512 loc) · 20.7 KB
/
test.py
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
import getpass
import time
import unittest
import uuid
from functools import wraps
from six.moves import input
import rpmfusion_cert
from rfpkgdb2client import PkgDB, PkgDBException
PKGDB_URL = 'http://127.0.0.1:5000'
AUTH = True
if AUTH:
try:
USERNAME = rpmfusion_cert.read_user_cert()
except:
USERNAME = input('FAS username: ')
PASSWORD = getpass.getpass('FAS password: ')
if not PASSWORD:
AUTH = False
COL_NAME = str(uuid.uuid1())[:30]
PKG_NAME = str(uuid.uuid1())[:30]
VERSION = time.mktime(datetime.datetime.utcnow().timetuple())
def auth_only(function):
""" Decorator to skip tests if AUTH is set to False """
@wraps(function)
def decorated_function(*args, **kwargs):
""" Decorated function, actually does the work. """
if AUTH:
return function(*args, **kwargs)
else:
return 'Skipped'
return decorated_function
class TestPkgdDB(unittest.TestCase):
''' Un-authenticated pkgdb2 tests. '''
def setUp(self):
""" set up data used in the tests.
setUp is called before each test function execution.
"""
self.pkgdb = PkgDB(PKGDB_URL, insecure=True)
def test_get_collection(self):
''' Test the get_collections function. '''
out = self.pkgdb.get_collections()
self.assertEqual(
sorted(out.keys()),
['collections', 'output'])
self.assertTrue(len(out['collections']) >= 30)
out = self.pkgdb.get_collections(pattern='f19')
self.assertEqual(len(out['collections']), 1)
self.assertEqual(out['collections'][0]['branchname'], 'f19')
self.assertEqual(
sorted(out.keys()),
['collections', 'output'])
out = self.pkgdb.get_collections(
clt_status=['EOL', 'Under Development'])
self.assertEqual(
sorted(out.keys()),
['collections', 'output'])
self.assertTrue(len(out['collections']) >= 25)
def test_get_package(self):
''' Test the get_package function. '''
out = self.pkgdb.get_package('guake')
self.assertEqual(
sorted(out.keys()),
['output', 'packages'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(len(out['packages']), 5)
self.assertEqual(
out['packages'][0]['collection']['branchname'], 'master')
self.assertEqual(
out['packages'][0]['package']['name'], 'guake')
self.assertEqual(
out['packages'][0]['point_of_contact'], 'pingou')
out = self.pkgdb.get_package('guake', 'f20')
self.assertEqual(
sorted(out.keys()),
['output', 'packages'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(len(out['packages']), 1)
self.assertEqual(
out['packages'][0]['collection']['branchname'], 'f20')
self.assertEqual(
out['packages'][0]['package']['name'], 'guake')
out = self.pkgdb.get_package('guake', ['f20', 'f19'])
self.assertEqual(
sorted(out.keys()),
['output', 'packages'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(len(out['packages']), 2)
self.assertEqual(
out['packages'][0]['collection']['branchname'], 'f19')
self.assertEqual(
out['packages'][1]['collection']['branchname'], 'f20')
self.assertEqual(
out['packages'][0]['package']['name'], 'guake')
self.assertEqual(
out['packages'][1]['package']['name'], 'guake')
def test_get_packager_acls(self):
''' Test the get_packager_acls function. '''
out = self.pkgdb.get_packager_acls('pingou')
self.assertEqual(
sorted(out.keys()),
['acls', 'output', 'page', 'page_total'])
self.assertEqual(len(out['acls']), 250)
self.assertEqual(out['page_total'], 6)
out = self.pkgdb.get_packager_acls('pingou', acls=['approveacls'])
self.assertEqual(
sorted(out.keys()),
['acls', 'output', 'page', 'page_total'])
self.assertTrue(len(out['acls']) >= 239)
self.assertEqual(out['page_total'], 2)
out = self.pkgdb.get_packager_acls('pingou', page=3)
self.assertEqual(
sorted(out.keys()),
['acls', 'output', 'page', 'page_total'])
self.assertTrue(len(out['acls']) >= 250)
self.assertEqual(out['page_total'], 6)
out = self.pkgdb.get_packager_acls('pingou', count=True)
self.assertEqual(
sorted(out.keys()),
['acls_count', 'output', 'page', 'page_total'])
self.assertTrue(out['acls_count'] >= 1043)
self.assertEqual(out['page_total'], 1)
out = self.pkgdb.get_packager_acls('pingou', poc=True, count=True)
self.assertEqual(
sorted(out.keys()),
['acls_count', 'output', 'page', 'page_total'])
self.assertTrue(out['acls_count'] >= 750)
self.assertEqual(out['page_total'], 1)
out = self.pkgdb.get_packager_acls('pingou', poc=False, count=True)
self.assertEqual(
sorted(out.keys()),
['acls_count', 'output', 'page', 'page_total'])
self.assertTrue(out['acls_count'] >= 239)
self.assertEqual(out['page_total'], 1)
def test_get_packager_stats(self):
''' Test the get_packager_stats function. '''
out = self.pkgdb.get_packager_stats('pingou')
self.assertEqual(
sorted(out.keys()),
['el5', 'el6', 'epel7', 'f19', 'f20', 'f21', 'master', 'output'])
self.assertEqual(
sorted(out['master'].keys()),
['co-maintainer', 'point of contact'])
self.assertTrue(out['master']['point of contact'] >= 50)
def test_get_packagers(self):
''' Test the get_packagers function. '''
out = self.pkgdb.get_packagers('ping*')
self.assertEqual(
sorted(out.keys()),
['output', 'packagers'])
self.assertEqual(out['packagers'], ['pingou'])
def test_get_packages(self):
''' Test the get_packages function. '''
out = self.pkgdb.get_packages('gua*')
expected_keys = [
'acls', 'creation_date', 'description', 'monitor', 'name',
'review_url', 'status', 'summary', 'upstream_url',
]
self.assertEqual(
sorted(out.keys()),
['output', 'packages', 'page', 'page_total'])
self.assertEqual(len(out['packages']), 10)
self.assertEqual(out['packages'][0]['name'], 'guacamole-client')
self.assertEqual(sorted(out['packages'][0].keys()), expected_keys)
self.assertEqual(out['packages'][1]['name'], 'guacamole-common')
self.assertEqual(out['page'], 1)
self.assertEqual(out['page_total'], 1)
out = self.pkgdb.get_packages('gua*', branches='el6')
self.assertEqual(
sorted(out.keys()),
['output', 'packages', 'page', 'page_total'])
self.assertEqual(len(out['packages']), 7)
self.assertEqual(out['packages'][0]['name'], 'guacamole-common')
self.assertEqual(sorted(out['packages'][0].keys()), expected_keys)
self.assertEqual(out['packages'][1]['name'], 'guacamole-ext')
self.assertEqual(out['page'], 1)
self.assertEqual(out['page_total'], 1)
out = self.pkgdb.get_packages('gua*', poc='pingou')
self.assertEqual(
sorted(out.keys()),
['output', 'packages', 'page', 'page_total'])
self.assertEqual(len(out['packages']), 1)
self.assertEqual(out['packages'][0]['name'], 'guake')
self.assertEqual(sorted(out['packages'][0].keys()), expected_keys)
self.assertEqual(out['page'], 1)
self.assertEqual(out['page_total'], 1)
out = self.pkgdb.get_packages('gua*', status='Retired')
self.assertEqual(
sorted(out.keys()),
['output', 'packages', 'page', 'page_total'])
self.assertEqual(len(out['packages']), 5)
self.assertEqual(out['packages'][0]['name'], 'guacd')
self.assertEqual(sorted(out['packages'][0].keys()), expected_keys)
self.assertEqual(out['page'], 1)
self.assertEqual(out['page_total'], 1)
out = self.pkgdb.get_packages('g*', orphaned=True)
self.assertEqual(
sorted(out.keys()),
['output', 'packages', 'page', 'page_total'])
self.assertTrue(len(out['packages']) >= 44)
self.assertEqual(out['packages'][0]['name'], 'ghex')
self.assertEqual(sorted(out['packages'][0].keys()), expected_keys)
#self.assertEqual(out['packages'][1]['name'], 'glom')
self.assertEqual(out['page'], 1)
self.assertEqual(out['page_total'], 1)
out = self.pkgdb.get_packages('gua*', poc='pingou', acls=True)
self.assertEqual(
sorted(out.keys()),
['output', 'packages', 'page', 'page_total'])
self.assertEqual(len(out['packages']), 1)
self.assertEqual(out['packages'][0]['name'], 'guake')
self.assertEqual(sorted(out['packages'][0].keys()), expected_keys)
self.assertEqual(out['page'], 1)
self.assertEqual(out['page_total'], 1)
out = self.pkgdb.get_packages('g*', page=2)
self.assertEqual(
sorted(out.keys()),
['output', 'packages', 'page', 'page_total'])
self.assertEqual(len(out['packages']), 250)
self.assertEqual(out['packages'][0]['name'], 'ghc-parameterized-data')
self.assertEqual(sorted(out['packages'][0].keys()), expected_keys)
self.assertEqual(out['page'], 2)
self.assertEqual(out['page_total'], 6)
out = self.pkgdb.get_packages('g*', count=True)
self.assertEqual(
sorted(out.keys()),
['output', 'packages', 'page', 'page_total'])
self.assertTrue(out['packages'] >= 1340)
self.assertEqual(out['page'], 1)
self.assertEqual(out['page_total'], 1)
class TestPkgdDBAuth(unittest.TestCase):
''' Authenticated pkgdb2 tests. '''
@auth_only
def setUp(self):
""" set up data used in the tests.
setUp is called before each test function execution.
"""
self.pkgdb = PkgDB(PKGDB_URL, insecure=True)
self.pkgdb.login(USERNAME, PASSWORD)
@auth_only
def test_01_create_collection(self):
''' Test the create_collection function. '''
out = self.pkgdb.create_collection(
clt_name='Test',
version=VERSION,
clt_status='Active',
branchname=COL_NAME,
dist_tag='.tst' + COL_NAME[:20],
git_branch_name='test',
kojiname='test',
)
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['Collection "%s" created' % COL_NAME])
self.assertRaises(
PkgDBException,
self.pkgdb.create_collection,
clt_name='Test',
version=VERSION,
clt_status='Active',
branchname=COL_NAME,
dist_tag='.tst' + COL_NAME[:20],
git_branch_name='test',
kojiname='test',
)
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['Collection "%s" created' % COL_NAME])
@auth_only
def test_02_create_package(self):
''' Test the create_package function. '''
out = self.pkgdb.create_package(
pkgname=PKG_NAME,
summary='Test package',
description='Test package desc',
review_url='https://bz.com',
status='Approved',
shouldopen=False,
branches=COL_NAME,
poc='pingou',
upstream_url='http://guake.org',
critpath=False)
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['Package created'])
@auth_only
def test_03_orphan_packages(self):
''' Test the orphan_packages function. '''
out = self.pkgdb.orphan_packages('guake', ['master', 'el6'])
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['user: pingou changed point of contact of package: guake from: '
'pingou to: orphan on branch: master',
'user: pingou changed point of contact of package: guake from: '
'pingou to: orphan on branch: el6'])
@auth_only
def test_04_unorphan_packages(self):
''' Test the unorphan_packages function. '''
out = self.pkgdb.unorphan_packages(
'guake', ['master', 'el6'], 'pingou')
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['Package guake has been unorphaned on master by pingou',
'Package guake has been unorphaned on el6 by pingou'])
@auth_only
def test_05_retire_packages(self):
''' Test the retire_packages function. '''
out = self.pkgdb.retire_packages('guake', 'master')
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['user: pingou updated package: guake status from: Approved to '
'Retired on branch: master'])
@auth_only
def test_06_unretire_packages(self):
''' Test the unretire_packages function. '''
out = self.pkgdb.unretire_packages('guake', 'master')
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['user: pingou updated package: guake status from: Retired to '
'Approved on branch: master'])
@auth_only
def test_07_update_acl(self):
''' Test the update_acl function. '''
# After un-retiring the package on master, we need to re-set Ralph's
# pending ACL request
out = self.pkgdb.update_acl(
'guake', ['master', 'el6'], 'commit', 'Awaiting Review',
'ralph')
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['user: pingou set for ralph acl: commit of package: guake from: '
'Obsolete to: Awaiting Review on branch: master',
'Nothing to update on branch: el6 for acl: commit'])
# Check the output when we try to change an ACL to what it is already
out = self.pkgdb.update_acl(
'guake', ['master', 'el6'], 'commit', 'Awaiting Review',
'ralph')
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['Nothing to update on branch: master for acl: commit',
'Nothing to update on branch: el6 for acl: commit'])
@auth_only
def test_08_update_collection_status(self):
''' Test the update_collection_status function. '''
out = self.pkgdb.update_collection_status(COL_NAME, 'EOL')
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['Collection updated from "Active" to "EOL"'])
@auth_only
def test_09_update_package_poc(self):
''' Test the update_package_poc function. '''
out = self.pkgdb.update_package_poc(
'guake', ['master', 'el6'], 'ralph')
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['user: pingou changed point of contact of package: guake from: '
'orphan to: ralph on branch: master',
'user: pingou changed point of contact of package: guake from: '
'pingou to: ralph on branch: el6'])
out = self.pkgdb.update_package_poc(
'guake', ['master', 'el6'], 'pingou')
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['user: pingou changed point of contact of package: guake from: '
'ralph to: pingou on branch: master',
'user: pingou changed point of contact of package: guake from: '
'ralph to: pingou on branch: el6'])
@auth_only
def test_10_update_critpath(self):
''' Test the update_critpath function. '''
# Check before changing the critpath
out = self.pkgdb.get_package('guake')
self.assertEqual(
sorted(out.keys()),
['output', 'packages'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(len(out['packages']), 5)
critpaths = [el['critpath'] for el in out['packages']]
branches = [el['collection']['branchname'] for el in out['packages']]
self.assertEqual(
critpaths,
[False, False, False, False, False]
)
self.assertEqual(
branches,
['master', 'el6', 'f19', 'f20', 'f21']
)
out = self.pkgdb.update_critpath(
'guake', ['master', 'el6'], True)
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['guake: critpath updated on master to True',
'guake: critpath updated on el6 to True']
)
# Check after changing the critpath
out = self.pkgdb.get_package('guake')
self.assertEqual(
sorted(out.keys()),
['output', 'packages'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(len(out['packages']), 5)
critpaths = [el['critpath'] for el in out['packages']]
branches = [el['collection']['branchname'] for el in out['packages']]
self.assertEqual(
critpaths,
[True, True, False, False, False]
)
self.assertEqual(
branches,
['master', 'el6', 'f19', 'f20', 'f21']
)
out = self.pkgdb.get_package('guake')
self.assertEqual(
sorted(out.keys()),
['output', 'packages'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(len(out['packages']), 5)
self.assertEqual(
out['packages'][0]['collection']['branchname'], 'master')
self.assertEqual(
out['packages'][0]['package']['name'], 'guake')
self.assertEqual(
out['packages'][0]['point_of_contact'], 'pingou')
out = self.pkgdb.update_critpath(
'guake', ['master', 'el6'], False)
self.assertEqual(
sorted(out.keys()),
['messages', 'output'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(
out['messages'],
['guake: critpath updated on master to False',
'guake: critpath updated on el6 to False']
)
# Check after reste critpath to False
out = self.pkgdb.get_package('guake')
self.assertEqual(
sorted(out.keys()),
['output', 'packages'])
self.assertEqual(out['output'], 'ok')
self.assertEqual(len(out['packages']), 5)
critpaths = [el['critpath'] for el in out['packages']]
branches = [el['collection']['branchname'] for el in out['packages']]
self.assertEqual(
critpaths,
[False, False, False, False, False]
)
self.assertEqual(
branches,
['master', 'el6', 'f19', 'f20', 'f21']
)
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestPkgdDB))
suite.addTest(unittest.makeSuite(TestPkgdDBAuth))
return suite
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())