This repository was archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (34 loc) · 1.65 KB
/
main.py
File metadata and controls
46 lines (34 loc) · 1.65 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
import requests
import json
SERVER_URL = 'http://127.0.0.1:8000/te/'
# This method sends a delete request to delete all the templates in the database.
def reset_templates():
url_endpoint = SERVER_URL + 'reset'
response = requests.delete(url_endpoint)
print(response.status_code, response.content)
# This method sends a put request with system templates to insert them into the database.
def put_system_templates():
url_endpoint = SERVER_URL + 'system/templates'
system_template_file = open('system_templates.json')
system_templates = json.load(system_template_file)
for template in system_templates:
response = requests.put(url_endpoint, json=template)
print(response.status_code, response.content)
# This method sends a get request with customer_id to retrieve customer_template.
def get_customer_templates(customer_id):
url_endpoint = SERVER_URL + 'customer/' + str(customer_id) + '/templates'
response = requests.get(url_endpoint)
print(response.status_code, response.content)
# This method sends a post request with customer_id to create customer_template.
def post_customer_templates(customer_id):
url_endpoint = SERVER_URL + 'customer/' + str(customer_id) + '/templates'
response = requests.post(url_endpoint)
print(response.status_code, response.content)
# Run only one function at a time, comment out the rest.
# Run `reset_templates()` before a series of tests to clear the database.
# Run `put_system_templates()` to add system templates to the database.
if __name__ == '__main__':
reset_templates()
# put_system_templates()
# get_customer_templates(10)
# post_customer_templates(10)