-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_dev.py
More file actions
93 lines (76 loc) · 2.15 KB
/
setup_dev.py
File metadata and controls
93 lines (76 loc) · 2.15 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
import json
import requests
headers = {'Content-type': 'application/json'}
base_url = "http://localhost:5000/%s"
users_url = base_url % "api/users/"
orgs_url = base_url % "api/organizations/"
org_users_url = base_url % "api/organizations/%s/users/"
domains_url = base_url % "api/organizations/%s/domains/"
rules_url = base_url % "api/organizations/%s/domains/%s/rules/"
michael = {
"email": "mike@example.com",
"first_name": "Michael",
"last_name": "Smith",
"password": "test",
"phone": "5555551234"
}
org = {
"name": "MailBeaker",
"billing_address": "1234 Oakwood Lane",
"billing_phone": "5555551234"
}
domain = {
"domain_name": "example.com",
"mx_records": [
{
"priority": 10,
"domain_name": "example.com"
}
]
}
rules = [
{
"description": "First Test Rule",
"alert_admins": True,
"action": 1,
"body_mod": 3,
"body_value": "haxor"
},
{
"description": "Second Test Rule",
"alert_admins": False,
"action": 2,
"sender_mod": 3,
"sender_value": "computmaxer"
},
{
"description": "Third Test Rule",
"alert_admins": False,
"action": 2,
"sender_mod": 6,
"sender_value": ".ru"
}
]
org_id = None
domain_id = None
data = json.dumps(michael)
response = requests.post(users_url, data=data, headers=headers)
michael_id = response.json()['id']
data = json.dumps(org)
response = requests.post(orgs_url, data=data, headers=headers)
if 199 < response.status_code < 300:
print response.json()
org_id = response.json()['id']
membership['user_id'] = michael_id
data = json.dumps(membership)
response = requests.post(org_users_url % org_id, data=data, headers=headers)
if 199 < response.status_code < 300:
print response.json()
data = json.dumps(domain)
response = requests.post(domains_url % org_id, data=data, headers=headers)
if 199 < response.status_code < 300:
print response.json()
domain_id = response.json()['id']
for rule in rules:
data = json.dumps(rule)
response = requests.post(rules_url % (org_id, domain_id), data=data, headers=headers)