forked from mathialm/secfit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sondre Malerud
committed
Apr 3, 2025
1 parent
daa5e99
commit 39bf907
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import os | ||
| from locust import HttpUser, task, between | ||
| from datetime import datetime, timezone | ||
| from dotenv import load_dotenv | ||
| load_dotenv() # load variables from .env file when running locust command locally | ||
|
|
||
| class SecFitUser(HttpUser): | ||
| host = "http://tdt4242-23.idi.ntnu.no" # Match Django backend | ||
| wait_time = between(10, 10.5) | ||
| token = None # Store authentication token | ||
| exercise_url = None # Store existing exercise URL | ||
|
|
||
|
|
||
| workout_num = "1" | ||
|
|
||
| def on_start(self): | ||
|
|
||
| response = self.client.post("/api/token/", json={"username": os.environ.get("LOCUST_USER_USERNAME") , "password": os.environ.get("LOCUST_USER_PASSWORD")}) | ||
| if response.status_code == 200: | ||
| self.token = response.json().get("access") | ||
| if self.token: | ||
| self.client.headers.update({"Authorization": f"Bearer {self.token}"}) | ||
| else: | ||
| print("\nFailed to retrieve token from response.") | ||
| else: | ||
| print("\nFailed to authenticate. Response:", response.json()) | ||
|
|
||
| @task | ||
| def update_workout(self): | ||
| """Updates the first workout""" | ||
| new_date = datetime.now(timezone.utc).isoformat() | ||
| workout = { | ||
| "url": self.host + "/api/workouts/" + self.workout_num + "/", | ||
| "name": "My Great Workout", | ||
| "date": new_date, | ||
| "notes": "Great workout!", | ||
| "exercise_instances": [] | ||
| } | ||
|
|
||
| headers = {"Authorization": f"Bearer {self.token}"} if hasattr(self, "token") else {} | ||
| workout_response = self.client.put("/api/workouts/" + self.workout_num + "/", json=workout, headers=headers) | ||
| if workout_response.status_code == 200: | ||
| print("\nUpdate OK") | ||
| else: | ||
| print("\nError when updating workout") |