init python-api lib
This commit is contained in:
commit
66398936f0
30
src/Client.py
Normal file
30
src/Client.py
Normal file
@ -0,0 +1,30 @@
|
||||
import requests
|
||||
from requets.Session import Session
|
||||
from requests import Response, Requests
|
||||
|
||||
import urls
|
||||
|
||||
class Client:
|
||||
def __init__(self, url: str):
|
||||
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):
|
||||
return (not self.token is None)
|
||||
|
||||
def login(self: Client, 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 _post(self: Client, 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))
|
||||
return response.content
|
3
src/urls.py
Normal file
3
src/urls.py
Normal file
@ -0,0 +1,3 @@
|
||||
accounts_url: str = "/api/accounts/"
|
||||
accounts_login_url: str = "login"
|
||||
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