Replaced the "editor" and "editor2" accounts in the test site with "admin" and "editor", to be clear.

This commit is contained in:
依瑪貓 2023-03-24 08:32:28 +08:00
parent 4ccaf01b3c
commit d2f11e8779
7 changed files with 33 additions and 33 deletions

View File

@ -547,8 +547,8 @@ class AccountTestCase(unittest.TestCase):
:return: None.
"""
from accounting.models import Account
editor_username, editor2_username = "editor", "editor2"
client, csrf_token = get_client(self.app, editor2_username)
editor_username, admin_username = "editor", "admin"
client, csrf_token = get_client(self.app, admin_username)
detail_uri: str = f"{PREFIX}/{CASH.code}"
update_uri: str = f"{PREFIX}/{CASH.code}/update"
account: Account
@ -571,7 +571,7 @@ class AccountTestCase(unittest.TestCase):
self.assertEqual(account.created_by.username,
editor_username)
self.assertEqual(account.updated_by.username,
editor2_username)
admin_username)
def test_l10n(self) -> None:
"""Tests the localization.

View File

@ -471,8 +471,8 @@ class CurrencyTestCase(unittest.TestCase):
:return: None.
"""
from accounting.models import Currency
editor_username, editor2_username = "editor", "editor2"
client, csrf_token = get_client(self.app, editor2_username)
editor_username, admin_username = "editor", "admin"
client, csrf_token = get_client(self.app, admin_username)
detail_uri: str = f"{PREFIX}/{USD.code}"
update_uri: str = f"{PREFIX}/{USD.code}/update"
currency: Currency
@ -493,7 +493,7 @@ class CurrencyTestCase(unittest.TestCase):
with self.app.app_context():
currency = db.session.get(Currency, USD.code)
self.assertEqual(currency.created_by.username, editor_username)
self.assertEqual(currency.updated_by.username, editor2_username)
self.assertEqual(currency.updated_by.username, admin_username)
def test_api_exists(self) -> None:
"""Tests the API to check if a code exists.

View File

@ -537,8 +537,8 @@ class CashReceiptJournalEntryTestCase(unittest.TestCase):
from accounting.models import JournalEntry
journal_entry_id: int \
= add_journal_entry(self.client, self.__get_add_form())
editor_username, editor2_username = "editor", "editor2"
client, csrf_token = get_client(self.app, editor2_username)
editor_username, admin_username = "editor", "admin"
client, csrf_token = get_client(self.app, admin_username)
detail_uri: str = f"{PREFIX}/{journal_entry_id}?next=%2F_next"
update_uri: str = f"{PREFIX}/{journal_entry_id}/update"
journal_entry: JournalEntry
@ -562,7 +562,7 @@ class CashReceiptJournalEntryTestCase(unittest.TestCase):
self.assertEqual(journal_entry.created_by.username,
editor_username)
self.assertEqual(journal_entry.updated_by.username,
editor2_username)
admin_username)
def test_delete(self) -> None:
"""Tests to delete a journal entry.
@ -1163,8 +1163,8 @@ class CashDisbursementJournalEntryTestCase(unittest.TestCase):
from accounting.models import JournalEntry
journal_entry_id: int \
= add_journal_entry(self.client, self.__get_add_form())
editor_username, editor2_username = "editor", "editor2"
client, csrf_token = get_client(self.app, editor2_username)
editor_username, admin_username = "editor", "admin"
client, csrf_token = get_client(self.app, admin_username)
detail_uri: str = f"{PREFIX}/{journal_entry_id}?next=%2F_next"
update_uri: str = f"{PREFIX}/{journal_entry_id}/update"
journal_entry: JournalEntry
@ -1188,7 +1188,7 @@ class CashDisbursementJournalEntryTestCase(unittest.TestCase):
self.assertEqual(journal_entry.created_by.username,
editor_username)
self.assertEqual(journal_entry.updated_by.username,
editor2_username)
admin_username)
def test_delete(self) -> None:
"""Tests to delete a journal entry.
@ -1837,8 +1837,8 @@ class TransferJournalEntryTestCase(unittest.TestCase):
from accounting.models import JournalEntry
journal_entry_id: int \
= add_journal_entry(self.client, self.__get_add_form())
editor_username, editor2_username = "editor", "editor2"
client, csrf_token = get_client(self.app, editor2_username)
editor_username, admin_username = "editor", "admin"
client, csrf_token = get_client(self.app, admin_username)
detail_uri: str = f"{PREFIX}/{journal_entry_id}?next=%2F_next"
update_uri: str = f"{PREFIX}/{journal_entry_id}/update"
journal_entry: JournalEntry
@ -1862,7 +1862,7 @@ class TransferJournalEntryTestCase(unittest.TestCase):
self.assertEqual(journal_entry.created_by.username,
editor_username)
self.assertEqual(journal_entry.updated_by.username,
editor2_username)
admin_username)
def test_save_as_receipt(self) -> None:
"""Tests to save a transfer journal entry as a cash receipt journal

View File

@ -67,7 +67,7 @@ class OptionTestCase(unittest.TestCase):
self.assertEqual(result.exit_code, 0)
Option.query.delete()
self.client, self.csrf_token = get_client(self.app, "editor")
self.client, self.csrf_token = get_client(self.app, "admin")
self.data: TestData = TestData(self.app, self.client, self.csrf_token)
def test_nobody(self) -> None:
@ -104,12 +104,12 @@ class OptionTestCase(unittest.TestCase):
response = client.post(UPDATE_URI, data=self.__get_form(csrf_token))
self.assertEqual(response.status_code, 403)
def test_editor2(self) -> None:
"""Test the permission as non-administrator.
def test_editor(self) -> None:
"""Test the permission as editor.
:return: None.
"""
client, csrf_token = get_client(self.app, "editor2")
client, csrf_token = get_client(self.app, "editor")
response: httpx.Response
response = client.get(DETAIL_URI)
@ -121,7 +121,7 @@ class OptionTestCase(unittest.TestCase):
response = client.post(UPDATE_URI, data=self.__get_form(csrf_token))
self.assertEqual(response.status_code, 403)
def test_editor(self) -> None:
def test_admin(self) -> None:
"""Test the permission as administrator.
:return: None.
@ -343,7 +343,7 @@ class OptionTestCase(unittest.TestCase):
"""
from accounting.models import Option
from accounting.utils.user import get_user_pk
editor_username, editor2_username = "editor", "editor2"
admin_username, editor_username = "admin", "editor"
option: Option | None
response: httpx.Response
@ -352,11 +352,11 @@ class OptionTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], DETAIL_URI)
with self.app.app_context():
editor2_pk: int = get_user_pk(editor2_username)
editor_pk: int = get_user_pk(editor_username)
option = db.session.get(Option, "recurring")
self.assertIsNotNone(option)
option.created_by_id = editor2_pk
option.updated_by_id = editor2_pk
option.created_by_id = editor_pk
option.updated_by_id = editor_pk
db.session.commit()
form: dict[str, str] = self.__get_form()
@ -371,8 +371,8 @@ class OptionTestCase(unittest.TestCase):
with self.app.app_context():
option = db.session.get(Option, "recurring")
self.assertIsNotNone(option)
self.assertEqual(option.created_by.username, editor2_username)
self.assertEqual(option.updated_by.username, editor_username)
self.assertEqual(option.created_by.username, editor_username)
self.assertEqual(option.updated_by.username, admin_username)
def __get_form(self, csrf_token: str | None = None) -> dict[str, str]:
"""Returns the option form.

View File

@ -72,15 +72,15 @@ def create_app(is_testing: bool = False) -> Flask:
def can_view(self) -> bool:
return auth.current_user() is not None \
and auth.current_user().username in ["viewer", "editor",
"editor2"]
"admin"]
def can_edit(self) -> bool:
return auth.current_user() is not None \
and auth.current_user().username in ["editor", "editor2"]
and auth.current_user().username in ["editor", "admin"]
def can_admin(self) -> bool:
return auth.current_user() is not None \
and auth.current_user().username == "editor"
and auth.current_user().username == "admin"
@property
def cls(self) -> t.Type[auth.User]:
@ -112,7 +112,7 @@ def init_db_command() -> None:
"""Initializes the database."""
db.create_all()
from .auth import User
for username in ["viewer", "editor", "editor2", "nobody"]:
for username in ["viewer", "editor", "admin", "nobody"]:
if User.query.filter(User.username == username).first() is None:
db.session.add(User(username=username))
db.session.commit()

View File

@ -58,8 +58,8 @@ def login() -> redirect:
:return: The redirection to the home page.
"""
if request.form.get("username") not in ["viewer", "editor", "editor2",
"nobody"]:
if request.form.get("username") not in {"viewer", "editor", "admin",
"nobody"}:
return redirect(url_for("auth.login"))
session["user"] = request.form.get("username")
return redirect(url_for("home.home"))

View File

@ -29,7 +29,7 @@ First written: 2023/1/27
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button class="btn btn-primary" type="submit" name="username" value="viewer">{{ _("Viewer") }}</button>
<button class="btn btn-primary" type="submit" name="username" value="editor">{{ _("Editor") }}</button>
<button class="btn btn-primary" type="submit" name="username" value="editor2">{{ _("Editor2") }}</button>
<button class="btn btn-primary" type="submit" name="username" value="admin">{{ _("Administrator") }}</button>
<button class="btn btn-primary" type="submit" name="username" value="nobody">{{ _("Nobody") }}</button>
</form>