diff --git a/locust-scenarios/locustfile.py b/locust-scenarios/locustfile.py index 1311589510216bfa4c19ca2226228517e6bb53e2..127a93a10d3d7217eb31683cc2f47669b4b4bcb3 100644 --- a/locust-scenarios/locustfile.py +++ b/locust-scenarios/locustfile.py @@ -2,6 +2,74 @@ from locust import HttpUser, task class Admin(HttpUser): + + 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" + }) + + self.client.post(":8080/api/countries", json= + { + "name": "Slovensko" + }) + self.client.post(":8080/api/cities", json= + { + "name": "HolĂÄŤ" + }) + self.client.post(":8080/api/cities", json= + { + "name": "Senica" + }) + self.client.post(":8080/api/cities/1/countries/1", json= + { + "name": "Senica" + }) + self.client.post(":8080/api/cities/2/countries/1", json= + { + "name": "Senica" + }) + #create 2 airports - just once because airport need to have unique code + self.client.post(":8080/api/airports", json= + { + "name": "TrávnĂk HolĂÄŤ", + "code": "TH", + "location": { + "latitude": 48.48440, + "longitude": 17.9380 + } + }) + self.client.post(":8080/api/airports", json= + { + "name": "Hlinište Senica", + "code": "HS", + "location": { + "latitude": 48.40500, + "longitude": 17.22000 + } + }) + + def on_start(self): + + tenant_id = "tenant123" + client_id = "client123" + secret = "secret123" + scope = "api://123/.default" + + body ="grant_type=client_credentials&client_id=" + client_id + "&client_secret=" + secret + "&scope=" + scope + + tokenResponse = self.client.post( + f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token", + body, + headers = { "ContentType": "application/x-www-form-urlencoded"} + ) + + response = tokenResponse.json() + responseToken = response['access_token'] + + + self.headers = {'Authorization': 'Bearer ' + responseToken} @task def create_airplane_type(self): self.client.post(":8080/api/airplaneTypes", json=