· 6 years ago · Feb 11, 2020, 08:30 PM
1#!/usr/bin/python
2import requests
3import json
4import random
5
6
7headers = {
8 'Content-Type': 'application/json',
9}
10
11
12
13users = ["admin"]
14date = ["2018-01-04", "2019-04-04", "2020-06-16"]
15labs = [["Database", "Developpers"], ["UI", "Developpers"], ["Database", "UI"]]
16days = ["3d", "4d", "5d", "6d"]
17priorities = ["10000", "10001", "10002", "10003"]
18
19projectkey = "AD"
20issuetype = "Bug"
21summary = "Bug generated by API REST"
22reporter = random.choice(users)
23duedate = random.choice(date)
24description = """
25 This
26 is
27 a
28 description
29 """
30assignee = random.choice(users)
31priority = random.choice(priorities)
32labels = random.choice(labs)
33
34data = {
35 "fields":
36 {
37 "project":
38 {
39 "key": projectkey
40 },
41 "issuetype":
42 {
43 "name": issuetype
44 },
45 "summary": summary,
46 "reporter":
47 {
48 "name": reporter
49 },
50 "duedate": duedate,
51 "description": description,
52 "assignee":
53 {
54 "name": assignee
55 },
56 "priority":
57 {
58 "id": priority
59 },
60 "labels": labels
61 }
62}
63
64response = requests.post('http://localhost:8080/jirasw/rest/api/2/issue', headers=headers, data=json.dumps(data),
65 auth=('admin', 'admin'))
66
67if response.status_code == 201:
68 print("Issue : " + summary + "\n--> Created")
69 print("\n")
70else:
71 print(response.status_code)
72 print(response.text)
73 print("\n")