Added the PREFIX constant to simplify the CurrencyTestCase test case.
This commit is contained in:
parent
fb9ff1d7ff
commit
0491614ae4
@ -52,6 +52,8 @@ zzc: CurrencyData = CurrencyData("ZZC", "Testing Dollar #C")
|
|||||||
"""The third test currency."""
|
"""The third test currency."""
|
||||||
zzd: CurrencyData = CurrencyData("ZZD", "Testing Dollar #D")
|
zzd: CurrencyData = CurrencyData("ZZD", "Testing Dollar #D")
|
||||||
"""The fourth test currency."""
|
"""The fourth test currency."""
|
||||||
|
PREFIX: str = "/accounting/currencies"
|
||||||
|
"""The URL prefix of the currency management."""
|
||||||
|
|
||||||
|
|
||||||
class CurrencyCommandTestCase(unittest.TestCase):
|
class CurrencyCommandTestCase(unittest.TestCase):
|
||||||
@ -122,21 +124,19 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
self.client, self.csrf_token = get_client(self, self.app, "editor")
|
self.client, self.csrf_token = get_client(self, self.app, "editor")
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
response = self.client.post("/accounting/currencies/store",
|
response = self.client.post(f"{PREFIX}/store",
|
||||||
data={"csrf_token": self.csrf_token,
|
data={"csrf_token": self.csrf_token,
|
||||||
"code": zza.code,
|
"code": zza.code,
|
||||||
"name": zza.name})
|
"name": zza.name})
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(response.headers["Location"],
|
self.assertEqual(response.headers["Location"], f"{PREFIX}/{zza.code}")
|
||||||
f"/accounting/currencies/{zza.code}")
|
|
||||||
|
|
||||||
response = self.client.post("/accounting/currencies/store",
|
response = self.client.post(f"{PREFIX}/store",
|
||||||
data={"csrf_token": self.csrf_token,
|
data={"csrf_token": self.csrf_token,
|
||||||
"code": zzb.code,
|
"code": zzb.code,
|
||||||
"name": zzb.name})
|
"name": zzb.name})
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(response.headers["Location"],
|
self.assertEqual(response.headers["Location"], f"{PREFIX}/{zzb.code}")
|
||||||
f"/accounting/currencies/{zzb.code}")
|
|
||||||
|
|
||||||
def test_nobody(self) -> None:
|
def test_nobody(self) -> None:
|
||||||
"""Test the permission as nobody.
|
"""Test the permission as nobody.
|
||||||
@ -146,31 +146,31 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
client, csrf_token = get_client(self, self.app, "nobody")
|
client, csrf_token = get_client(self, self.app, "nobody")
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
response = client.get("/accounting/currencies")
|
response = client.get(PREFIX)
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.get(f"/accounting/currencies/{zza.code}")
|
response = client.get(f"{PREFIX}/{zza.code}")
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.get("/accounting/currencies/create")
|
response = client.get(f"{PREFIX}/create")
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.post("/accounting/currencies/store",
|
response = client.post(f"{PREFIX}/store",
|
||||||
data={"csrf_token": csrf_token,
|
data={"csrf_token": csrf_token,
|
||||||
"code": zzc.code,
|
"code": zzc.code,
|
||||||
"name": zzc.name})
|
"name": zzc.name})
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.get(f"/accounting/currencies/{zza.code}/edit")
|
response = client.get(f"{PREFIX}/{zza.code}/edit")
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.post(f"/accounting/currencies/{zza.code}/update",
|
response = client.post(f"{PREFIX}/{zza.code}/update",
|
||||||
data={"csrf_token": csrf_token,
|
data={"csrf_token": csrf_token,
|
||||||
"code": zzd.code,
|
"code": zzd.code,
|
||||||
"name": zzd.name})
|
"name": zzd.name})
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.post(f"/accounting/currencies/{zzb.code}/delete",
|
response = client.post(f"{PREFIX}/{zzb.code}/delete",
|
||||||
data={"csrf_token": csrf_token})
|
data={"csrf_token": csrf_token})
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
@ -182,31 +182,31 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
client, csrf_token = get_client(self, self.app, "viewer")
|
client, csrf_token = get_client(self, self.app, "viewer")
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
response = client.get("/accounting/currencies")
|
response = client.get(PREFIX)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = client.get(f"/accounting/currencies/{zza.code}")
|
response = client.get(f"{PREFIX}/{zza.code}")
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = client.get("/accounting/currencies/create")
|
response = client.get(f"{PREFIX}/create")
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.post("/accounting/currencies/store",
|
response = client.post(f"{PREFIX}/store",
|
||||||
data={"csrf_token": csrf_token,
|
data={"csrf_token": csrf_token,
|
||||||
"code": zzc.code,
|
"code": zzc.code,
|
||||||
"name": zzc.name})
|
"name": zzc.name})
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.get(f"/accounting/currencies/{zza.code}/edit")
|
response = client.get(f"{PREFIX}/{zza.code}/edit")
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.post(f"/accounting/currencies/{zza.code}/update",
|
response = client.post(f"{PREFIX}/{zza.code}/update",
|
||||||
data={"csrf_token": csrf_token,
|
data={"csrf_token": csrf_token,
|
||||||
"code": zzd.code,
|
"code": zzd.code,
|
||||||
"name": zzd.name})
|
"name": zzd.name})
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
response = client.post(f"/accounting/currencies/{zzb.code}/delete",
|
response = client.post(f"{PREFIX}/{zzb.code}/delete",
|
||||||
data={"csrf_token": csrf_token})
|
data={"csrf_token": csrf_token})
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
@ -217,41 +217,36 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
response = self.client.get("/accounting/currencies")
|
response = self.client.get(PREFIX)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.get(f"/accounting/currencies/{zza.code}")
|
response = self.client.get(f"{PREFIX}/{zza.code}")
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.get("/accounting/currencies/create")
|
response = self.client.get(f"{PREFIX}/create")
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.post("/accounting/currencies/store",
|
response = self.client.post(f"{PREFIX}/store",
|
||||||
data={"csrf_token": self.csrf_token,
|
data={"csrf_token": self.csrf_token,
|
||||||
"code": zzc.code,
|
"code": zzc.code,
|
||||||
"name": zzc.name})
|
"name": zzc.name})
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(response.headers["Location"],
|
self.assertEqual(response.headers["Location"], f"{PREFIX}/{zzc.code}")
|
||||||
f"/accounting/currencies/{zzc.code}")
|
|
||||||
|
|
||||||
response = self.client.get(f"/accounting/currencies/{zza.code}/edit")
|
response = self.client.get(f"{PREFIX}/{zza.code}/edit")
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.post(
|
response = self.client.post(f"{PREFIX}/{zza.code}/update",
|
||||||
f"/accounting/currencies/{zza.code}/update",
|
|
||||||
data={"csrf_token": self.csrf_token,
|
data={"csrf_token": self.csrf_token,
|
||||||
"code": zzd.code,
|
"code": zzd.code,
|
||||||
"name": zzd.name})
|
"name": zzd.name})
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(response.headers["Location"],
|
self.assertEqual(response.headers["Location"], f"{PREFIX}/{zzd.code}")
|
||||||
f"/accounting/currencies/{zzd.code}")
|
|
||||||
|
|
||||||
response = self.client.post(
|
response = self.client.post(f"{PREFIX}/{zzb.code}/delete",
|
||||||
f"/accounting/currencies/{zzb.code}/delete",
|
|
||||||
data={"csrf_token": self.csrf_token})
|
data={"csrf_token": self.csrf_token})
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(response.headers["Location"],
|
self.assertEqual(response.headers["Location"], PREFIX)
|
||||||
"/accounting/currencies")
|
|
||||||
|
|
||||||
def test_add(self) -> None:
|
def test_add(self) -> None:
|
||||||
"""Tests to add the currencies.
|
"""Tests to add the currencies.
|
||||||
@ -260,9 +255,9 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
from accounting.models import Currency
|
from accounting.models import Currency
|
||||||
from test_site import db
|
from test_site import db
|
||||||
create_uri: str = "/accounting/currencies/create"
|
create_uri: str = f"{PREFIX}/create"
|
||||||
store_uri: str = "/accounting/currencies/store"
|
store_uri: str = f"{PREFIX}/store"
|
||||||
detail_uri: str = f"/accounting/currencies/{zzc.code}"
|
detail_uri: str = f"{PREFIX}/{zzc.code}"
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
@ -345,10 +340,10 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
from accounting.models import Currency
|
from accounting.models import Currency
|
||||||
from test_site import db
|
from test_site import db
|
||||||
detail_uri: str = f"/accounting/currencies/{zza.code}"
|
detail_uri: str = f"{PREFIX}/{zza.code}"
|
||||||
edit_uri: str = f"/accounting/currencies/{zza.code}/edit"
|
edit_uri: str = f"{PREFIX}/{zza.code}/edit"
|
||||||
update_uri: str = f"/accounting/currencies/{zza.code}/update"
|
update_uri: str = f"{PREFIX}/{zza.code}/update"
|
||||||
detail_c_uri: str = f"/accounting/currencies/{zzc.code}"
|
detail_c_uri: str = f"{PREFIX}/{zzc.code}"
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
# Success, with spaces to be stripped
|
# Success, with spaces to be stripped
|
||||||
@ -425,8 +420,8 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
from accounting.models import Currency
|
from accounting.models import Currency
|
||||||
from test_site import db
|
from test_site import db
|
||||||
detail_uri: str = f"/accounting/currencies/{zza.code}"
|
detail_uri: str = f"{PREFIX}/{zza.code}"
|
||||||
update_uri: str = f"/accounting/currencies/{zza.code}/update"
|
update_uri: str = f"{PREFIX}/{zza.code}/update"
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
@ -464,8 +459,8 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
from test_site import db
|
from test_site import db
|
||||||
editor_username, editor2_username = "editor", "editor2"
|
editor_username, editor2_username = "editor", "editor2"
|
||||||
client, csrf_token = get_client(self, self.app, editor2_username)
|
client, csrf_token = get_client(self, self.app, editor2_username)
|
||||||
detail_uri: str = f"/accounting/currencies/{zza.code}"
|
detail_uri: str = f"{PREFIX}/{zza.code}"
|
||||||
update_uri: str = f"/accounting/currencies/{zza.code}/update"
|
update_uri: str = f"{PREFIX}/{zza.code}/update"
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
@ -492,8 +487,8 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
from accounting.models import Currency
|
from accounting.models import Currency
|
||||||
from test_site import db
|
from test_site import db
|
||||||
detail_uri: str = f"/accounting/currencies/{zza.code}"
|
detail_uri: str = f"{PREFIX}/{zza.code}"
|
||||||
update_uri: str = f"/accounting/currencies/{zza.code}/update"
|
update_uri: str = f"{PREFIX}/{zza.code}/update"
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
@ -552,9 +547,9 @@ class CurrencyTestCase(unittest.TestCase):
|
|||||||
:return: None.
|
:return: None.
|
||||||
"""
|
"""
|
||||||
from accounting.models import Currency
|
from accounting.models import Currency
|
||||||
detail_uri: str = f"/accounting/currencies/{zza.code}"
|
detail_uri: str = f"{PREFIX}/{zza.code}"
|
||||||
delete_uri: str = f"/accounting/currencies/{zza.code}/delete"
|
delete_uri: str = f"{PREFIX}/{zza.code}/delete"
|
||||||
list_uri: str = "/accounting/currencies"
|
list_uri: str = PREFIX
|
||||||
response: httpx.Response
|
response: httpx.Response
|
||||||
|
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
|
Loading…
Reference in New Issue
Block a user