Test script

This commit is contained in:
Imbus 2024-03-17 01:55:24 +01:00
parent c13378d3b9
commit 04d7a2cdec
2 changed files with 51 additions and 0 deletions

View file

@ -27,6 +27,10 @@ clean: remove-podman-containers
cd backend && make clean
@echo "Cleaned up!"
.PHONY: itest
itest:
python testing.py
# Cleans up everything related to podman, not just the project. Make sure you understand what this means.
podman-clean:
podman system reset --force

47
testing.py Normal file
View file

@ -0,0 +1,47 @@
import requests
import string
import random
def randomString(len=10):
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(len))
# Defined once per test run
username = randomString()
# Define the base URL of the API
base_url = "http://localhost:8080"
# Define the endpoint to test
registerPath = base_url + "/api/register"
loginPath = base_url + "/api/login"
# Define a function to prform POST request with data and return response
def create_user(data):
response = requests.post(registerPath, json=data)
return response
def login(username, password):
response = requests.post(loginPath, json={"username": username, "password": password})
return response
def test_login():
response = login(username, "always_same")
assert response.status_code == 200, "Login failed"
print("Login successful")
print(response.json()["token"])
# Define a function to test the POST request
def test_create_user():
data = {"username": username, "password": "always_same"}
response = create_user(data)
assert response.status_code == 200, "Registration failed"
print("Registration successful")
# Run the tests
if __name__ == "__main__":
# test_get_users()
test_create_user()
test_login()