create package and separate code

This commit is contained in:
2023-11-06 14:26:40 +01:00
parent 3c96defea3
commit a17f09e04b
7 changed files with 27 additions and 17 deletions

70
tests/tests.py Normal file
View File

@ -0,0 +1,70 @@
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
from uuid import uuid4
import os
def test(value, expected_value, title, description = None):
print(title, end=" ")
if (value == expected_value):
print("[OK]")
return
print ("[ERROR]")
print ("expected", expected_value, ", got", value)
if not description is None:
print (description)
def test_accounts_register(client, username, password):
print ("REGISTER")
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()
def test_accounts_delete(client):
print ("DELETE")
test(client.accounts.delete(), b'ok: account has been deleted', 'normal')
print()
def test_profile_get(client):
print ("GET")
test(client.profiles.get(1), Profile(username="997e13f5-474d-4fea-b55a-ad8a27b9534b", title=""), "normal")
print()
def tests():
username = uuid4()
password = uuid4()
client = Client("http://0.0.0.0:8000/")
print("ACCOUNTS".center(os.get_terminal_size()[0], '-'))
test_accounts_register(client, username, password)
test_accounts_login(client, username, password)
test_accounts_delete(client)
print("ACCOUNTS".center(os.get_terminal_size()[0], '-'))
test_profile_get(client)
if __name__ == "__main__":
tests()