commit 66398936f0c99364fa148eff6fd41629ba3a9089 Author: starnakin Date: Thu Nov 2 23:26:05 2023 +0100 init python-api lib diff --git a/src/Client.py b/src/Client.py new file mode 100644 index 0000000..2688e96 --- /dev/null +++ b/src/Client.py @@ -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 \ No newline at end of file diff --git a/src/urls.py b/src/urls.py new file mode 100644 index 0000000..afdb53e --- /dev/null +++ b/src/urls.py @@ -0,0 +1,3 @@ +accounts_url: str = "/api/accounts/" +accounts_login_url: str = "login" +accounts_register_url: str = "register" \ No newline at end of file diff --git a/tests/accounts/login.py b/tests/accounts/login.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/accounts/register.py b/tests/accounts/register.py new file mode 100644 index 0000000..bd3ce71 --- /dev/null +++ b/tests/accounts/register.py @@ -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 \ No newline at end of file