Repository navigation
Expand file tree
/
Copy pathtestrail.py
More file actions
3292 lines (2668 loc) · 108 KB
/
Copy pathtestrail.py
File metadata and controls
3292 lines (2668 loc) · 108 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
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
# -*- coding:utf-8 -*-
"""
A high-level interface to Testrail API.
This is not a complete implementation of API methods provided by Testrail in
documentation here: http://docs.gurock.com/testrail-api2/start
I was creating a library useful for scripting. Many operations should not be
perform via scripts. For example managing suite structure is easier in
user interface. Also bulk methods provided by API is quite useless in script,
which can easily do bulk operations itself. So I did not implement some methods
to keep it simple.
One thing to remember = this module is not designed for long-time work, it is
for single-run scripts. So it will be better to re-run entire script rather
than do something in endless loop.
"""
#TODO: Previous versions support
#TODO: Test Plan full support
from __future__ import absolute_import
from __future__ import print_function
import time
import datetime
import json
from collections import defaultdict
try:
import requests
import requests.auth as auth
except ImportError:
raise RuntimeError('Module "requests" is required.')
__author__ = 'Vyacheslav Spiridonov'
__version__ = '0.1.0'
__maintainer__ = 'Vyacheslav Spiridonov'
__email__ = 'namelessorama@gmail.com'
__status__ = 'Development'
################################################################################
# Exceptions
################################################################################
class NotFound(Exception):
"""
Will be raised when request results to 400 code on server, meaning there is
no object with requested parameters.
"""
pass
class AccessDenied(Exception):
"""
Will be raised when request results to 403 code on server, meaning you don`t
have required permissions.
"""
pass
################################################################################
# Service Classes
################################################################################
class _Comparable(object):
def __lt__(self, other):
# Override me
raise NotImplementedError
def __eq__(self, other):
return not self < other and not other < self
def __ne__(self, other):
return self < other or other < self
def __gt__(self, other):
return other < self
def __ge__(self, other):
return not self < other
def __le__(self, other):
return not other < self
class _TestrailObject(object):
cache = None
def __init__(self, attributes):
"""
:arg attributes: dictionary of object fields (attributes)
:type attributes: dict
"""
self.id = None
self._settle_attributes(attributes)
# store links to the object in cache
self.cache[self.id] = self
def _settle_attributes(self, attributes):
raise NotImplementedError
def __str__(self):
return '<%s object [%s]>' % (self.__class__.__name__, self.id)
class _CustomField(object):
def __init__(self):
self.configs = []
def present_in_project(self, project_id):
"""
Return True if this field is applicable to provided project_id,
False otherwise
"""
for config in self.configs:
if project_id in config.project_ids:
return True
return False
################################################################################
# Main Class
################################################################################
class Testrail(object):
"""
Main class for testrail communication.
Start with initializing this class, this will configuring your testrail
connection.
"""
session = requests.Session()
base_url = ''
version = (4, 0)
def __init__(self,
host='', port='80',
user='', password='',
compatibility=(4, 0)):
Testrail.base_url = 'http://%s:%s/testrail/index.php?api/v2/' % (
host,
port
)
Testrail.session.headers.update({
'Content-Type': 'application/json'
})
Testrail.session.auth = auth.HTTPBasicAuth(user, password)
Testrail.version = compatibility
############################################################################
# Shortcuts to access API by relative path and do common error processing
@staticmethod
def get(url, **kwargs):
print('GET ', url, kwargs) # debug
result = Testrail.session.get(Testrail.base_url + url, **kwargs)
if result.status_code == 200:
return json.loads(result.text)
elif result.status_code == 400:
raise NotFound(json.loads(result.text)['error'])
elif result.status_code == 403:
raise AccessDenied(json.loads(result.text)['error'])
else:
return defaultdict(lambda: None)
@staticmethod
def post(url, data=None, **kwargs):
print('POST', url, kwargs) # debug
if data is not None:
result = Testrail.session.post(Testrail.base_url + url,
data=json.dumps(data),
**kwargs)
else:
result = Testrail.session.post(Testrail.base_url + url,
**kwargs)
if result.status_code == 200:
return json.loads(result.text)
elif result.status_code == 400:
raise NotFound(json.loads(result.text)['error'])
elif result.status_code == 403:
raise AccessDenied(json.loads(result.text)['error'])
else:
return defaultdict(lambda: None)
############################################################################
# Common Logic to work with read-only objects (Users, Priorities,
# Test Statuses, Case Types, Case Fields and Result Fields)
#
# 1. Objects are loaded from server all at once when any of them required.
# 2. And stay in memory to the end of the script.
# 3. No reload attempts will be made
@staticmethod
def _get_objects_list(object_class):
if object_class.cache is not None:
return object_class.cache.values()
else:
object_class.cache = {}
return object_class.get_all()
@staticmethod
def _get_object_from_list(object_class,
search_attribute, search_value):
for item in Testrail._get_objects_list(object_class):
if getattr(item, search_attribute) == search_value:
return item
raise NotFound('No %s with %s: %s' % (object_class.__name__,
search_attribute,
search_value))
############################################################################
# User methods
@staticmethod
def users():
"""
Get list of all testrail users.
:rtype: list of [User]
"""
return Testrail._get_objects_list(User)
@staticmethod
def get_user_by_id(user_id):
"""
:type user_id: int
:rtype: User
"""
return Testrail._get_object_from_list(User, 'id', user_id)
@staticmethod
def get_user_by_name(user_name):
"""
:type user_name: str
:rtype: User
"""
return Testrail._get_object_from_list(User, 'name', user_name)
@staticmethod
def get_user_by_email(user_email):
"""
:type user_email: str
:rtype: User
"""
return Testrail._get_object_from_list(User, 'email', user_email)
############################################################################
# Priority methods
@staticmethod
def priorities():
"""
Get list of all configured priorities.
:rtype: list of [Priority]
"""
return Testrail._get_objects_list(Priority)
@staticmethod
def get_priority_by_id(priority_id):
"""
:type priority_id: int
:rtype: Priority
"""
return Testrail._get_object_from_list(Priority, 'id', priority_id)
@staticmethod
def get_priority_by_name(priority_name):
"""
:arg priority_name: A short_name (abbreviation) of the priority.
:type priority_name: str
:rtype: Priority
"""
return Testrail._get_object_from_list(Priority, 'short_name',
priority_name)
@staticmethod
def get_priority_by_value(priority_value):
"""
:type priority_value: int
:rtype: Priority
"""
return Testrail._get_object_from_list(Priority, 'priority',
priority_value)
############################################################################
# Test Status methods
@staticmethod
def statuses():
"""
Returns a list of all active test statuses.
:rtype: list of [Status]
"""
return Testrail._get_objects_list(Status)
@staticmethod
def get_status_by_id(status_id):
"""
:type status_id: int
:rtype: Status
"""
return Testrail._get_object_from_list(Status, 'id', status_id)
@staticmethod
def get_status_by_name(status_name):
"""
:arg status_name: a Label (human name) of the status.
:type status_name: str
:rtype: Status
"""
return Testrail._get_object_from_list(Status, 'label', status_name)
############################################################################
# Case Type methods
@staticmethod
def case_types():
"""
Returns a list of available case types.
:rtype: list of [CaseType]
"""
return Testrail._get_objects_list(CaseType)
@staticmethod
def get_case_type_by_id(case_type_id):
"""
:type case_type_id: int
:rtype: CaseType
"""
return Testrail._get_object_from_list(CaseType, 'id', case_type_id)
@staticmethod
def get_case_type_by_name(case_type_name):
"""
:type case_type_name: str
:rtype: CaseType
"""
return Testrail._get_object_from_list(CaseType, 'name', case_type_name)
############################################################################
# Case Field methods
@staticmethod
def case_fields():
"""
Returns a list of all case custom fields.
:rtype: list of [CaseField]
"""
return Testrail._get_objects_list(CaseField)
@staticmethod
def get_case_field_by_id(case_field_id):
"""
:type case_field_id: int
:rtype: CaseField
"""
return Testrail._get_object_from_list(CaseField, 'id', case_field_id)
@staticmethod
def get_case_field_by_name(case_field_name):
"""
:arg case_field_name: a Label of the field (used in the user interface)
:type case_field_name: str
:rtype: CaseField
"""
return Testrail._get_object_from_list(CaseField, 'label',
case_field_name)
############################################################################
# Result Field methods
@staticmethod
def result_fields():
"""
Returns a list of all result custom fields.
:rtype: list of [ResultField]
"""
return Testrail._get_objects_list(ResultField)
@staticmethod
def get_result_field_by_id(result_field_id):
"""
:type result_field_id: int
:rtype: ResultField
"""
return Testrail._get_object_from_list(ResultField, 'id',
result_field_id)
@staticmethod
def get_result_field_by_name(result_field_name):
"""
:arg result_field_name: a Label of the field (used in the user
interface)
:type result_field_name: str
:rtype: ResultField
"""
return Testrail._get_object_from_list(ResultField, 'label',
result_field_name)
############################################################################
# Common Logic to work with read-write objects (Projects, Milestones,
# Suites, Sections, Runs, Plans, Runs, Tests and Results)
#
# 1. Requests for a list of objects always is forwarded to server.
# 2. All loaded objects go to the cache.
# 3. When single object is requested - cache is checked first.
@staticmethod
def _get_object_by_id(object_class, object_id):
try:
return object_class.cache[object_id]
except KeyError:
return object_class.get_one(object_id)
############################################################################
# Project methods
@staticmethod
def projects(is_completed=None):
"""
Get list of projects.
:arg is_completed: True - to return only completed projects.
False - only incomplete.
None - return all projects.
:type is_completed: bool
:rtype: list of [Project]
"""
return [Project(p) for p in TestrailAPI.get_projects(is_completed)]
@staticmethod
def get_project_by_id(project_id):
"""
:type project_id: int
:rtype: Project
"""
return Testrail._get_object_by_id(Project, project_id)
@staticmethod
def get_project_by_name(project_name):
"""
:type project_name: str
:rtype: Project
"""
for p in Testrail.projects():
if p.name == project_name:
return p
raise NotFound('No Project with name: %s' % project_name)
@staticmethod
def add_project(name, announcement='', show_announcement=False,
suite_mode=3):
"""
Creates new project.
Returns newly created project object.
:arg name: Name of new project
:arg announcement: Announcement/Description of new project
:arg show_announcement: True to show the announcement/description on
project page and false otherwise
:arg suite_mode: The suite mode of the project:
1 - single suite mode
2 - single suite + baselines mode
3 - multiple suites mode
:type name: str
:type announcement: str
:type show_announcement: bool
:type suite_mode: int
:rtype: Project
"""
return Project(TestrailAPI.add_project(name=name,
announcement=announcement,
show_announcement=show_announcement,
suite_mode=suite_mode))
############################################################################
# Direct access by object ID
@staticmethod
def get_suite_by_id(suite_id):
"""
:type suite_id: int
:rtype: Suite
"""
return Testrail._get_object_by_id(Suite,
suite_id)
@staticmethod
def get_milestone_by_id(milestone_id):
"""
:type milestone_id: int
:rtype: Milestone
"""
return Testrail._get_object_by_id(Milestone,
milestone_id)
@staticmethod
def get_section_by_id(section_id):
"""
:type section_id: int
:rtype: Section
"""
return Testrail._get_object_by_id(Section,
section_id)
@staticmethod
def get_case_by_id(case_id):
"""
:type case_id: int
:rtype: Case
"""
return Testrail._get_object_by_id(Case,
case_id)
@staticmethod
def get_plan_by_id(plan_id):
"""
:type plan_id: int
:rtype: Plan
"""
return Testrail._get_object_by_id(Plan,
plan_id)
@staticmethod
def get_run_by_id(run_id):
"""
:type run_id: int
:rtype: Run
"""
return Testrail._get_object_by_id(Run,
run_id)
@staticmethod
def get_test_by_id(test_id):
"""
:type test_id: int
:rtype: Test
"""
return Testrail._get_object_by_id(Test,
test_id)
################################################################################
# API methods as-is (can be used, but not intended to)
################################################################################
class TestrailAPI(object):
@staticmethod
def get_case(case_id):
return Testrail.get('get_case/%s' % case_id)
@staticmethod
def get_cases(project_id, suite_id, section_id=None, created_after=None,
created_before=None, created_by=None, milestone_id=None,
priority_id=None, type_id=None, updated_after=None,
updated_before=None, updated_by=None):
pattern = 'get_cases/%s&suite_id=%s' % (project_id, suite_id)
if section_id is not None:
pattern += '§ion_id=%s' % section_id
if created_after is not None:
pattern += '&created_after=%s' % created_after
if created_before is not None:
pattern += '&created_before=%s' % created_before
if created_by is not None:
pattern += '&created_by=%s' % ','.join(created_by)
if milestone_id is not None:
pattern += '&milestone_id=%s' % ','.join(milestone_id)
if priority_id is not None:
pattern += '&priority_id=%s' % ','.join(priority_id)
if type_id is not None:
pattern += '&type_id=%s' % ','.join(type_id)
if updated_after is not None:
pattern += '&updated_after=%s' % updated_after
if updated_before is not None:
pattern += '&updated_before=%s' % updated_before
if updated_by is not None:
pattern += '&updated_by=%s' % ','.join(updated_by)
return Testrail.get(pattern)
@staticmethod
def add_case(section_id, **kwargs):
"""
The following POST fields are supported (system fields):
title string The title of the test case (required)
type_id int The ID of the case type
priority_id int The ID of the case priority
estimate timespan The estimate, e.g. "30s" or "1m 45s"
milestone_id int The ID of the milestone to link to the test case
refs string A comma-separated list of references/
requirements
"""
return Testrail.post('add_case/%s' % section_id,
data=kwargs)
@staticmethod
def update_case(case_id, **kwargs):
"""
Same fields as _add_case
"""
return Testrail.post('update_case/%s' % case_id,
data=kwargs)
@staticmethod
def delete_case(case_id):
return Testrail.post('delete_case/%s' % case_id)
@staticmethod
def get_case_fields():
return Testrail.get('get_case_fields')
@staticmethod
def get_case_types():
return Testrail.get('get_case_types')
@staticmethod
def get_configs(project_id):
return Testrail.get('get_configs/%s' % project_id)
@staticmethod
def get_milestone(milestone_id):
return Testrail.get('get_milestone/%s' % milestone_id)
@staticmethod
def get_milestones(project_id, is_completed=None):
pattern = 'get_milestones/%s' % project_id
if is_completed is not None:
pattern += '&is_completed=%s' % int(is_completed)
return Testrail.get(pattern)
@staticmethod
def add_milestone(project_id, **kwargs):
"""
The following POST fields are supported:
name string The name of the milestone (required)
description string The description of the milestone
due_on timestamp The due date of the milestone
(as UNIX timestamp)
"""
return Testrail.post('add_milestone/%s' % project_id,
data=kwargs)
@staticmethod
def update_milestone(milestone_id, **kwargs):
"""
Same fields as _add_milestone, and also:
is_completed bool Specifies whether a milestone is considered
completed or not
"""
return Testrail.post('update_milestone/%s' % milestone_id,
data=kwargs)
@staticmethod
def delete_milestone(milestone_id):
return Testrail.post('delete_milestone/%s' % milestone_id)
@staticmethod
def get_plan(plan_id):
return Testrail.get('get_plan/%s' % plan_id)
@staticmethod
def get_plans(project_id, created_after=None, created_before=None,
created_by=None, is_completed=None, limit=None,
offset=None, milestone_id=None):
pattern = 'get_plans/%s' % project_id
if created_after is not None:
pattern += '&created_after=%s' % created_after
if created_before is not None:
pattern += '&created_before=%s' % created_before
if created_by is not None:
pattern += '&created_by=%s' % ','.join(created_by)
if is_completed is not None:
pattern += '&is_completed=%s' % int(is_completed)
if limit is not None:
pattern += '&limit=%s' % limit
if offset is not None:
pattern += '&offset=%s' % offset
if milestone_id is not None:
pattern += '&milestone_id=%s' % ','.join(milestone_id)
return Testrail.get(pattern)
@staticmethod
def add_plan(project_id, **kwargs):
"""
The following POST fields are supported:
name string The name of the test plan (required)
description string The description of the test plan
milestone_id int The ID of the milestone to link to the test plan
entries array An array of objects describing the test runs of
the plan, see _add_plan_entry
"""
return Testrail.post('add_plan/%s' % project_id,
data=kwargs)
@staticmethod
def add_plan_entry(plan_id, **kwargs):
"""
The following POST fields are supported:
suite_id int The ID of the test suite for the test run(s)
(required)
name string The name of the test run (s)
assignedto_id int The ID of the user the test run(s) should be
assigned to
include_all bool True for including all test cases of the test
suite and false for a custom case selection
(default: true)
case_ids array An array of case IDs for the custom case
selection
config_ids array An array of configuration IDs used for the test
runs of the test plan entry
(requires TestRail 3.1 or later)
runs array An array of test runs with configurations
(requires TestRail 3.1 or later)
"""
return Testrail.post('add_plan_entry/%s' % plan_id,
data=kwargs)
@staticmethod
def update_plan(plan_id, **kwargs):
"""
Same fields as _add_plan
"""
return Testrail.post('update_plan/%s' % plan_id,
data=kwargs)
@staticmethod
def update_plan_entry(plan_id, entry_id, **kwargs):
"""
The following POST fields are supported:
name string The name of the test run(s)
assignedto_id int The ID of the user the test run(s) should be
assigned to
include_all bool True for including all test cases of the test
suite and false for a custom case selection
(default: true)
case_ids array An array of case IDs for the custom case
selection
"""
return Testrail.post('update_plan_entry/%s/%s' % (plan_id, entry_id),
data=kwargs)
@staticmethod
def close_plan(plan_id):
return Testrail.post('close_plan/%s' % plan_id)
@staticmethod
def delete_plan(plan_id):
return Testrail.post('delete_plan/%s' % plan_id)
@staticmethod
def delete_plan_entry(plan_id, entry_id):
return Testrail.post('delete_plan_entry/%s/%s' % (plan_id, entry_id))
@staticmethod
def get_priorities():
return Testrail.get('get_priorities')
@staticmethod
def get_project(project_id):
return Testrail.get('get_project/%s' % project_id)
@staticmethod
def get_projects(is_completed=None):
pattern = 'get_projects'
if is_completed is not None:
pattern += '&is_completed=%s' % int(is_completed)
return Testrail.get(pattern)
@staticmethod
def add_project(**kwargs):
"""
The following POST fields are supported:
name string The name of the project (required)
announcement string The description of the project
show_announcement bool True if the announcement should be displayed
on the project's overview page and
false otherwise
suite_mode integer The suite mode of the project (1 for single
suite mode, 2 for single suite + baselines,
3 for multiple suites)
(added with TestRail 4.0)
"""
return Testrail.post('add_project',
data=kwargs)
@staticmethod
def update_project(project_id, **kwargs):
"""
Same fields as _add_project, and also:
is_completed bool Specifies whether a project is considered
completed or not
"""
return Testrail.post('update_project/%s' % project_id,
data=kwargs)
@staticmethod
def delete_project(project_id):
return Testrail.post('delete_project/%s' % project_id)
@staticmethod
def get_results(test_id, limit=None, offset=None, status_id=None):
pattern = 'get_results/%s' % test_id
if limit is not None:
pattern += '&limit=%s' % limit
if offset is not None:
pattern += '&offset=%s' % offset
if status_id is not None:
pattern += '&status_id=%s' % ','.join(status_id)
return Testrail.get(pattern)
@staticmethod
def get_results_for_case(run_id, case_id, limit=None,
offset=None, status_id=None):
pattern = 'get_results_for_case/%s/%s' % (run_id, case_id)
if limit is not None:
pattern += '&limit=%s' % limit
if offset is not None:
pattern += '&offset=%s' % offset
if status_id is not None:
pattern += '&status_id=%s' % ','.join(status_id)
return Testrail.get(pattern)
@staticmethod
def get_results_for_run(run_id, created_after=None,
created_before=None, created_by=None, limit=None,
offset=None, status_id=None):
pattern = 'get_results_for_run/%s' % run_id
if created_after is not None:
pattern += '&created_after=%s' % created_after
if created_before is not None:
pattern += '&created_before=%s' % created_before
if created_by is not None:
pattern += '&created_by=%s' % ','.join(created_by)
if limit is not None:
pattern += '&limit=%s' % limit
if offset is not None:
pattern += '&offset=%s' % offset
if status_id is not None:
pattern += '&status_id=%s' % ','.join(status_id)
return Testrail.get(pattern)
@staticmethod
def add_result(test_id, **kwargs):
"""
The following POST fields are supported (system fields):
status_id int The ID of the test status. The built-in system
statuses have the following IDs:
1 Passed
2 Blocked
3 Untested
4 Retest
5 Failed
You can get a full list of system and custom
statuses via get_statuses.
comment string The comment / description for the test result
version string The version or build you tested against
elapsed timespan The time it took to execute the test,
e.g. "30s" or "1m 45s"
defects string A comma-separated list of defects to link to
the test result
assignedto_id int The ID of a user the test should be assigned to
"""
return Testrail.post('add_result/%s' % test_id,
data=kwargs)
@staticmethod
def add_result_for_case(run_id, case_id, **kwargs):
"""
Same fields as _add_result
"""
return Testrail.post('add_result_for_case/%s/%s' % (run_id, case_id),
data=kwargs)
@staticmethod
def add_results(run_id, **kwargs):
"""
This method expects an array of test results (via the 'results' field).
Each test result must specify the test ID and can pass in the same
fields as _add_result
"""
return Testrail.post('add_results/%s' % run_id,
data=kwargs)
@staticmethod
def add_results_for_cases(run_id, **kwargs):
"""
Same as _add_results but with Case_ID rather than Test_ID.
"""
return Testrail.post('add_results_for_cases/%s' % run_id,
data=kwargs)
@staticmethod
def get_result_fields():
return Testrail.get('get_result_fields')
@staticmethod
def get_run(run_id):
return Testrail.get('get_run/%s' % run_id)
@staticmethod
def get_runs(project_id, created_after=None, created_before=None,
created_by=None, is_completed=None, limit=None,
offset=None, milestone_id=None, suite_id=None):
pattern = 'get_runs/%s' % project_id
if created_after is not None:
pattern += '&created_after=%s' % created_after
if created_before is not None:
pattern += '&created_before=%s' % created_before
if created_by is not None:
pattern += '&created_by=%s' % ','.join(created_by)
if is_completed is not None:
pattern += '&is_completed=%s' % int(is_completed)
if limit is not None:
pattern += '&limit=%s' % limit
if offset is not None:
pattern += '&offset=%s' % offset
if milestone_id is not None:
pattern += '&milestone_id=%s' % ','.join(milestone_id)