Compare commits

..

No commits in common. "21ed36fd99f2ef0a771c6745e9bb527ba6a18447" and "66398936f0c99364fa148eff6fd41629ba3a9089" have entirely different histories.

6 changed files with 25 additions and 49 deletions

3
.gitignore vendored
View File

@ -1,3 +0,0 @@
.env
*.pyc

View File

@ -1,5 +1,6 @@
import requests import requests
from requests import Response, Request, Session from requets.Session import Session
from requests import Response, Requests
import urls import urls
@ -8,23 +9,22 @@ class Client:
self.url: str = url self.url: str = url
self.token: str = None self.token: str = None
self.session: Session = Session() self.session: Session = Session()
response: Response = s.get(self.url)
self.csrf_token = response.cookies['csrftoken']
def is_authentificate(self): def is_authentificate(self: Client):
return (not self.token is None) return (not self.token is None)
def login(self, username: str, password: str): def login(self: Client, username: str, password: str):
response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password}) response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password})
return response.content return response.content
def register(self, username: str, password: str): def register(self: Client, username: str, password: str):
response: Response = self._post(urls.accounts_register_url, {'username': username, 'password': password}) response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password})
return response return response.content
def _post(self, uri: str, data: dict): def _post(self: Client, uri: str, data: dict):
url: str = self.url + uri url: str = self.url + uri
if self.token is None: data.update({'csrfmiddlewaretoken': self.csrf_token})
response: Response = self.session.get(url) response: Response = s.post(url, data = data, headers = dict(Referer=url))
self.token = response.cookies['csrftoken']
data.update({'csrfmiddlewaretoken': self.token})
response: Response = self.session.post(url, data = data, headers = dict(Referer=url))
return response.content return response.content

View File

@ -1,31 +0,0 @@
import Client
from urls import *
from uuid import uuid4
def test(value, expected_value, title, description):
if (value == expected_value):
print(title, "[OK]")
return
print (title, "[ERROR]")
print ("expected", expected_value, ", got", value)
if not description is None:
print (description)
def test_accounts_register():
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()
if __name__ == "__main__":
tests()

View File

@ -1,3 +1,3 @@
accounts_url: str = "api/accounts/" accounts_url: str = "/api/accounts/"
accounts_login_url: str = accounts_url + "login" accounts_login_url: str = "login"
accounts_register_url: str = accounts_url + "register" accounts_register_url: str = "register"

0
tests/accounts/login.py Normal file
View File

View File

@ -0,0 +1,10 @@
from unittest import TestCase
import uuid
class RegisterTest(TestCase):
def setUp(self):
self.username: str = uuid.uuid4()
self.password: str = uuid.uuid4()
def test_valid