Skip to content
Snippets Groups Projects
Commit bbab9237 authored by Jan Pokorný's avatar Jan Pokorný :lifter_tone2:
Browse files

Adding auth header to rest calls

parent c6d9774f
No related branches found
No related tags found
1 merge request!37M3 locust
Pipeline #
...@@ -2,6 +2,7 @@ import random ...@@ -2,6 +2,7 @@ import random
from locust import HttpUser, task, between from locust import HttpUser, task, between
from locust.exception import StopUser from locust.exception import StopUser
header={'Authorization': 'Bearer YOUR_ACCESS_TOKEN'}
class StudentActor(HttpUser): class StudentActor(HttpUser):
...@@ -14,25 +15,41 @@ class StudentActor(HttpUser): ...@@ -14,25 +15,41 @@ class StudentActor(HttpUser):
@task(3) @task(3)
def get_courses_english(self): def get_courses_english(self):
self.client.get('/courses/findAllByLang?lang=ENGLISH') self.client.get(
url='/courses/findAllByLang?lang=ENGLISH',
auth=None,
headers=header,
name="Find Courses"
)
@task(3) @task(3)
def get_courses_spanish(self): def get_courses_spanish(self):
self.client.get('/courses/findAllByLang?lang=SPANISH') self.client.get(
url='/courses/findAllByLang?lang=SPANISH',
auth=None,
headers=header,
name="Find Courses"
)
@task @task
def enrol(self): def enrol(self):
self.client.get(f'http://localhost:5000/courses/enrol/{1}?studentId={1}') self.client.patch(
url=f'/courses/enrol/{1}?studentId={1}',
auth=None,
headers=header,
name="Enrol Courses"
)
@task @task
def get_lecture_by_id(self): def get_lecture_by_id(self):
self.client.get(f'/lectures/findByCourse?courseId={1}') self.client.get(
url=f'/lectures/findByCourse?courseId={1}',
def on_start(self): auth=None,
# TODO auth headers=header,
return super().on_start() name="Find Lectures"
)
class LecturerActor(HttpUser): class LecturerActor(HttpUser):
weight = 0 weight = 0
...@@ -48,9 +65,13 @@ class LecturerActor(HttpUser): ...@@ -48,9 +65,13 @@ class LecturerActor(HttpUser):
def new_course(self): def new_course(self):
if self.courses_created < 3: if self.courses_created < 3:
self.client.headers['Content-Type'] = "application/json" self.client.headers['Content-Type'] = "application/json"
response = self.client.post("/courses", json= response = self.client.post(
{ url="/courses",
"name": "string", auth=None,
headers=header,
name="Create Course",
json={
"name": "string",
"capacity": 10, "capacity": 10,
"language": random.choice(["SPANISH", "ENGLISH"]), "language": random.choice(["SPANISH", "ENGLISH"]),
"proficiency": random.choice(["A1", "B1", "C1"]) "proficiency": random.choice(["A1", "B1", "C1"])
...@@ -66,8 +87,12 @@ class LecturerActor(HttpUser): ...@@ -66,8 +87,12 @@ class LecturerActor(HttpUser):
def new_lecture(self): def new_lecture(self):
if self.courses_created > 0 and self.lecture_created < 10: if self.courses_created > 0 and self.lecture_created < 10:
self.client.headers['Content-Type'] = "application/json" self.client.headers['Content-Type'] = "application/json"
response = self.client.post("/lectures", json= response = self.client.post(
{ url="/lectures",
auth=None,
headers=header,
name="Create Lecture",
json={
"lectureFrom": "2024-04-26T18:06:30.658Z", "lectureFrom": "2024-04-26T18:06:30.658Z",
"lectureTo": "2024-04-27T18:06:30.658Z", "lectureTo": "2024-04-27T18:06:30.658Z",
"topic": "string", "topic": "string",
...@@ -82,7 +107,3 @@ class LecturerActor(HttpUser): ...@@ -82,7 +107,3 @@ class LecturerActor(HttpUser):
if self.lecture_created >= 9: if self.lecture_created >= 9:
raise StopUser() raise StopUser()
def on_start(self):
# TODO auth
return super().on_start()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment