This repository has been archived by the owner on Sep 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulate_db.py
70 lines (57 loc) · 1.59 KB
/
populate_db.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
import requests
USER_ID = "74a65c12-86ad-4ffd-a463-27ec8ccefd27"
BEARER_TOKEN = "08e7768e-0ef8-477a-9ff9-f35fe25a1fb8"
API_BASE_URL = "http://localhost/api/v1/"
PRODUCT_URL = API_BASE_URL + "products/"
APPLICATION_URL = API_BASE_URL + "accounts/" + USER_ID + "/applications/"
def make_request(type, url, json=None):
request = getattr(requests, type)
if json:
return request(
url,
json,
headers={"Authorization": "Bearer " + BEARER_TOKEN}
)
else:
return request(
url,
headers={"Authorization": "Bearer " + BEARER_TOKEN}
)
def create_application(name):
return make_request(
"post",
APPLICATION_URL,
json={
"name": name
}
)
def create_product(name, description, price):
return make_request(
"post",
PRODUCT_URL,
json={
"name": name,
"description": description,
"price": price
}
)
def create_transaction():
response = create_product("test", "test", 10.10)
product_id = response.json().get("id")
transaction_url = PRODUCT_URL + product_id + "/transactions/"
return make_request(
"post", transaction_url, json={"token": "tok_visa"}
)
# Creating an application
# response = create_application("test")
# print(response.json())
# Creating a product
# response = create_product(
# "ACM Semesterly Membership",
# "ACM Semesterly Membership",
# 20.20
# )
# print(response.json())
# Creating a transaction
response = create_transaction()
print(response.json())