ft_transcendence/src/tests.py

65 lines
1.5 KiB
Python
Raw Normal View History

2023-11-03 16:04:38 -04:00
import Client
2023-11-05 12:15:48 -05:00
import Profile
2023-11-03 16:04:38 -04:00
from urls import *
from uuid import uuid4
2023-11-05 12:15:48 -05:00
import os
2023-11-03 16:04:38 -04:00
2023-11-03 16:52:26 -04:00
def test(value, expected_value, title, description = None):
2023-11-05 12:15:48 -05:00
print(title, end=" ")
2023-11-03 16:04:38 -04:00
if (value == expected_value):
2023-11-05 12:15:48 -05:00
print("[OK]")
2023-11-03 16:04:38 -04:00
return
2023-11-05 12:15:48 -05:00
print ("[ERROR]")
2023-11-03 16:04:38 -04:00
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()
2023-11-03 17:22:24 -04:00
def test_profile_get(client):
2023-11-05 12:15:48 -05:00
print ("GET")
test(client.profiles.get(1), Profile.Profile(username="997e13f5-474d-4fea-b55a-ad8a27b9534b", title=""), "normal")
print()
2023-11-03 17:22:24 -04:00
2023-11-03 16:04:38 -04:00
def tests():
2023-11-03 16:52:26 -04:00
username = uuid4()
password = uuid4()
client = Client.Client("http://0.0.0.0:8000/")
2023-11-05 12:15:48 -05:00
print("ACCOUNTS".center(os.get_terminal_size()[0], '-'))
2023-11-03 16:52:26 -04:00
test_accounts_register(client, username, password)
test_accounts_login(client, username, password)
test_accounts_delete(client)
2023-11-05 12:15:48 -05:00
print("ACCOUNTS".center(os.get_terminal_size()[0], '-'))
2023-11-03 17:22:24 -04:00
test_profile_get(client)
2023-11-03 16:04:38 -04:00
if __name__ == "__main__":
tests()