add: accounts: create, delete
This commit is contained in:
parent
f14279b956
commit
06e95b9751
15
src/Accounts.py
Normal file
15
src/Accounts.py
Normal file
@ -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
|
@ -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)
|
||||
|
40
src/tests.py
40
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()
|
Loading…
Reference in New Issue
Block a user