-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_test.py
111 lines (88 loc) · 2.61 KB
/
load_test.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
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
import time
import psycopg2
import os
import random
from dotenv import load_dotenv
from locust import HttpUser, task, between
load_dotenv()
URL = os.getenv('API_URL')
# conn = psycopg2.connect(
# host=os.getenv('host'),
# dbname=os.getenv('dbname'),
# password=os.getenv('password'),
# user='root'
# )
# cur = conn.cursor()
class ProductionTrackUser(HttpUser):
wait_time = between(1, 5)
URL = os.getenv('API_URL')
# # fetch locations
# cur.execute(
# f"""
# SELECT id FROM location WHERE organization_id = 4 AND
# EXISTS (SELECT 1 FROM license_plate WHERE location_id = location.id);
# """
# )
# locs = [x[0] for x in cur.fetchall()]
# def prepare_headers(self):
# token = self.client.post(
# url=os.getenv('API_LOGIN'),
# data={
# 'email': '[email protected]',
# 'password': 'vishwa'
# }
# ).json()['data']['access_token']
# return {
# "Authorization": f"Bearer {token}"
# }
# def getData(self):
# loc_pair = random.choices(ProductionTrackUser.locs, k=2)
# src = random.choice(loc_pair)
# cur.execute(
# f"""
# SELECT id FROM license_plate WHERE organization_id = 4 AND location_id = {src}
# """
# )
# res = cur.fetchone()
# if res:
# res = res[0]
# else:
# res = 2315
# payload_schema = {
# "dest_location_id": loc_pair[0] if loc_pair.index(src) else loc_pair[1],
# "license_plate_id": res
# }
# print({'src_loc': src, **payload_schema})
# return payload_schema
def getData(self):
ticNos = [
"DSCA231975844",
"DSCA231921621",
"DSCA231923114",
"DSCA231926593",
"DSCA231975556",
"DSCA231922755",
"DSCA231950519",
"DSCA231938572",
"DSCA231970670",
"DSCA231957894"
]
events = [1, 2, 3, 4, 5, 6, 7, 8, 9]
uid = random.choice(ticNos)
events = random.sample(events, k=3)
resp = {
"ticket_id": uid,
"event_ids": events
}
print(resp)
return resp
@task
def rsvp(self):
_path = f"rsvp/"
resp = self.client.post(
url=URL+f"/{_path}",
json=self.getData(),
)
print("resp:: ", resp.json())
# def on_start(self):
# self.client.post("/login", json={"username":"foo", "password":"bar"})