Compare commits
No commits in common. "21ed36fd99f2ef0a771c6745e9bb527ba6a18447" and "66398936f0c99364fa148eff6fd41629ba3a9089" have entirely different histories.
21ed36fd99
...
66398936f0
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
.env
|
|
||||||
|
|
||||||
*.pyc
|
|
@ -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
|
31
src/tests.py
31
src/tests.py
@ -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()
|
|
@ -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
0
tests/accounts/login.py
Normal file
10
tests/accounts/register.py
Normal file
10
tests/accounts/register.py
Normal 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
|
Loading…
Reference in New Issue
Block a user