forked from pycontribs/jira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·1909 lines (1569 loc) · 77.8 KB
/
tests.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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
from __future__ import print_function
import json
import os
import re
import sys
import logging
import getpass
import random
import requests
import string
import traceback
import inspect
import pickle
from time import sleep
import py
import pytest
from six import print_ as print
from six import integer_types, string_types
from requests.exceptions import ConnectionError
# import sys
# from imp import reload
# reload(sys) # Reload does the trick!
# sys.setdefaultencoding('UTF8')
if sys.version_info < (2, 7, 0):
try:
import unittest2 as unittest
except ImportError:
import pip
if hasattr(sys, 'real_prefix'):
pip.main(['install', '--upgrade', 'unittest2'])
else:
pip.main(['install', '--upgrade', '--user', 'unittest2'])
import unittest2 as unittest
else:
import unittest
cmd_folder = os.path.abspath(os.path.join(os.path.split(inspect.getfile(
inspect.currentframe()))[0], ".."))
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)
import jira
from jira import User, Role, Issue, JIRA, JIRAError, Project
from jira.resources import Resource, cls_for_resource
TEST_ROOT = os.path.dirname(__file__)
TEST_ICON_PATH = os.path.join(TEST_ROOT, 'icon.png')
TEST_ATTACH_PATH = os.path.join(TEST_ROOT, 'tests.py')
OAUTH = False
CONSUMER_KEY = 'oauth-consumer'
KEY_CERT_FILE = '/home/bspeakmon/src/atlassian-oauth-examples/rsa.pem'
KEY_CERT_DATA = None
try:
with open(KEY_CERT_FILE, 'r') as cert:
KEY_CERT_DATA = cert.read()
OAUTH = True
except:
pass
def rndstr():
return ''.join(random.sample(string.ascii_letters, 6))
def rndpassword():
# generates a password of lengh 14
s = ''.join(random.sample(string.ascii_uppercase, 5)) +\
''.join(random.sample(string.ascii_lowercase, 5)) +\
''.join(random.sample(string.digits, 2)) +\
''.join(random.sample('~`!@#$%^&*()_+-=[]\\{}|;\':<>?,./', 2))
return ''.join(random.sample(s, len(s)))
class Singleton(type):
def __init__(cls, name, bases, dict):
super(Singleton, cls).__init__(name, bases, dict)
cls.instance = None
def __call__(cls, *args, **kw):
if cls.instance is None:
cls.instance = super(Singleton, cls).__call__(*args, **kw)
return cls.instance
class JiraTestManager(object):
"""
Used to instantiate and populate the JIRA instance with data used by the unit tests.
"""
# __metaclass__ = Singleton
# __instance = None
#
# Singleton implementation
# def __new__(cls, *args, **kwargs):
# if not cls.__instance:
# cls.__instance = super(JiraTestManager, cls).__new__(
# cls, *args, **kwargs)
# return cls.__instance
# Implementing some kind of Singleton, to prevent test initialization
# http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python/33201#33201
__shared_state = {}
def __init__(self):
self.__dict__ = self.__shared_state
if not self.__dict__:
self.initialized = 0
try:
if 'CI_JIRA_URL' in os.environ:
self.CI_JIRA_URL = os.environ['CI_JIRA_URL']
self.max_retries = 5
else:
self.CI_JIRA_URL = "https://pycontribs.atlassian.net"
self.max_retries = 5
if 'CI_JIRA_ADMIN' in os.environ:
self.CI_JIRA_ADMIN = os.environ['CI_JIRA_ADMIN']
else:
self.CI_JIRA_ADMIN = 'ci-admin'
if 'CI_JIRA_ADMIN_PASSWORD' in os.environ:
self.CI_JIRA_ADMIN_PASSWORD = os.environ[
'CI_JIRA_ADMIN_PASSWORD']
else:
self.CI_JIRA_ADMIN_PASSWORD = 'sd4s3dgec5fhg4tfsds3434'
if 'CI_JIRA_USER' in os.environ:
self.CI_JIRA_USER = os.environ['CI_JIRA_USER']
else:
self.CI_JIRA_USER = 'ci-user'
if 'CI_JIRA_USER_PASSWORD' in os.environ:
self.CI_JIRA_USER_PASSWORD = os.environ[
'CI_JIRA_USER_PASSWORD']
else:
self.CI_JIRA_USER_PASSWORD = 'sd4s3dgec5fhg4tfsds3434'
if OAUTH:
self.jira_admin = JIRA(oauth={
'access_token': 'hTxcwsbUQiFuFALf7KZHDaeAJIo3tLUK',
'access_token_secret': 'aNCLQFP3ORNU6WY7HQISbqbhf0UudDAf',
'consumer_key': CONSUMER_KEY,
'key_cert': KEY_CERT_DATA,
})
else:
if self.CI_JIRA_ADMIN:
self.jira_admin = JIRA(self.CI_JIRA_URL, basic_auth=(self.CI_JIRA_ADMIN,
self.CI_JIRA_ADMIN_PASSWORD),
logging=False, validate=True, max_retries=self.max_retries)
else:
self.jira_admin = JIRA(self.CI_JIRA_URL, validate=True,
logging=False, max_retries=self.max_retries)
if self.jira_admin.current_user() != self.CI_JIRA_ADMIN:
# self.jira_admin.
self.initialized = 1
sys.exit(3)
if OAUTH:
self.jira_sysadmin = JIRA(oauth={
'access_token': '4ul1ETSFo7ybbIxAxzyRal39cTrwEGFv',
'access_token_secret':
'K83jBZnjnuVRcfjBflrKyThJa0KSjSs2',
'consumer_key': CONSUMER_KEY,
'key_cert': KEY_CERT_DATA,
}, logging=False, max_retries=self.max_retries)
else:
if self.CI_JIRA_ADMIN:
self.jira_sysadmin = JIRA(self.CI_JIRA_URL,
basic_auth=(self.CI_JIRA_ADMIN,
self.CI_JIRA_ADMIN_PASSWORD),
logging=False, validate=True, max_retries=self.max_retries)
else:
self.jira_sysadmin = JIRA(self.CI_JIRA_URL,
logging=False, max_retries=self.max_retries)
if OAUTH:
self.jira_normal = JIRA(oauth={
'access_token': 'ZVDgYDyIQqJY8IFlQ446jZaURIz5ECiB',
'access_token_secret':
'5WbLBybPDg1lqqyFjyXSCsCtAWTwz1eD',
'consumer_key': CONSUMER_KEY,
'key_cert': KEY_CERT_DATA,
})
else:
if self.CI_JIRA_ADMIN:
self.jira_normal = JIRA(self.CI_JIRA_URL,
basic_auth=(self.CI_JIRA_USER,
self.CI_JIRA_USER_PASSWORD),
validate=True, logging=False, max_retries=self.max_retries)
else:
self.jira_normal = JIRA(self.CI_JIRA_URL,
validate=True, logging=False, max_retries=self.max_retries)
# now we need some data to start with for the tests
# jira project key is max 10 chars, no letter.
# [0] always "Z"
# [1-6] username running the tests (hope we will not collide)
# [7-8] python version A=0, B=1,..
# [9] A,B -- we may need more than one project
prefix = 'Z' + (re.sub("[^A-Z]", "",
getpass.getuser().upper()))[0:6] + \
chr(ord('A') + sys.version_info[0]) + \
chr(ord('A') + sys.version_info[1])
self.project_a = prefix + 'A' # old XSS
self.project_a_name = "Test user=%s python=%s.%s A" \
% (getpass.getuser(), sys.version_info[0],
sys.version_info[1])
self.project_b_name = "Test user=%s python=%s.%s B" \
% (getpass.getuser(), sys.version_info[0],
sys.version_info[1])
self.project_b = prefix + 'B' # old BULK
# TODO: fin a way to prevent SecurityTokenMissing for On Demand
# https://jira.atlassian.com/browse/JRA-39153
try:
self.jira_admin.project(self.project_a)
except Exception as e:
logging.warning(e)
pass
else:
self.jira_admin.delete_project(self.project_a)
try:
self.jira_admin.project(self.project_b)
except Exception as e:
logging.warning(e)
pass
else:
self.jira_admin.delete_project(self.project_b)
# try:
self.jira_admin.create_project(self.project_a,
self.project_a_name)
# except Exception as e:
# logging.warning("Got %s" % e)
# try:
# assert self.jira_admin.create_project(self.project_b,
# self.project_b_name) is True, "Failed to create %s" %
# self.project_b
self.jira_admin.create_project(self.project_b,
self.project_b_name)
# except Exception as e:
# logging.warning("Got %s" % e)
self.project_b_issue1_obj = self.jira_admin.create_issue(project=self.project_b,
summary='issue 1 from %s'
% self.project_b,
issuetype={'name': 'Bug'})
self.project_b_issue1 = self.project_b_issue1_obj.key
self.project_b_issue2_obj = self.jira_admin.create_issue(project=self.project_b,
summary='issue 2 from %s'
% self.project_b,
issuetype={'name': 'Bug'})
self.project_b_issue2 = self.project_b_issue2_obj.key
self.project_b_issue3_obj = self.jira_admin.create_issue(project=self.project_b,
summary='issue 3 from %s'
% self.project_b,
issuetype={'name': 'Bug'})
self.project_b_issue3 = self.project_b_issue3_obj.key
except Exception as e:
# exc_type, exc_value, exc_traceback = sys.exc_info()
formatted_lines = traceback.format_exc().splitlines()
msg = "Basic test setup failed: %s\n\t%s" % (
e, "\n\t".join(formatted_lines))
logging.fatal(msg)
self.initialized = 1
py.test.exit("FATAL")
self.initialized = 1
else:
# already exist but we need to be sure it was initialized
counter = 0
while not self.initialized:
sleep(1)
counter += 1
if counter > 60:
logging.fatal("Something is clearly not right with\
initialization, killing the tests to prevent a\
deadlock.")
sys.exit(3)
def find_by_key(seq, key):
for seq_item in seq:
if seq_item['key'] == key:
return seq_item
def find_by_key_value(seq, key):
for seq_item in seq:
if seq_item.key == key:
return seq_item
def find_by_id(seq, id):
for seq_item in seq:
if seq_item.id == id:
return seq_item
def find_by_name(seq, name):
for seq_item in seq:
if seq_item['name'] == name:
return seq_item
class UniversalResourceTests(unittest.TestCase):
def setUp(self):
self.jira = JiraTestManager().jira_admin
self.test_manager = JiraTestManager()
def test_universal_find_existing_resource(self):
resource = self.jira.find('issue/{0}',
self.test_manager.project_b_issue1)
issue = self.jira.issue(self.test_manager.project_b_issue1)
self.assertEqual(resource.self, issue.self)
self.assertEqual(resource.key, issue.key)
def test_find_invalid_resource_raises_exception(self):
with self.assertRaises(JIRAError) as cm:
self.jira.find('woopsydoodle/{0}', '666')
ex = cm.exception
# py26,27,34 gets 404 but on py33 gets 400
assert ex.status_code in [400, 404]
self.assertIsNotNone(ex.text)
self.assertEqual(ex.url,
'https://pycontribs.atlassian.net/rest/api/2/woopsydoodle/666')
@pytest.mark.xfail
# see https://github.com/pycontribs/jira/pull/30
def test_pickling_resource(self):
resource = self.jira.find('issue/{0}',
self.test_manager.project_b_issue1)
pickled = pickle.dumps(resource)
unpickled = pickle.loads(pickled)
self.assertEqual(resource.key, unpickled.key)
class ResourceTests(unittest.TestCase):
def setUp(self):
pass
def test_cls_for_resource(self):
self.assertEqual(cls_for_resource('https://jira.atlassian.com/rest/\
api/2/issue/JRA-1330'), Issue)
self.assertEqual(cls_for_resource('http://localhost:2990/jira/rest/\
api/2/project/BULK'), Project)
self.assertEqual(cls_for_resource('http://imaginary-jira.com/rest/\
api/2/project/IMG/role/10002'), Role)
self.assertEqual(cls_for_resource('http://customized-jira.com/rest/\
plugin-resource/4.5/json/getMyObject'), Resource)
class ApplicationPropertiesTests(unittest.TestCase):
def setUp(self):
self.jira = JiraTestManager().jira_admin
def test_application_properties(self):
props = self.jira.application_properties()
self.assertEqual(len(props), 30)
def test_application_property(self):
clone_prefix = self.jira.application_properties(
key='jira.lf.text.headingcolour')
self.assertEqual(clone_prefix['value'], '#292929')
def test_set_application_property(self):
prop = 'jira.lf.favicon.hires.url'
valid_value = '/jira-favicon-hires.png'
invalud_value = '/Tjira-favicon-hires.png'
counter = 0
while self.jira.application_properties(key=prop)['value'] != valid_value and conter < 3:
if counter:
sleep(10)
self.jira.set_application_property(prop, invalid_value)
self.assertEqual(self.jira.application_properties(key=prop)['value'],
invalid_value)
self.jira.set_application_property(prop, valid_value)
self.assertEqual(self.jira.application_properties(key=prop)['value'],
valid_value)
counter += 1
def test_setting_bad_property_raises(self):
prop = 'random.nonexistent.property'
self.assertRaises(JIRAError, self.jira.set_application_property, prop,
'666')
class AttachmentTests(unittest.TestCase):
def setUp(self):
self.test_manager = JiraTestManager()
self.jira = JiraTestManager().jira_admin
self.project_b = self.test_manager.project_b
self.issue_1 = self.test_manager.project_b_issue1
self.attachment = None
def test_0_attachment_meta(self):
meta = self.jira.attachment_meta()
self.assertTrue(meta['enabled'])
self.assertEqual(meta['uploadLimit'], 10485760)
def test_1_add_remove_attachment(self):
issue = self.jira.issue(self.issue_1)
self.attachment = self.jira.add_attachment(issue, open(TEST_ATTACH_PATH, 'rb'),
"new test attachment")
new_attachment = self.jira.attachment(self.attachment.id)
msg = "attachment %s of issue %s" % (new_attachment.__dict__, issue)
self.assertEqual(
new_attachment.filename, 'new test attachment', msg=msg)
self.assertEqual(
new_attachment.size, os.path.getsize(TEST_ATTACH_PATH), msg=msg)
assert self.attachment.delete() is None
class ComponentTests(unittest.TestCase):
def setUp(self):
self.test_manager = JiraTestManager()
self.jira = JiraTestManager().jira_admin
self.project_b = self.test_manager.project_b
self.issue_1 = self.test_manager.project_b_issue1
self.issue_2 = self.test_manager.project_b_issue2
def test_2_create_component(self):
proj = self.jira.project(self.project_b)
name = "project-%s-component-%s" % (proj, rndstr())
component = self.jira.create_component(name,
proj, description='test!!', assigneeType='COMPONENT_LEAD',
isAssigneeTypeValid=False)
self.assertEqual(component.name, name)
self.assertEqual(component.description, 'test!!')
self.assertEqual(component.assigneeType, 'COMPONENT_LEAD')
self.assertFalse(component.isAssigneeTypeValid)
component.delete()
for c in self.jira.project_components(self.project_b):
print(x)
# COmponents field can't be modified from issue.update
# def test_component_count_related_issues(self):
# component = self.jira.create_component('PROJECT_B_TEST',self.project_b, description='test!!',
# assigneeType='COMPONENT_LEAD', isAssigneeTypeValid=False)
# issue1 = self.jira.issue(self.issue_1)
# issue2 = self.jira.issue(self.issue_2)
# (issue1.update ({'components': ['PROJECT_B_TEST']}))
# (issue2.update (components = ['PROJECT_B_TEST']))
# issue_count = self.jira.component_count_related_issues(component.id)
# self.assertEqual(issue_count, 2)
# component.delete()
def test_3_update(self):
try:
components = self.jira.project_components(self.project_b)
for component in components:
if component.name == 'To be updated':
component.delete()
break
except Exception as e:
# We ignore errors as this code intends only to prepare for
# component creation
pass
name = 'component-' + rndstr()
component = self.jira.create_component(name,
self.project_b, description='stand by!',
leadUserName='ci-admin')
name = 'renamed-' + name
component.update(name=name, description='It is done.',
leadUserName='ci-admin')
self.assertEqual(component.name, name)
self.assertEqual(component.description, 'It is done.')
self.assertEqual(component.lead.name, 'ci-admin')
component.delete()
def test_4_delete(self):
component = self.jira.create_component('To be deleted',
self.project_b, description='not long for this world')
myid = component.id
component.delete()
self.assertRaises(JIRAError, self.jira.component, myid)
class CustomFieldOptionTests(unittest.TestCase):
def setUp(self):
self.jira = JiraTestManager().jira_admin
def test_custom_field_option(self):
option = self.jira.custom_field_option('10001')
self.assertEqual(option.value, 'To Do')
class DashboardTests(unittest.TestCase):
def setUp(self):
self.jira = JiraTestManager().jira_admin
def test_dashboards(self):
dashboards = self.jira.dashboards()
self.assertEqual(len(dashboards), 3)
def test_dashboards_filter(self):
dashboards = self.jira.dashboards(filter='my')
self.assertEqual(len(dashboards), 2)
self.assertEqual(dashboards[0].id, '10101')
def test_dashboards_startat(self):
dashboards = self.jira.dashboards(startAt=1, maxResults=1)
self.assertEqual(len(dashboards), 1)
def test_dashboards_maxresults(self):
dashboards = self.jira.dashboards(maxResults=1)
self.assertEqual(len(dashboards), 1)
def test_dashboard(self):
dashboard = self.jira.dashboard('10101')
self.assertEqual(dashboard.id, '10101')
self.assertEqual(dashboard.name, 'Another test dashboard')
class FieldsTests(unittest.TestCase):
def setUp(self):
self.jira = JiraTestManager().jira_admin
def test_fields(self):
fields = self.jira.fields()
self.assertGreater(len(fields), 10)
class FilterTests(unittest.TestCase):
def setUp(self):
self.test_manager = JiraTestManager()
self.jira = JiraTestManager().jira_admin
self.project_b = self.test_manager.project_b
self.issue_1 = self.test_manager.project_b_issue1
self.issue_2 = self.test_manager.project_b_issue2
def test_filter(self):
jql = "project = %s and component is not empty" % self.project_b
name = 'same filter ' + rndstr()
myfilter = self.jira.create_filter(name=name,
description="just some new test filter", jql=jql,
favourite=False)
self.assertEqual(myfilter.name, name)
self.assertEqual(myfilter.owner.name, 'ci-admin')
myfilter.delete()
def test_favourite_filters(self):
# filters = self.jira.favourite_filters()
jql = "project = %s and component is not empty" % self.project_b
name = "filter-to-fav-" + rndstr()
myfilter = self.jira.create_filter(name=name,
description="just some new test filter", jql=jql,
favourite=True)
new_filters = self.jira.favourite_filters()
assert name in [f.name for f in new_filters]
myfilter.delete()
class GroupsTest(unittest.TestCase):
def setUp(self):
self.jira = JiraTestManager().jira_admin
def test_groups(self):
groups = self.jira.groups()
self.assertGreater(len(groups), 0)
def test_groups_for_users(self):
groups = self.jira.groups('jira-users')
self.assertGreater(len(groups), 0)
class IssueTests(unittest.TestCase):
def setUp(self):
self.test_manager = JiraTestManager()
self.jira = JiraTestManager().jira_admin
self.jira_normal = self.test_manager.jira_normal
self.project_b = self.test_manager.project_b
self.project_a = self.test_manager.project_a
self.issue_1 = self.test_manager.project_b_issue1
self.issue_2 = self.test_manager.project_b_issue2
self.issue_3 = self.test_manager.project_b_issue3
def test_issue(self):
issue = self.jira.issue(self.issue_1)
self.assertEqual(issue.key, self.issue_1)
self.assertEqual(issue.fields.summary,
'issue 1 from %s' % self.project_b)
@unittest.skip("disabled as it seems to be ignored by jira, returning all")
def test_issue_field_limiting(self):
issue = self.jira.issue(self.issue_2, fields='summary,comment')
self.assertEqual(issue.fields.summary,
'issue 2 from %s' % self.project_b)
comment1 = self.jira.add_comment(issue, 'First comment')
comment2 = self.jira.add_comment(issue, 'Second comment')
comment3 = self.jira.add_comment(issue, 'Third comment')
self.jira.issue(self.issue_2, fields='summary,comment')
logging.warning(issue.raw['fields'])
self.assertFalse(hasattr(issue.fields, 'reporter'))
self.assertFalse(hasattr(issue.fields, 'progress'))
comment1.delete()
comment2.delete()
comment3.delete()
def test_issue_equal(self):
issue1 = self.jira.issue(self.issue_1)
issue2 = self.jira.issue(self.issue_2)
issues = self.jira.search_issues('key=%s' % self.issue_1)
self.assertTrue(issue1 == issues[0])
self.assertFalse(issue2 == issues[0])
def test_issue_expandos(self):
issue = self.jira.issue(self.issue_1, expand='editmeta,schema')
self.assertTrue(hasattr(issue, 'editmeta'))
self.assertTrue(hasattr(issue, 'schema'))
# testing for changelog is not reliable because it may exist or not based on test order
#self.assertFalse(hasattr(issue, 'changelog'))
def test_create_issue_with_fieldargs(self):
issue = self.jira.create_issue(project=self.project_b,
summary='Test issue created', description='blahery',
issuetype={'name': 'Bug'}, customfield_10022='XSS')
self.assertEqual(issue.fields.summary, 'Test issue created')
self.assertEqual(issue.fields.description, 'blahery')
self.assertEqual(issue.fields.issuetype.name, 'Bug')
self.assertEqual(issue.fields.project.key, self.project_b)
self.assertEqual(issue.fields.customfield_10022, 'XSS')
issue.delete()
def test_create_issue_with_fielddict(self):
fields = {
'project': {
'key': self.project_b
},
'summary': 'Issue created from field dict',
'description': "Some new issue for test",
'issuetype': {
'name': 'Bug'
},
'customfield_10022': 'XSS',
'priority': {
'name': 'Major'
}
}
issue = self.jira.create_issue(fields=fields)
self.assertEqual(issue.fields.summary,
'Issue created from field dict')
self.assertEqual(issue.fields.description, "Some new issue for test")
self.assertEqual(issue.fields.issuetype.name, 'Bug')
self.assertEqual(issue.fields.project.key, self.project_b)
self.assertEqual(issue.fields.customfield_10022, 'XSS')
self.assertEqual(issue.fields.priority.name, 'Major')
issue.delete()
def test_create_issue_without_prefetch(self):
issue = self.jira.create_issue(prefetch=False,
project=self.project_b,
summary='Test issue created',
description='blahery', issuetype={'name': 'Bug'},
customfield_10022='XSS')
assert hasattr(issue, 'self')
assert hasattr(issue, 'raw')
assert 'fields' not in issue.raw
issue.delete()
def test_update_with_fieldargs(self):
issue = self.jira.create_issue(project=self.project_b,
summary='Test issue for updating',
description='Will be updated shortly',
issuetype={'name': 'Bug'},
customfield_10022='XSS')
issue.update(summary='Updated summary', description='Now updated',
issuetype={'name': 'Improvement'})
self.assertEqual(issue.fields.summary, 'Updated summary')
self.assertEqual(issue.fields.description, 'Now updated')
self.assertEqual(issue.fields.issuetype.name, 'Improvement')
self.assertEqual(issue.fields.customfield_10022, 'XSS')
self.assertEqual(issue.fields.project.key, self.project_b)
issue.delete()
def test_update_with_fielddict(self):
issue = self.jira.create_issue(project=self.project_b,
summary='Test issue for updating', description='Will be updated shortly',
issuetype={'name': 'Bug'},
customfield_10022='XSS')
fields = {
'summary': 'Issue is updated',
'description': "it sure is",
'issuetype': {
'name': 'Improvement'
},
'customfield_10022': 'DOC',
'priority': {
'name': 'Major'
}
}
issue.update(fields=fields)
self.assertEqual(issue.fields.summary, 'Issue is updated')
self.assertEqual(issue.fields.description, 'it sure is')
self.assertEqual(issue.fields.issuetype.name, 'Improvement')
self.assertEqual(issue.fields.customfield_10022, 'DOC')
self.assertEqual(issue.fields.priority.name, 'Major')
issue.delete()
def test_update_with_label(self):
issue = self.jira.create_issue(project=self.project_b,
summary='Test issue for updating labels', description='Label testing',
issuetype={'name': 'Bug'})
labelarray = ['testLabel']
fields = {
'labels': labelarray
}
issue.update(fields=fields)
self.assertEqual(issue.fields.labels, ['testLabel'])
def test_update_with_bad_label(self):
issue = self.jira.create_issue(project=self.project_b,
summary='Test issue for updating labels', description='Label testing',
issuetype={'name': 'Bug'})
issue.fields.labels.append('this should not work')
fields = {
'labels': issue.fields.labels
}
self.assertRaises(JIRAError, issue.update, fields=fields)
def test_delete(self):
issue = self.jira.create_issue(project=self.project_b,
summary='Test issue created',
description='Not long for this world',
issuetype={'name': 'Bug'},
customfield_10022='XSS')
key = issue.key
issue.delete()
self.assertRaises(JIRAError, self.jira.issue, key)
def test_createmeta(self):
meta = self.jira.createmeta()
ztravisdeb_proj = find_by_key(meta['projects'], self.project_b)
self.assertEqual(len(ztravisdeb_proj['issuetypes']), 8)
def test_createmeta_filter_by_projectkey_and_name(self):
meta = self.jira.createmeta(projectKeys=self.project_b,
issuetypeNames='Bug')
self.assertEqual(len(meta['projects']), 1)
self.assertEqual(len(meta['projects'][0]['issuetypes']), 1)
def test_createmeta_filter_by_projectkeys_and_name(self):
meta = self.jira.createmeta(projectKeys=(self.project_a,
self.project_b), issuetypeNames='Improvement')
self.assertEqual(len(meta['projects']), 2)
for project in meta['projects']:
self.assertEqual(len(project['issuetypes']), 1)
def test_createmeta_filter_by_id(self):
projects = self.jira.projects()
proja = find_by_key_value(projects, self.project_a)
projb = find_by_key_value(projects, self.project_b)
meta = self.jira.createmeta(projectIds=(proja.id, projb.id),
issuetypeIds=('3', '4', '5'))
self.assertEqual(len(meta['projects']), 2)
for project in meta['projects']:
self.assertEqual(len(project['issuetypes']), 3)
def test_createmeta_expando(self):
# limit to SCR project so the call returns promptly
meta = self.jira.createmeta(projectKeys=self.project_b,
expand='projects.issuetypes.fields')
self.assertTrue('fields' in meta['projects'][0]['issuetypes'][0])
def test_assign_issue(self):
self.assertIsNone(self.jira.assign_issue(self.issue_1, 'ci-admin'))
self.assertEqual(self.jira.issue(self.issue_1).fields.assignee.name,
'ci-admin')
def test_assign_issue_with_issue_obj(self):
issue = self.jira.issue(self.issue_1)
self.assertIsNone(self.jira.assign_issue(issue, 'ci-admin'))
self.assertEqual(self.jira.issue(self.issue_1).fields.assignee.name,
'ci-admin')
def test_assign_to_bad_issue_raises(self):
self.assertRaises(JIRAError, self.jira.assign_issue, 'NOPE-1',
'notauser')
def test_comments(self):
for issue in [self.issue_1, self.jira.issue(self.issue_2)]:
self.jira.issue(issue)
comment1 = self.jira.add_comment(issue, 'First comment')
comment2 = self.jira.add_comment(issue, 'Second comment')
comments = self.jira.comments(issue)
assert comments[0].body == 'First comment'
assert comments[1].body == 'Second comment'
comment1.delete()
comment2.delete()
comments = self.jira.comments(issue)
assert len(comments) == 0
def test_add_comment(self):
comment = self.jira.add_comment(self.issue_3, 'a test comment!',
visibility={'type': 'role', 'value': 'Administrators'})
self.assertEqual(comment.body, 'a test comment!')
self.assertEqual(comment.visibility.type, 'role')
self.assertEqual(comment.visibility.value, 'Administrators')
comment.delete()
def test_add_comment_with_issue_obj(self):
issue = self.jira.issue(self.issue_3)
comment = self.jira.add_comment(issue, 'a new test comment!',
visibility={'type': 'role', 'value': 'Administrators'})
self.assertEqual(comment.body, 'a new test comment!')
self.assertEqual(comment.visibility.type, 'role')
self.assertEqual(comment.visibility.value, 'Administrators')
comment.delete()
def test_update_comment(self):
comment = self.jira.add_comment(self.issue_3, 'updating soon!')
comment.update(body='updated!')
self.assertEqual(comment.body, 'updated!')
# self.assertEqual(comment.visibility.type, 'role')
# self.assertEqual(comment.visibility.value, 'Administrators')
comment.delete()
def test_editmeta(self):
meta = self.jira.editmeta(self.issue_1)
self.assertEqual(len(meta['fields']), 18)
self.assertTrue('customfield_10007' in meta['fields'])
self.assertTrue('customfield_10022' in meta['fields'])
def test_editmeta_with_issue_obj(self):
issue = self.jira.issue(self.issue_2)
meta = self.jira.editmeta(issue)
self.assertEqual(len(meta['fields']), 18)
self.assertTrue('customfield_10022' in meta['fields'])
self.assertTrue('customfield_10007' in meta['fields'])
# Nothing from remote link works
# def test_remote_links(self):
# self.jira.add_remote_link ('ZTRAVISDEB-3', globalId='python-test:story.of.horse.riding',
# links = self.jira.remote_links('QA-44')
# self.assertEqual(len(links), 1)
# links = self.jira.remote_links('BULK-1')
# self.assertEqual(len(links), 0)
#
# @unittest.skip("temporary disabled")
# def test_remote_links_with_issue_obj(self):
# issue = self.jira.issue('QA-44')
# links = self.jira.remote_links(issue)
# self.assertEqual(len(links), 1)
# issue = self.jira.issue('BULK-1')
# links = self.jira.remote_links(issue)
# self.assertEqual(len(links), 0)
#
# @unittest.skip("temporary disabled")
# def test_remote_link(self):
# link = self.jira.remote_link('QA-44', '10000')
# self.assertEqual(link.id, 10000)
# self.assertTrue(hasattr(link, 'globalId'))
# self.assertTrue(hasattr(link, 'relationship'))
#
# @unittest.skip("temporary disabled")
# def test_remote_link_with_issue_obj(self):
# issue = self.jira.issue('QA-44')
# link = self.jira.remote_link(issue, '10000')
# self.assertEqual(link.id, 10000)
# self.assertTrue(hasattr(link, 'globalId'))
# self.assertTrue(hasattr(link, 'relationship'))
#
# @unittest.skip("temporary disabled")
# def test_add_remote_link(self):
# link = self.jira.add_remote_link('BULK-3', globalId='python-test:story.of.horse.riding',
# object={'url': 'http://google.com', 'title': 'googlicious!'},
# application={'name': 'far too silly', 'type': 'sketch'}, relationship='mousebending')
# creation response doesn't include full remote link info, so we fetch it again using the new internal ID
# link = self.jira.remote_link('BULK-3', link.id)
# self.assertEqual(link.application.name, 'far too silly')
# self.assertEqual(link.application.type, 'sketch')
# self.assertEqual(link.object.url, 'http://google.com')
# self.assertEqual(link.object.title, 'googlicious!')
# self.assertEqual(link.relationship, 'mousebending')
# self.assertEqual(link.globalId, 'python-test:story.of.horse.riding')
#
# @unittest.skip("temporary disabled")
# def test_add_remote_link_with_issue_obj(self):
# issue = self.jira.issue('BULK-3')
# link = self.jira.add_remote_link(issue, globalId='python-test:story.of.horse.riding',
# object={'url': 'http://google.com', 'title': 'googlicious!'},
# application={'name': 'far too silly', 'type': 'sketch'}, relationship='mousebending')
# creation response doesn't include full remote link info, so we fetch it again using the new internal ID
# link = self.jira.remote_link(issue, link.id)
# self.assertEqual(link.application.name, 'far too silly')
# self.assertEqual(link.application.type, 'sketch')
# self.assertEqual(link.object.url, 'http://google.com')
# self.assertEqual(link.object.title, 'googlicious!')
# self.assertEqual(link.relationship, 'mousebending')
# self.assertEqual(link.globalId, 'python-test:story.of.horse.riding')
#
# @unittest.skip("temporary disabled")
# def test_update_remote_link(self):
# link = self.jira.add_remote_link('BULK-3', globalId='python-test:story.of.horse.riding',
# object={'url': 'http://google.com', 'title': 'googlicious!'},
# application={'name': 'far too silly', 'type': 'sketch'}, relationship='mousebending')
# creation response doesn't include full remote link info, so we fetch it again using the new internal ID
# link = self.jira.remote_link('BULK-3', link.id)
# link.update(object={'url': 'http://yahoo.com', 'title': 'yahooery'}, globalId='python-test:updated.id',
# relationship='cheesing')
# self.assertEqual(link.globalId, 'python-test:updated.id')
# self.assertEqual(link.relationship, 'cheesing')
# self.assertEqual(link.object.url, 'http://yahoo.com')
# self.assertEqual(link.object.title, 'yahooery')
# link.delete()
#
# @unittest.skip("temporary disabled")
# def test_delete_remove_link(self):
# link = self.jira.add_remote_link('BULK-3', globalId='python-test:story.of.horse.riding',
# object={'url': 'http://google.com', 'title': 'googlicious!'},
# application={'name': 'far too silly', 'type': 'sketch'}, relationship='mousebending')
# _id = link.id
# link.delete()
# self.assertRaises(JIRAError, self.jira.remote_link, 'BULK-3', _id)
def test_transitions(self):
transitions = self.jira.transitions(self.issue_2)
self.assertEqual(len(transitions), 3)
def test_transitions_with_issue_obj(self):
issue = self.jira.issue(self.issue_2)
transitions = self.jira.transitions(issue)
self.assertEqual(len(transitions), 3)
def test_transition(self):
transition = self.jira.transitions(self.issue_2, '5')
self.assertEqual(transition[0]['name'], 'Resolve Issue')
def test_transition_expand(self):
transition = self.jira.transitions(self.issue_2, '5',
expand='transitions.fields')
self.assertTrue('fields' in transition[0])
def test_transition_issue_with_fieldargs(self):
issue = self.jira.create_issue(project=self.project_b,
summary='Test issue for transition created',
description='blahery', issuetype={'name': 'Bug'},
customfield_10022='XSS')
self.jira.transition_issue(issue.key, '2',
assignee={'name': 'ci-admin'})
issue = self.jira.issue(issue.key)
self.assertEqual(issue.fields.assignee.name, 'ci-admin')
self.assertEqual(issue.fields.status.id, '6') # issue 'Closed'
def test_transition_issue_obj_with_fieldargs(self):
issue = self.jira.create_issue(project=self.project_b,
summary='Test issue for transition created',
description='blahery',
issuetype={'name': 'Bug'},
customfield_10022='XSS')
self.jira.transition_issue(issue, '2', assignee={'name': 'ci-admin'})
issue = self.jira.issue(issue.key)
self.assertEqual(issue.fields.assignee.name, 'ci-admin')
self.assertEqual(issue.fields.status.id, '6')
def test_transition_issue_with_fielddict(self):
issue = self.jira.create_issue(project=self.project_b,
summary='Test issue for transition created',