ft_transcendence/tests/tests.py

70 lines
1.7 KiB
Python
Raw Normal View History

2023-11-06 08:26:40 -05:00
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) # Add parent directory to system path
from src.client import Client
from src.profiles import Profiles
from src.profile import Profile
from src import urls
2023-11-03 16:04:38 -04:00
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")
2023-11-06 08:26:40 -05:00
test(client.profiles.get(1), Profile(username="997e13f5-474d-4fea-b55a-ad8a27b9534b", title=""), "normal")
2023-11-05 12:15:48 -05:00
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()
2023-11-06 08:26:40 -05:00
client = Client("http://0.0.0.0:8000/")
2023-11-03 16:52:26 -04:00
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()