From 617b67df24d66d69e539d4d24c9176d0d4ed0264 Mon Sep 17 00:00:00 2001 From: starnakin Date: Mon, 6 Nov 2023 14:36:28 +0100 Subject: [PATCH] split test --- tests/__init__.py | 0 tests/accounts.py | 35 ++++++++++++++++++++++++ tests/profiles.py | 19 +++++++++++++ tests/test.py | 22 +++++++++++++++ tests/tests.py | 70 ----------------------------------------------- tests/utils.py | 9 ++++++ 6 files changed, 85 insertions(+), 70 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/accounts.py create mode 100644 tests/profiles.py create mode 100644 tests/test.py delete mode 100644 tests/tests.py create mode 100644 tests/utils.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/accounts.py b/tests/accounts.py new file mode 100644 index 0000000..6c0941a --- /dev/null +++ b/tests/accounts.py @@ -0,0 +1,35 @@ +from uuid import uuid4 + +from tests.utils import test + +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_accounts(client): + + username = uuid4() + password = uuid4() + + test_accounts_register(client, username, password) + test_accounts_login(client, username, password) + test_accounts_delete(client) \ No newline at end of file diff --git a/tests/profiles.py b/tests/profiles.py new file mode 100644 index 0000000..d0e2290 --- /dev/null +++ b/tests/profiles.py @@ -0,0 +1,19 @@ +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) # Add parent directory to system path + +from tests.utils import test + +from src.profile import Profile + +def test_profiles_get(client): + + print ("GET") + + test(client.profiles.get(1), Profile(username="997e13f5-474d-4fea-b55a-ad8a27b9534b", title=""), "normal") + + print() + +def test_profiles(client): + + test_profiles_get(client) \ No newline at end of file diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..aa5f001 --- /dev/null +++ b/tests/test.py @@ -0,0 +1,22 @@ +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 import urls + +from tests.accounts import test_accounts +from tests.profiles import test_profiles + +def tests(): + + client = Client("http://0.0.0.0:8000/") + + print("ACCOUNTS".center(os.get_terminal_size()[0], '-')) + test_accounts(client) + + print("PROFILES".center(os.get_terminal_size()[0], '-')) + test_profiles(client) + +if __name__ == "__main__": + tests() \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py deleted file mode 100644 index 37e67e0..0000000 --- a/tests/tests.py +++ /dev/null @@ -1,70 +0,0 @@ -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() \ No newline at end of file diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..5a4fd97 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,9 @@ +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) \ No newline at end of file