Compare commits
2 Commits
22ff3d58d3
...
a13feba991
Author | SHA1 | Date | |
---|---|---|---|
a13feba991 | |||
1f8bb5800b |
@ -9,12 +9,13 @@ class Client:
|
|||||||
def __init__(self, url: str):
|
def __init__(self, url: str):
|
||||||
self.url: str = url
|
self.url: str = url
|
||||||
self.token: str = None
|
self.token: str = None
|
||||||
|
self.csrf_token: str = None
|
||||||
self.session: Session = Session()
|
self.session: Session = Session()
|
||||||
self.accounts: Accounts = Accounts(self)
|
self.accounts: Accounts = Accounts(self)
|
||||||
self.profiles: Profiles = Profiles(self)
|
self.profiles: Profiles = Profiles(self)
|
||||||
|
|
||||||
def is_authentificate(self):
|
def is_authentificate(self):
|
||||||
return (not self.token is None)
|
return (self.token is not None)
|
||||||
|
|
||||||
def login(self, username: str, password: str):
|
def login(self, username: str, password: str):
|
||||||
response: Response = self._post(urls.accounts_login, {'username': username, 'password': password})
|
response: Response = self._post(urls.accounts_login, {'username': username, 'password': password})
|
||||||
@ -22,16 +23,16 @@ class Client:
|
|||||||
|
|
||||||
def _post(self, uri: str, data: dict = {}):
|
def _post(self, uri: str, data: dict = {}):
|
||||||
url: str = self.url + uri
|
url: str = self.url + uri
|
||||||
if self.token is None:
|
if self.csrf_token is None:
|
||||||
response: Response = self.session.get(url)
|
response: Response = self.session.get(url)
|
||||||
self.token = response.cookies.get('csrftoken')
|
self.csrf_token = response.cookies.get('csrftoken')
|
||||||
data.update({'csrfmiddlewaretoken': self.token})
|
data.update({'csrfmiddlewaretoken': self.csrf_token})
|
||||||
response: Response = self.session.post(url, data = data, headers = dict(Referer=url))
|
response: Response = self.session.post(url, data = data, headers = dict(Referer=url))
|
||||||
self.token = response.cookies.get('csrftoken')
|
self.csrf_token = response.cookies.get('csrftoken')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _get(self, uri: str):
|
def _get(self, uri: str):
|
||||||
url: str = self.url + uri
|
url: str = self.url + uri
|
||||||
response: Response = self.session.get(url)
|
response: Response = self.session.get(url)
|
||||||
self.token = response.cookies.get('csrftoken')
|
self.csrf_token = response.cookies.get('csrftoken')
|
||||||
return response
|
return response
|
@ -1,6 +1,7 @@
|
|||||||
def test(func: callable, params, expected_value, title: str, description = None):
|
def test(func: callable, params, expected_value, title: str, description = None):
|
||||||
print(title, end=" ")
|
print(title, end=" ")
|
||||||
if (func(*params) == expected_value):
|
value = func(*params)
|
||||||
|
if (value == expected_value):
|
||||||
print("[OK]")
|
print("[OK]")
|
||||||
return
|
return
|
||||||
print ("[ERROR]")
|
print ("[ERROR]")
|
||||||
|
Loading…
Reference in New Issue
Block a user