diff --git a/Makefile b/Makefile index 668ccf1..97db62e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/testing.py b/testing.py new file mode 100644 index 0000000..6394b94 --- /dev/null +++ b/testing.py @@ -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() +