Compare commits
6 Commits
66398936f0
...
21ed36fd99
Author | SHA1 | Date | |
---|---|---|---|
21ed36fd99 | |||
75a0b5055e | |||
92da8114c3 | |||
80e638072f | |||
a03000891e | |||
2c0878b6af |
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.env
|
||||||
|
|
||||||
|
*.pyc
|
@ -1,6 +1,5 @@
|
|||||||
import requests
|
import requests
|
||||||
from requets.Session import Session
|
from requests import Response, Request, Session
|
||||||
from requests import Response, Requests
|
|
||||||
|
|
||||||
import urls
|
import urls
|
||||||
|
|
||||||
@ -9,22 +8,23 @@ 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: Client):
|
def is_authentificate(self):
|
||||||
return (not self.token is None)
|
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})
|
response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password})
|
||||||
return response.content
|
return response.content
|
||||||
|
|
||||||
def register(self: Client, username: str, password: str):
|
def register(self, username: str, password: str):
|
||||||
response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password})
|
response: Response = self._post(urls.accounts_register_url, {'username': username, 'password': password})
|
||||||
return response.content
|
return response
|
||||||
|
|
||||||
def _post(self: Client, uri: str, data: dict):
|
def _post(self, uri: str, data: dict):
|
||||||
url: str = self.url + uri
|
url: str = self.url + uri
|
||||||
data.update({'csrfmiddlewaretoken': self.csrf_token})
|
if self.token is None:
|
||||||
response: Response = s.post(url, data = data, headers = dict(Referer=url))
|
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
|
return response.content
|
31
src/tests.py
Normal file
31
src/tests.py
Normal 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()
|
@ -1,3 +1,3 @@
|
|||||||
accounts_url: str = "/api/accounts/"
|
accounts_url: str = "api/accounts/"
|
||||||
accounts_login_url: str = "login"
|
accounts_login_url: str = accounts_url + "login"
|
||||||
accounts_register_url: str = "register"
|
accounts_register_url: str = accounts_url + "register"
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user