ft_transcendence/src/tests.py

51 lines
1.1 KiB
Python
Raw Normal View History

2023-11-03 16:04:38 -04:00
import Client
from urls import *
from uuid import uuid4
2023-11-03 16:52:26 -04:00
def test(value, expected_value, title, description = None):
2023-11-03 16:04:38 -04:00
if (value == expected_value):
print(title, "[OK]")
return
print (title, "[ERROR]")
print ("expected", expected_value, ", got", value)
if not description is None:
print (description)
2023-11-03 16:52:26 -04:00
def test_accounts_register(client, username, password):
2023-11-03 16:04:38 -04:00
print ("REGISTER")
2023-11-03 16:52:26 -04:00
test(client.accounts.create(username, password), b'ok: user added', 'normal', None)
print()
def test_accounts_login(client, username, password):
print ("LOGIN")
test(client.login(username, password), b'ok: account valid', "normal", None)
print()
2023-11-03 16:04:38 -04:00
2023-11-03 16:52:26 -04:00
def test_accounts_delete(client):
print ("DELETE")
test(client.accounts.delete(), b'ok: account has been deleted', 'normal')
2023-11-03 16:04:38 -04:00
print()
def tests():
2023-11-03 16:52:26 -04:00
username = uuid4()
password = uuid4()
client = Client.Client("http://0.0.0.0:8000/")
test_accounts_register(client, username, password)
test_accounts_login(client, username, password)
test_accounts_delete(client)
2023-11-03 16:04:38 -04:00
if __name__ == "__main__":
tests()