Skip to content
Snippets Groups Projects
Commit 4608b6e0 authored by Ján Macháček's avatar Ján Macháček
Browse files

fix - locust authorize

parent 6964cdab
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -2,13 +2,15 @@ from locust import HttpUser, task
class Admin(HttpUser):
auth_header = {'Authorization': 'Bearer eyJraWQiOiJyc2ExIiwidHlwIjoiYXQrand0IiwiYWxnIjoiUlMyNTYifQ.eyJhdWQiOiI3ZTAyYTBhOS00NDZhLTQxMmQtYWQyYi05MGFkZDQ3YjBmZGQiLCJzdWIiOiI0OTMyMzdAbXVuaS5jeiIsImFjciI6Imh0dHBzOi8vcmVmZWRzLm9yZy9wcm9maWxlL3NmYSIsInNjb3BlIjoidGVzdF80IHRlc3RfMyB0ZXN0XzIgdGVzdF8xIHRlc3RfcmVhZCBvcGVuaWQgcHJvZmlsZSBlZHVwZXJzb25fc2NvcGVkX2FmZmlsaWF0aW9uIHRlc3Rfd3JpdGUgZW1haWwgdGVzdF81IiwiYXV0aF90aW1lIjoxNjgzNDk1NDgwLCJpc3MiOiJodHRwczovL29pZGMubXVuaS5jei9vaWRjLyIsImV4cCI6MTY4MzQ5OTEzOSwiaWF0IjoxNjgzNDk1NTM5LCJjbGllbnRfaWQiOiI3ZTAyYTBhOS00NDZhLTQxMmQtYWQyYi05MGFkZDQ3YjBmZGQiLCJqdGkiOiIzMjgxZmJiYy01MWYxLTQ0ZGEtOGMzNi1hY2Q5OTM1N2QxYzUifQ.BVLruvROGTvJh6CmhtjKIhURSheMCOVPADKgI6P-qhTmbhi_jTT4gvnLHsAwImGehmwDvo2seLAGahRdv84iM3iYJ7WTblPTGhu9CI5SAE-59ROlGtUaA-3q8zL2xdOVtF5in_KjF8lrk2gI8uY4i3iRE-PZnm9EyK4qmgzcCXIiu9K3TAPnDtKPs8sileFj7_V6Xq4qmjq7g1dr_jGOcelesUgnq6fQlDLvb2guUwWHFTkWZQSnS-cEAX6ZkROkuzPi7d53YlQaPSVngjMYpd81y_DypDcUqbrzNYK28y5cBLbLZ2y2CWKqKyE4ENryc237AH_UcaVdFWwf6Vh2gQ'}
def on_start(self):
#create airplane type - just once because creating airplane type more times would report fail due to not unique name
self.client.post(":8080/api/airplaneTypes", json=
{
"name": "Práškovač 2000"
})
},
headers = self.auth_header)
response = self.client.get(":8080/api/airplaneTypes/1")
......@@ -18,28 +20,34 @@ class Admin(HttpUser):
"name": "Prášek",
"capacity": 2,
"typeId": 1
})
},
headers = self.auth_header)
self.client.post(":8080/api/countries", json=
{
"name": "Slovensko"
})
},
headers = self.auth_header)
self.client.post(":8080/api/cities", json=
{
"name": "Holíč"
})
},
headers = self.auth_header)
self.client.post(":8080/api/cities", json=
{
"name": "Senica"
})
},
headers = self.auth_header)
self.client.post(":8080/api/cities/1/countries/1", json=
{
"name": "Senica"
})
},
headers = self.auth_header)
self.client.post(":8080/api/cities/2/countries/1", json=
{
"name": "Senica"
})
},
headers = self.auth_header)
#create 2 airports - just once because airport need to have unique code
self.client.post(":8080/api/airports", json=
{
......@@ -49,7 +57,8 @@ class Admin(HttpUser):
"latitude": 41.40338,
"longitude": 2.17403
}
})
},
headers = self.auth_header)
self.client.post(":8080/api/airports", json=
{
"name": "Hliniste Senica",
......@@ -58,7 +67,8 @@ class Admin(HttpUser):
"latitude": 41.40338,
"longitude": 2.17403
}
})
},
headers = self.auth_header)
@task
def create_steward(self):
......@@ -66,7 +76,8 @@ class Admin(HttpUser):
{
"firstName": "John",
"lastName": "Doe"
})
},
headers = self.auth_header)
@task
def create_flight(self):
......@@ -75,52 +86,54 @@ class Admin(HttpUser):
"departureTime": "2023-12-22T12:04:04.493908908+01:00",
"arrivalTime": "2023-12-22T12:04:04.493908908+01:00",
"airplaneId": 1
})
},
headers = self.auth_header)
@task
def assign_steward_flight(self):
response_steward = self.client.get(":8080/api/stewards/1")
response_flight = self.client.get(":8080/api/flights/1")
response_steward = self.client.get(":8080/api/stewards/1", headers = self.auth_header)
response_flight = self.client.get(":8080/api/flights/1", headers = self.auth_header)
if response_steward.status_code == 200 and response_flight.status_code == 200:
self.client.post(":8080/api/stewards/1/flights/1")
self.client.delete(":8080/api/stewards/1/flights/1")
self.client.post(":8080/api/stewards/1/flights/1", headers = self.auth_header)
self.client.delete(":8080/api/stewards/1/flights/1", headers = self.auth_header)
@task
def assign_airport_flight(self):
response_airport1 = self.client.get(":8080/api/airports/1")
response_airport2 = self.client.get(":8080/api/airports/2")
response_flight = self.client.get(":8080/api/flights/1")
response_airport1 = self.client.get(":8080/api/airports/1", headers = self.auth_header)
response_airport2 = self.client.get(":8080/api/airports/2", headers = self.auth_header)
response_flight = self.client.get(":8080/api/flights/1", headers = self.auth_header)
if response_airport1.status_code == 200 and response_flight.status_code == 200 and response_airport2.status_code == 200:
self.client.post(":8080/api/airports/1/departingFlights/1")
self.client.post(":8080/api/airports/2/arrivingFlights/1")
self.client.delete(":8080/api/airports/1/departingFlights/1")
self.client.delete(":8080/api/airports/2/arrivingFlights/1")
self.client.post(":8080/api/airports/1/departingFlights/1", headers = self.auth_header)
self.client.post(":8080/api/airports/2/arrivingFlights/1", headers = self.auth_header)
self.client.delete(":8080/api/airports/1/departingFlights/1", headers = self.auth_header)
self.client.delete(":8080/api/airports/2/arrivingFlights/1", headers = self.auth_header)
class BasicUser(HttpUser):
min_wait = 5000
max_wait = 15000
auth_header = {'Authorization': 'Bearer eyJraWQiOiJyc2ExIiwidHlwIjoiYXQrand0IiwiYWxnIjoiUlMyNTYifQ.eyJhdWQiOiI3ZTAyYTBhOS00NDZhLTQxMmQtYWQyYi05MGFkZDQ3YjBmZGQiLCJzdWIiOiI0OTMyMzdAbXVuaS5jeiIsImFjciI6Imh0dHBzOi8vcmVmZWRzLm9yZy9wcm9maWxlL3NmYSIsInNjb3BlIjoidGVzdF80IHRlc3RfMyB0ZXN0XzIgdGVzdF8xIHRlc3RfcmVhZCBvcGVuaWQgcHJvZmlsZSBlZHVwZXJzb25fc2NvcGVkX2FmZmlsaWF0aW9uIHRlc3Rfd3JpdGUgZW1haWwgdGVzdF81IiwiYXV0aF90aW1lIjoxNjgzNDk1NDgwLCJpc3MiOiJodHRwczovL29pZGMubXVuaS5jei9vaWRjLyIsImV4cCI6MTY4MzQ5OTEzOSwiaWF0IjoxNjgzNDk1NTM5LCJjbGllbnRfaWQiOiI3ZTAyYTBhOS00NDZhLTQxMmQtYWQyYi05MGFkZDQ3YjBmZGQiLCJqdGkiOiIzMjgxZmJiYy01MWYxLTQ0ZGEtOGMzNi1hY2Q5OTM1N2QxYzUifQ.BVLruvROGTvJh6CmhtjKIhURSheMCOVPADKgI6P-qhTmbhi_jTT4gvnLHsAwImGehmwDvo2seLAGahRdv84iM3iYJ7WTblPTGhu9CI5SAE-59ROlGtUaA-3q8zL2xdOVtF5in_KjF8lrk2gI8uY4i3iRE-PZnm9EyK4qmgzcCXIiu9K3TAPnDtKPs8sileFj7_V6Xq4qmjq7g1dr_jGOcelesUgnq6fQlDLvb2guUwWHFTkWZQSnS-cEAX6ZkROkuzPi7d53YlQaPSVngjMYpd81y_DypDcUqbrzNYK28y5cBLbLZ2y2CWKqKyE4ENryc237AH_UcaVdFWwf6Vh2gQ'}
@task
def get_airplane(self):
self.client.get(":8080/api/airplanes")
self.client.get(":8080/api/airplanes", headers = self.auth_header)
@task
def get_stewards(self):
self.client.get(":8080/api/stewards")
self.client.get(":8080/api/stewards", headers = self.auth_header)
@task
def get_airports(self):
self.client.get(":8080/api/airports")
self.client.get(":8080/api/airports", headers = self.auth_header)
@task
def get_flights(self):
self.client.get(":8080/api/flights")
self.client.get(":8080/api/flights", headers = self.auth_header)
@task
def generate_airplane_report(self):
self.client.get(":8085/api/reports/airplane/1")
self.client.get(":8085/api/reports/airplane/1", headers = self.auth_header)
@task
def generate_airport_report(self):
self.client.get(":8085/api/reports/airport/1")
self.client.get(":8085/api/reports/airport/1", headers = self.auth_header)
@task
def generate_flight_report(self):
self.client.get(":8085/api/reports/flight/1")
self.client.get(":8085/api/reports/flight/1", headers = self.auth_header)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment