create package and separate code
This commit is contained in:
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
@ -1,7 +1,9 @@
|
||||
import urls
|
||||
from src import urls
|
||||
|
||||
from requests import Response
|
||||
|
||||
class Account:
|
||||
|
||||
class Accounts:
|
||||
|
||||
def __init__(self, client):
|
||||
self._client = client
|
@ -1,18 +1,17 @@
|
||||
import requests
|
||||
from requests import Response, Request, Session
|
||||
|
||||
import Profiles
|
||||
import Accounts
|
||||
|
||||
import urls
|
||||
from src.profiles import Profiles
|
||||
from src.accounts import Accounts
|
||||
from src import urls
|
||||
|
||||
class Client:
|
||||
def __init__(self, url: str):
|
||||
self.url: str = url
|
||||
self.token: str = None
|
||||
self.session: Session = Session()
|
||||
self.accounts: Account = Accounts.Account(self)
|
||||
self.profiles = Profiles.Profiles(self)
|
||||
self.accounts: Accounts = Accounts(self)
|
||||
self.profiles: Profiles = Profiles(self)
|
||||
|
||||
def is_authentificate(self):
|
||||
return (not self.token is None)
|
@ -1,8 +1,9 @@
|
||||
import urls
|
||||
import Client
|
||||
from src import urls
|
||||
|
||||
from src.profile import Profile
|
||||
|
||||
|
||||
from requests import Response
|
||||
import Profile
|
||||
|
||||
class Profiles:
|
||||
|
||||
@ -14,4 +15,4 @@ class Profiles:
|
||||
if response.status_code == 404:
|
||||
return None
|
||||
content: dict = eval(response.content)
|
||||
return Profile.Profile(data = content)
|
||||
return Profile(data = content)
|
65
src/tests.py
65
src/tests.py
@ -1,65 +0,0 @@
|
||||
import Client
|
||||
import Profile
|
||||
from urls import *
|
||||
|
||||
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.Profile(username="997e13f5-474d-4fea-b55a-ad8a27b9534b", title=""), "normal")
|
||||
|
||||
print()
|
||||
|
||||
def tests():
|
||||
|
||||
username = uuid4()
|
||||
password = uuid4()
|
||||
|
||||
client = 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()
|
Reference in New Issue
Block a user