-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrs_convert.py
73 lines (56 loc) · 1.92 KB
/
rs_convert.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
from __future__ import annotations
from http import HTTPStatus
import settings
import setup
from locust import TaskSet, between, task
class RSConvert(TaskSet):
"""Converting from Dollar to RS & vice versa."""
# Time period between firing consecutive tasks is 1-3 seconds
wait_time = between(1, 3)
def on_start(self) -> None:
"""Logins and stuff before starting a user session."""
setup.login()
@task
def usd_to_rs(self) -> None:
url = "exchange"
querystring = {"q": "1.0", "from": "USD", "to": "RS"}
headers = {
"x-rapidapi-host": settings.HOST,
"x-rapidapi-key": settings.API_TOKEN,
}
with self.client.get(
url,
headers=headers,
params=querystring,
catch_response=True,
) as response:
if response.status_code == HTTPStatus.OK:
response.success()
else:
response.failure(f"Failed! Http Code `{response.status_code}`")
@task
def rs_to_usd(self) -> None:
url = "exchange"
querystring = {"q": "1.0", "from": "RS", "to": "USD"}
headers = {
"x-rapidapi-host": settings.HOST,
"x-rapidapi-key": settings.API_TOKEN,
}
with self.client.get(
url,
headers=headers,
params=querystring,
catch_response=True,
) as response:
if response.status_code == HTTPStatus.OK:
response.success()
else:
response.failure(f"Failed! Http Code `{response.status_code}`")
@task
def stop(self) -> None:
"""TaskSet objects don't know when to hand over control
to the parent class. This method does exactly that."""
self.interrupt()
def on_stop(self) -> None:
"""Logout and stuff after ending a user session."""
setup.logout()