From 06e95b9751afb42f40fdbd7b4b207467b85c8e63 Mon Sep 17 00:00:00 2001 From: starnakin Date: Fri, 3 Nov 2023 21:52:26 +0100 Subject: [PATCH] add: accounts: create, delete --- src/Accounts.py | 15 +++++++++++++++ src/Client.py | 3 +++ src/tests.py | 40 ++++++++++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 src/Accounts.py diff --git a/src/Accounts.py b/src/Accounts.py new file mode 100644 index 0000000..960dcf3 --- /dev/null +++ b/src/Accounts.py @@ -0,0 +1,15 @@ +import urls + +class Account: + + def __init__(self, client): + self._client = client + + def create(self, username: str, password: str): + response: Response = self._client._post(urls.accounts_register, {'username': username, 'password': password}) + return response.content + + def delete(self): + assert self._client.is_authentificate + response: Response = self._client._post(urls.accounts_delete, {}) + return response.content \ No newline at end of file diff --git a/src/Client.py b/src/Client.py index bf21a88..baca40e 100644 --- a/src/Client.py +++ b/src/Client.py @@ -1,6 +1,8 @@ import requests from requests import Response, Request, Session +import Accounts + import urls class Client: @@ -8,6 +10,7 @@ class Client: self.url: str = url self.token: str = None self.session: Session = Session() + self.accounts: Account = Accounts.Account(self) def is_authentificate(self): return (not self.token is None) diff --git a/src/tests.py b/src/tests.py index 2fd86ca..f867f0a 100644 --- a/src/tests.py +++ b/src/tests.py @@ -3,7 +3,7 @@ from urls import * from uuid import uuid4 -def test(value, expected_value, title, description): +def test(value, expected_value, title, description = None): if (value == expected_value): print(title, "[OK]") return @@ -12,20 +12,40 @@ def test(value, expected_value, title, description): if not description is None: print (description) -def test_accounts_register(): +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 tests(): + username = uuid4() password = uuid4() client = Client.Client("http://0.0.0.0:8000/") - print ("REGISTER") - - test(client.register(username, password), b'ok: user added', 'normal register', None) - - print() - -def tests(): - test_accounts_register() + + test_accounts_register(client, username, password) + test_accounts_login(client, username, password) + test_accounts_delete(client) if __name__ == "__main__": tests() \ No newline at end of file