Compare commits

...

6 Commits

Author SHA1 Message Date
21ed36fd99 update .gitignore, remove .pyc 2023-11-03 21:05:58 +01:00
75a0b5055e fix: 2023-11-03 21:05:41 +01:00
92da8114c3 add: register test 2023-11-03 21:04:38 +01:00
80e638072f fix url 2023-11-03 20:39:52 +01:00
a03000891e fix: urls 2023-11-03 20:39:22 +01:00
2c0878b6af add gitignore 2023-11-03 20:39:09 +01:00
6 changed files with 49 additions and 25 deletions

3
.gitignore vendored Normal file
View File

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

View File

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

31
src/tests.py Normal file
View File

@ -0,0 +1,31 @@
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_login_url: str = "login"
accounts_register_url: str = "register"
accounts_url: str = "api/accounts/"
accounts_login_url: str = accounts_url + "login"
accounts_register_url: str = accounts_url + "register"

View File

@ -1,10 +0,0 @@
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