Test script
This commit is contained in:
parent
c13378d3b9
commit
04d7a2cdec
2 changed files with 51 additions and 0 deletions
4
Makefile
4
Makefile
|
@ -27,6 +27,10 @@ clean: remove-podman-containers
|
||||||
cd backend && make clean
|
cd backend && make clean
|
||||||
@echo "Cleaned up!"
|
@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.
|
# Cleans up everything related to podman, not just the project. Make sure you understand what this means.
|
||||||
podman-clean:
|
podman-clean:
|
||||||
podman system reset --force
|
podman system reset --force
|
||||||
|
|
47
testing.py
Normal file
47
testing.py
Normal 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()
|
||||||
|
|
Loading…
Reference in a new issue