-
Notifications
You must be signed in to change notification settings - Fork 3
/
locustfile.py
50 lines (43 loc) · 1.76 KB
/
locustfile.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
from random import randint
import requests
from locust import HttpUser, task
from requests.structures import CaseInsensitiveDict
urlArtist = "http://localhost:8080/api/vma/voting/artist"
urlSong = "http://localhost:8080/api/vma/voting/song"
open_voting = "http://localhost:8080/api/vma/voting/open"
count_url = "http://localhost:8080/api/vma/voting/count"
class VmaVoting(HttpUser):
@task
def voting(self):
response = requests.get("http://localhost:8080/api/vma/registry/current")
open_result = requests.get(open_voting).json()
print(open_result)
headers = CaseInsensitiveDict()
user_id = open_result['id']
headers["Cookie"] = f"votingId={user_id}"
for category in response.json():
print(category["category"])
print(category)
if category["type"] == "ARTIST":
elected = category["artists"][randint(0, len(category['artists']) - 1)]
resp = requests.post(
urlArtist,
headers=headers,
json={
"userId": user_id,
"idC": category["id"],
"idA": elected["id"]
})
print(resp.status_code)
if category["type"] == "SONG" or category["type"] == "INSTRUMENTAL":
elected = category["songs"][randint(0, len(category['songs']) - 1)]
resp = requests.post(
urlSong,
headers=headers,
json={
"userId": user_id,
"idC": category["id"],
"idS": elected["id"]
})
print(resp.status_code)
requests.post(count_url)