Added the TEST_SERVER constant in testlib.py, for consistency.
This commit is contained in:
parent
788225826d
commit
952061c4bb
@ -27,6 +27,7 @@ from accounting.utils.next_uri import append_next, inherit_next, or_next
|
|||||||
from accounting.utils.pagination import Pagination, DEFAULT_PAGE_SIZE
|
from accounting.utils.pagination import Pagination, DEFAULT_PAGE_SIZE
|
||||||
from accounting.utils.query import parse_query_keywords
|
from accounting.utils.query import parse_query_keywords
|
||||||
from test_site import create_app
|
from test_site import create_app
|
||||||
|
from testlib import TEST_SERVER
|
||||||
|
|
||||||
|
|
||||||
class NextUriTestCase(unittest.TestCase):
|
class NextUriTestCase(unittest.TestCase):
|
||||||
@ -66,9 +67,8 @@ class NextUriTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.app.add_url_rule("/test-next", view_func=test_next_uri_view,
|
self.app.add_url_rule("/test-next", view_func=test_next_uri_view,
|
||||||
methods=["GET", "POST"])
|
methods=["GET", "POST"])
|
||||||
client: httpx.Client = httpx.Client(app=self.app,
|
client: httpx.Client = httpx.Client(app=self.app, base_url=TEST_SERVER)
|
||||||
base_url="https://testserver")
|
client.headers["Referer"] = TEST_SERVER
|
||||||
client.headers["Referer"] = "https://testserver"
|
|
||||||
csrf_token: str = client.get("/test-csrf").text
|
csrf_token: str = client.get("/test-csrf").text
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
@ -96,9 +96,8 @@ class NextUriTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.app.add_url_rule("/test-no-next", view_func=test_no_next_uri_view,
|
self.app.add_url_rule("/test-no-next", view_func=test_no_next_uri_view,
|
||||||
methods=["GET", "POST"])
|
methods=["GET", "POST"])
|
||||||
client: httpx.Client = httpx.Client(app=self.app,
|
client: httpx.Client = httpx.Client(app=self.app, base_url=TEST_SERVER)
|
||||||
base_url="https://testserver")
|
client.headers["Referer"] = TEST_SERVER
|
||||||
client.headers["Referer"] = "https://testserver"
|
|
||||||
csrf_token: str = client.get("/test-csrf").text
|
csrf_token: str = client.get("/test-csrf").text
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
@ -188,8 +187,8 @@ class PaginationTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(pagination.list, self.params.result)
|
self.assertEqual(pagination.list, self.params.result)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
self.client = httpx.Client(app=self.app, base_url="https://testserver")
|
self.client = httpx.Client(app=self.app, base_url=TEST_SERVER)
|
||||||
self.client.headers["Referer"] = "https://testserver"
|
self.client.headers["Referer"] = TEST_SERVER
|
||||||
|
|
||||||
def __test_success(self, query: str, items: range,
|
def __test_success(self, query: str, items: range,
|
||||||
result: range, is_paged: bool = True,
|
result: range, is_paged: bool = True,
|
||||||
|
@ -23,6 +23,9 @@ from html.parser import HTMLParser
|
|||||||
import httpx
|
import httpx
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
|
TEST_SERVER: str = "https://testserver"
|
||||||
|
"""The test server URI."""
|
||||||
|
|
||||||
|
|
||||||
def get_client(app: Flask, username: str) -> tuple[httpx.Client, str]:
|
def get_client(app: Flask, username: str) -> tuple[httpx.Client, str]:
|
||||||
"""Returns a user client.
|
"""Returns a user client.
|
||||||
@ -31,8 +34,8 @@ def get_client(app: Flask, username: str) -> tuple[httpx.Client, str]:
|
|||||||
:param username: The username.
|
:param username: The username.
|
||||||
:return: A tuple of the client and the CSRF token.
|
:return: A tuple of the client and the CSRF token.
|
||||||
"""
|
"""
|
||||||
client: httpx.Client = httpx.Client(app=app, base_url="https://testserver")
|
client: httpx.Client = httpx.Client(app=app, base_url=TEST_SERVER)
|
||||||
client.headers["Referer"] = "https://testserver"
|
client.headers["Referer"] = TEST_SERVER
|
||||||
csrf_token: str = get_csrf_token(client, "/login")
|
csrf_token: str = get_csrf_token(client, "/login")
|
||||||
response: httpx.Response = client.post("/login",
|
response: httpx.Response = client.post("/login",
|
||||||
data={"csrf_token": csrf_token,
|
data={"csrf_token": csrf_token,
|
||||||
|
Loading…
Reference in New Issue
Block a user