Removed the CSRF token from the get_client function in testlib.py, so that type hints and documentation can be added to the client and the CSRF token properties separately.

This commit is contained in:
2023-06-10 09:35:51 +08:00
parent 501c4b1d22
commit 356d2010cc
10 changed files with 105 additions and 49 deletions

View File

@@ -25,8 +25,8 @@ from flask import Flask
from accounting.utils.next_uri import encode_next
from test_site import db
from testlib import NEXT_URI, create_test_app, get_client, set_locale, \
add_journal_entry
from testlib import NEXT_URI, create_test_app, get_client, get_csrf_token, \
set_locale, add_journal_entry
class CurrencyData:
@@ -74,7 +74,10 @@ class CurrencyTestCase(unittest.TestCase):
Currency.query.delete()
db.session.commit()
self.client, self.csrf_token = get_client(self.app, "editor")
self.client: httpx.Client = get_client(self.app, "editor")
"""The user client."""
self.csrf_token: str = get_csrf_token(self.client)
"""The CSRF token."""
response: httpx.Response
response = self.client.post(f"{PREFIX}/store",
@@ -96,7 +99,8 @@ class CurrencyTestCase(unittest.TestCase):
:return: None.
"""
client, csrf_token = get_client(self.app, "nobody")
client: httpx.Client = get_client(self.app, "nobody")
csrf_token: str = get_csrf_token(client)
response: httpx.Response
response = client.get(PREFIX)
@@ -132,7 +136,8 @@ class CurrencyTestCase(unittest.TestCase):
:return: None.
"""
client, csrf_token = get_client(self.app, "viewer")
client: httpx.Client = get_client(self.app, "viewer")
csrf_token: str = get_csrf_token(client)
response: httpx.Response
response = client.get(PREFIX)
@@ -410,7 +415,8 @@ class CurrencyTestCase(unittest.TestCase):
"""
from accounting.models import Currency
editor_username, admin_username = "editor", "admin"
client, csrf_token = get_client(self.app, admin_username)
client: httpx.Client = get_client(self.app, admin_username)
csrf_token: str = get_csrf_token(client)
detail_uri: str = f"{PREFIX}/{USD.code}"
update_uri: str = f"{PREFIX}/{USD.code}/update"
currency: Currency