housekeep: TU rename - code changes

Renaming of symbols. Functions, variables, values, DB values, etc.
Basically everything that is not user-facing.

This only covers "Trusted User" things:
tests, comments, etc. will covered in a following commit.
This commit is contained in:
moson 2023-09-01 13:25:21 +02:00
parent 7466e96449
commit 1702075875
No known key found for this signature in database
GPG key ID: 4A4760AB4EE15296
34 changed files with 265 additions and 203 deletions

View file

@ -17,9 +17,9 @@ from aurweb.db import create, query
from aurweb.models.accepted_term import AcceptedTerm
from aurweb.models.account_type import (
DEVELOPER_ID,
TRUSTED_USER,
TRUSTED_USER_AND_DEV_ID,
TRUSTED_USER_ID,
PACKAGE_MAINTAINER,
PACKAGE_MAINTAINER_AND_DEV_ID,
PACKAGE_MAINTAINER_ID,
USER_ID,
AccountType,
)
@ -98,7 +98,7 @@ def user() -> User:
@pytest.fixture
def tu_user(user: User):
with db.begin():
user.AccountTypeID = TRUSTED_USER_AND_DEV_ID
user.AccountTypeID = PACKAGE_MAINTAINER_AND_DEV_ID
yield user
@ -661,7 +661,7 @@ def test_get_account_edit_tu_as_tu(client: TestClient, tu_user: User):
"""Test edit get route of another TU as a TU."""
with db.begin():
user2 = create_user("test2")
user2.AccountTypeID = at.TRUSTED_USER_ID
user2.AccountTypeID = at.PACKAGE_MAINTAINER_ID
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
endpoint = f"/account/{user2.Username}/edit"
@ -672,10 +672,10 @@ def test_get_account_edit_tu_as_tu(client: TestClient, tu_user: User):
assert response.status_code == int(HTTPStatus.OK)
# Verify that we have an account type selection and that the
# "{at.TRUSTED_USER}" option is selected.
# "{at.PACKAGE_MAINTAINER}" option is selected.
root = parse_root(response.text)
atype = root.xpath('//select[@id="id_type"]/option[@selected="selected"]')
expected = at.TRUSTED_USER
expected = at.PACKAGE_MAINTAINER
assert atype[0].text.strip() == expected
username = root.xpath('//input[@id="id_username"]')[0]
@ -836,7 +836,7 @@ def test_post_account_edit_type_as_dev(client: TestClient, tu_user: User):
def test_post_account_edit_invalid_type_as_tu(client: TestClient, tu_user: User):
with db.begin():
user2 = create_user("test_tu")
tu_user.AccountTypeID = at.TRUSTED_USER_ID
tu_user.AccountTypeID = at.PACKAGE_MAINTAINER_ID
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
endpoint = f"/account/{user2.Username}/edit"
@ -861,8 +861,8 @@ def test_post_account_edit_invalid_type_as_tu(client: TestClient, tu_user: User)
def test_post_account_edit_dev(client: TestClient, tu_user: User):
# Modify our user to be a "Trusted User & Developer"
name = "Trusted User & Developer"
# Modify our user to be a "Package Maintainer & Developer"
name = "Package Maintainer & Developer"
tu_or_dev = query(AccountType, AccountType.AccountType == name).first()
with db.begin():
user.AccountType = tu_or_dev
@ -1004,7 +1004,7 @@ def test_post_account_edit_suspend_unauthorized(client: TestClient, user: User):
def test_post_account_edit_inactivity(client: TestClient, user: User):
with db.begin():
user.AccountTypeID = TRUSTED_USER_ID
user.AccountTypeID = PACKAGE_MAINTAINER_ID
assert not user.Suspended
cookies = {"AURSID": user.login(Request(), "testPassword")}
@ -1033,7 +1033,7 @@ def test_post_account_edit_inactivity(client: TestClient, user: User):
def test_post_account_edit_suspended(client: TestClient, user: User):
with db.begin():
user.AccountTypeID = TRUSTED_USER_ID
user.AccountTypeID = PACKAGE_MAINTAINER_ID
assert not user.Suspended
cookies = {"AURSID": user.login(Request(), "testPassword")}
@ -1223,7 +1223,7 @@ def test_post_account_edit_self_type_as_user(client: TestClient, user: User):
data = {
"U": user.Username,
"E": user.Email,
"T": TRUSTED_USER_ID,
"T": PACKAGE_MAINTAINER_ID,
"passwd": "testPassword",
}
with client as request:
@ -1298,7 +1298,7 @@ def test_post_account_edit_other_user_type_as_tu(
data = {
"U": user2.Username,
"E": user2.Email,
"T": TRUSTED_USER_ID,
"T": PACKAGE_MAINTAINER_ID,
"passwd": "testPassword",
}
@ -1308,13 +1308,13 @@ def test_post_account_edit_other_user_type_as_tu(
assert resp.status_code == int(HTTPStatus.OK)
# Let's make sure the DB got updated properly.
assert user2.AccountTypeID == TRUSTED_USER_ID
assert user2.AccountTypeID == PACKAGE_MAINTAINER_ID
# and also that this got logged out at DEBUG level.
expected = (
f"Trusted User '{tu_user.Username}' has "
f"Package Maintainer '{tu_user.Username}' has "
f"modified '{user2.Username}' account's type to"
f" {TRUSTED_USER}."
f" {PACKAGE_MAINTAINER}."
)
assert expected in caplog.text
@ -1601,7 +1601,7 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
# Set our only user to a Trusted User.
with db.begin():
user.AccountType = (
query(AccountType).filter(AccountType.ID == TRUSTED_USER_ID).first()
query(AccountType).filter(AccountType.ID == PACKAGE_MAINTAINER_ID).first()
)
with client as request:
@ -1615,7 +1615,7 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
row = next(iter(rows))
username, type, status, realname, irc, pgp_key, edit = row
assert type.text.strip() == "Trusted User"
assert type.text.strip() == "Package Maintainer"
with db.begin():
user.AccountType = (
@ -1637,7 +1637,9 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
with db.begin():
user.AccountType = (
query(AccountType).filter(AccountType.ID == TRUSTED_USER_AND_DEV_ID).first()
query(AccountType)
.filter(AccountType.ID == PACKAGE_MAINTAINER_AND_DEV_ID)
.first()
)
with client as request:
@ -1651,7 +1653,7 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
row = next(iter(rows))
username, type, status, realname, irc, pgp_key, edit = row
assert type.text.strip() == "Trusted User & Developer"
assert type.text.strip() == "Package Maintainer & Developer"
def test_post_accounts_status(client: TestClient, user: User, tu_user: User):
@ -1783,7 +1785,9 @@ def test_post_accounts_sortby(client: TestClient, user: User, tu_user: User):
with db.begin():
user.AccountType = (
query(AccountType).filter(AccountType.ID == TRUSTED_USER_AND_DEV_ID).first()
query(AccountType)
.filter(AccountType.ID == PACKAGE_MAINTAINER_AND_DEV_ID)
.first()
)
# Fetch first_rows again with our new AccountType ordering.

View file

@ -48,12 +48,12 @@ def test_adduser_tu():
"-p",
"abcd1234",
"-t",
at.TRUSTED_USER,
at.PACKAGE_MAINTAINER,
]
)
test = db.query(User).filter(User.Username == "test").first()
assert test is not None
assert test.AccountTypeID == at.TRUSTED_USER_ID
assert test.AccountTypeID == at.PACKAGE_MAINTAINER_ID
def test_adduser_ssh_pk():

View file

@ -137,9 +137,9 @@ def test_account_type_required():
account_type_required({"FAKE"})
def test_is_trusted_user():
def test_is_package_maintainer():
user_ = AnonymousUser()
assert not user_.is_trusted_user()
assert not user_.is_package_maintainer()
def test_is_developer():

View file

@ -62,7 +62,7 @@ def redis():
"package_count",
"orphan_count",
"user_count",
"trusted_user_count",
"package_maintainer_count",
"seven_days_old_added",
"seven_days_old_updated",
"year_old_updated",

View file

@ -12,7 +12,7 @@ from fastapi.testclient import TestClient
from aurweb import asgi, config, db
from aurweb.models import PackageBase
from aurweb.models.account_type import TRUSTED_USER_ID, USER_ID
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID, USER_ID
from aurweb.models.user import User
from aurweb.testing.html import get_errors, get_successes, parse_root
from aurweb.testing.requests import Request
@ -42,9 +42,9 @@ def user() -> User:
@pytest.fixture
def trusted_user(user: User) -> User:
def package_maintainer(user: User) -> User:
with db.begin():
user.AccountTypeID = TRUSTED_USER_ID
user.AccountTypeID = PACKAGE_MAINTAINER_ID
yield user
@ -81,7 +81,7 @@ def test_archdev_navbar_authenticated(client: TestClient, user: User):
assert item.text.strip() == expected[i]
def test_archdev_navbar_authenticated_tu(client: TestClient, trusted_user: User):
def test_archdev_navbar_authenticated_tu(client: TestClient, package_maintainer: User):
expected = [
"Dashboard",
"Packages",
@ -91,7 +91,7 @@ def test_archdev_navbar_authenticated_tu(client: TestClient, trusted_user: User)
"Trusted User",
"Logout",
]
cookies = {"AURSID": trusted_user.login(Request(), "testPassword")}
cookies = {"AURSID": package_maintainer.login(Request(), "testPassword")}
with client as request:
request.cookies = cookies
resp = request.get("/")

View file

@ -5,7 +5,7 @@ import pytest
from aurweb import config, db, models, time
from aurweb.models import Package, PackageBase, PackageRequest, User
from aurweb.models.account_type import TRUSTED_USER_ID, USER_ID
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID, USER_ID
from aurweb.models.request_type import ORPHAN_ID
from aurweb.scripts import notify, rendercomment
from aurweb.testing.email import Email
@ -393,7 +393,7 @@ please go to [3] and click "Disable notifications".
def set_tu(users: list[User]) -> User:
with db.begin():
for user in users:
user.AccountTypeID = TRUSTED_USER_ID
user.AccountTypeID = PACKAGE_MAINTAINER_ID
def test_open_close_request(

View file

@ -114,7 +114,9 @@ def maintainer() -> User:
@pytest.fixture
def tu_user():
tu_type = db.query(AccountType, AccountType.AccountType == "Trusted User").first()
tu_type = db.query(
AccountType, AccountType.AccountType == "Package Maintainer"
).first()
with db.begin():
tu_user = db.create(
User,

View file

@ -117,7 +117,9 @@ def comaintainer() -> User:
@pytest.fixture
def tu_user():
tu_type = db.query(AccountType, AccountType.AccountType == "Trusted User").first()
tu_type = db.query(
AccountType, AccountType.AccountType == "Package Maintainer"
).first()
with db.begin():
tu_user = db.create(
User,

View file

@ -8,7 +8,7 @@ from fastapi.testclient import TestClient
from aurweb import asgi, config, db, defaults, time
from aurweb.models import Package, PackageBase, PackageRequest, User
from aurweb.models.account_type import TRUSTED_USER_ID, USER_ID
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID, USER_ID
from aurweb.models.package_comaintainer import PackageComaintainer
from aurweb.models.package_notification import PackageNotification
from aurweb.models.package_request import ACCEPTED_ID, PENDING_ID, REJECTED_ID
@ -161,7 +161,7 @@ def tu_user() -> User:
"""Yield an authenticated Trusted User instance."""
user = create_user("test_tu", "test_tu@example.org")
with db.begin():
user.AccountTypeID = TRUSTED_USER_ID
user.AccountTypeID = PACKAGE_MAINTAINER_ID
cookies = {"AURSID": user.login(Request(), "testPassword")}
user.cookies = cookies
yield user

View file

@ -3,7 +3,7 @@ from prometheus_client import REGISTRY, generate_latest
from aurweb import cache, db, prometheus, time
from aurweb.models import Package, PackageBase, PackageRequest
from aurweb.models.account_type import TRUSTED_USER_ID, USER_ID
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID, USER_ID
from aurweb.models.package_request import (
ACCEPTED_ID,
CLOSED_ID,
@ -64,7 +64,7 @@ def test_data():
# Modify some data to get some variances for our counters
if i == 1:
user.AccountTypeID = TRUSTED_USER_ID
user.AccountTypeID = PACKAGE_MAINTAINER_ID
pkgbase.Maintainer = None
pkgbase.SubmittedTS = now
pkgreq.Status = PENDING_ID
@ -99,7 +99,7 @@ def stats() -> Statistics:
("year_old_updated", 9),
("never_updated", 1),
("user_count", 10),
("trusted_user_count", 1),
("package_maintainer_count", 1),
("regular_user_count", 9),
("updated_packages", 9),
("total_requests", 10),
@ -116,7 +116,7 @@ def test_get_count(stats: Statistics, test_data, counter: str, expected: int):
def test_get_count_change(stats: Statistics, test_data):
pkgs_before = stats.get_count("package_count")
tus_before = stats.get_count("trusted_user_count")
tus_before = stats.get_count("package_maintainer_count")
assert pkgs_before == 10
assert tus_before == 1
@ -127,16 +127,16 @@ def test_get_count_change(stats: Statistics, test_data):
db.delete(pkgbase)
user = db.query(User).filter(User.AccountTypeID == USER_ID).first()
user.AccountTypeID = TRUSTED_USER_ID
user.AccountTypeID = PACKAGE_MAINTAINER_ID
# Values should end up in (fake) redis cache so they should be the same
assert stats.get_count("package_count") == pkgs_before
assert stats.get_count("trusted_user_count") == tus_before
assert stats.get_count("package_maintainer_count") == tus_before
# Let's clear the cache and check again
cache._redis.flushall()
assert stats.get_count("package_count") != pkgs_before
assert stats.get_count("trusted_user_count") != tus_before
assert stats.get_count("package_maintainer_count") != tus_before
def test_update_prometheus_metrics(test_data):

View file

@ -8,7 +8,7 @@ import pytest
from fastapi.testclient import TestClient
from aurweb import config, db, filters, time
from aurweb.models.account_type import DEVELOPER_ID, TRUSTED_USER_ID, AccountType
from aurweb.models.account_type import DEVELOPER_ID, PACKAGE_MAINTAINER_ID, AccountType
from aurweb.models.tu_vote import TUVote
from aurweb.models.tu_voteinfo import TUVoteInfo
from aurweb.models.user import User
@ -90,7 +90,9 @@ def client():
@pytest.fixture
def tu_user():
tu_type = db.query(AccountType, AccountType.AccountType == "Trusted User").first()
tu_type = db.query(
AccountType, AccountType.AccountType == "Package Maintainer"
).first()
with db.begin():
tu_user = db.create(
User,
@ -112,7 +114,7 @@ def tu_user2():
Email="test_tu2@example.org",
RealName="Test TU 2",
Passwd="testPassword",
AccountTypeID=TRUSTED_USER_ID,
AccountTypeID=PACKAGE_MAINTAINER_ID,
)
yield tu_user2
@ -918,7 +920,7 @@ def test_tu_addvote_invalid_type(client: TestClient, tu_user: User):
def test_tu_addvote_post(client: TestClient, tu_user: User, user: User):
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
data = {"user": user.Username, "type": "add_tu", "agenda": "Blah"}
data = {"user": user.Username, "type": "add_pm", "agenda": "Blah"}
with client as request:
request.cookies = cookies
@ -934,7 +936,7 @@ def test_tu_addvote_post_cant_duplicate_username(
):
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
data = {"user": user.Username, "type": "add_tu", "agenda": "Blah"}
data = {"user": user.Username, "type": "add_pm", "agenda": "Blah"}
with client as request:
request.cookies = cookies
@ -970,7 +972,7 @@ def test_tu_addvote_post_invalid_type(client: TestClient, tu_user: User, user: U
def test_tu_addvote_post_invalid_agenda(client: TestClient, tu_user: User, user: User):
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
data = {"user": user.Username, "type": "add_tu"}
data = {"user": user.Username, "type": "add_pm"}
with client as request:
request.cookies = cookies
response = request.post("/addvote", data=data)

View file

@ -2,7 +2,7 @@ import pytest
from sqlalchemy.exc import IntegrityError
from aurweb import db, time
from aurweb.models.account_type import TRUSTED_USER_ID
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID
from aurweb.models.tu_vote import TUVote
from aurweb.models.tu_voteinfo import TUVoteInfo
from aurweb.models.user import User
@ -22,7 +22,7 @@ def user() -> User:
Email="test@example.org",
RealName="Test User",
Passwd="testPassword",
AccountTypeID=TRUSTED_USER_ID,
AccountTypeID=PACKAGE_MAINTAINER_ID,
)
yield user

View file

@ -3,7 +3,7 @@ from sqlalchemy.exc import IntegrityError
from aurweb import db, time
from aurweb.db import create, rollback
from aurweb.models.account_type import TRUSTED_USER_ID
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID
from aurweb.models.tu_voteinfo import TUVoteInfo
from aurweb.models.user import User
@ -22,7 +22,7 @@ def user() -> User:
Email="test@example.org",
RealName="Test User",
Passwd="testPassword",
AccountTypeID=TRUSTED_USER_ID,
AccountTypeID=PACKAGE_MAINTAINER_ID,
)
yield user

View file

@ -4,7 +4,7 @@ import pytest
from aurweb import config, db, time
from aurweb.models import TUVote, TUVoteInfo, User
from aurweb.models.account_type import TRUSTED_USER_ID
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID
from aurweb.scripts import tuvotereminder as reminder
from aurweb.testing.email import Email
@ -47,17 +47,17 @@ def email_pieces(voteinfo: TUVoteInfo) -> Tuple[str, str]:
@pytest.fixture
def user(db_test) -> User:
yield create_user("test", TRUSTED_USER_ID)
yield create_user("test", PACKAGE_MAINTAINER_ID)
@pytest.fixture
def user2() -> User:
yield create_user("test2", TRUSTED_USER_ID)
yield create_user("test2", PACKAGE_MAINTAINER_ID)
@pytest.fixture
def user3() -> User:
yield create_user("test3", TRUSTED_USER_ID)
yield create_user("test3", PACKAGE_MAINTAINER_ID)
@pytest.fixture

View file

@ -12,8 +12,8 @@ from aurweb import db
from aurweb.auth import creds
from aurweb.models.account_type import (
DEVELOPER_ID,
TRUSTED_USER_AND_DEV_ID,
TRUSTED_USER_ID,
PACKAGE_MAINTAINER_AND_DEV_ID,
PACKAGE_MAINTAINER_ID,
USER_ID,
)
from aurweb.models.ban import Ban
@ -53,7 +53,7 @@ def user() -> User:
@pytest.fixture
def tu_user() -> User:
user = create_user("test_tu", TRUSTED_USER_ID)
user = create_user("test_tu", PACKAGE_MAINTAINER_ID)
yield user
@ -65,7 +65,7 @@ def dev_user() -> User:
@pytest.fixture
def tu_and_dev_user() -> User:
user = create_user("test_tu_and_dev", TRUSTED_USER_AND_DEV_ID)
user = create_user("test_tu_and_dev", PACKAGE_MAINTAINER_AND_DEV_ID)
yield user
@ -207,33 +207,33 @@ def test_user_ssh_pub_key(user: User):
def test_user_credential_types(user: User):
assert user.AccountTypeID in creds.user_developer_or_trusted_user
assert user.AccountTypeID not in creds.trusted_user
assert user.AccountTypeID in creds.user_developer_or_package_maintainer
assert user.AccountTypeID not in creds.package_maintainer
assert user.AccountTypeID not in creds.developer
assert user.AccountTypeID not in creds.trusted_user_or_dev
assert user.AccountTypeID not in creds.package_maintainer_or_dev
with db.begin():
user.AccountTypeID = at.TRUSTED_USER_ID
user.AccountTypeID = at.PACKAGE_MAINTAINER_ID
assert user.AccountTypeID in creds.trusted_user
assert user.AccountTypeID in creds.trusted_user_or_dev
assert user.AccountTypeID in creds.package_maintainer
assert user.AccountTypeID in creds.package_maintainer_or_dev
with db.begin():
user.AccountTypeID = at.DEVELOPER_ID
assert user.AccountTypeID in creds.developer
assert user.AccountTypeID in creds.trusted_user_or_dev
assert user.AccountTypeID in creds.package_maintainer_or_dev
with db.begin():
user.AccountTypeID = at.TRUSTED_USER_AND_DEV_ID
user.AccountTypeID = at.PACKAGE_MAINTAINER_AND_DEV_ID
assert user.AccountTypeID in creds.trusted_user
assert user.AccountTypeID in creds.package_maintainer
assert user.AccountTypeID in creds.developer
assert user.AccountTypeID in creds.trusted_user_or_dev
assert user.AccountTypeID in creds.package_maintainer_or_dev
# Some model authorization checks.
assert user.is_elevated()
assert user.is_trusted_user()
assert user.is_package_maintainer()
assert user.is_developer()
@ -255,15 +255,15 @@ def test_user_as_dict(user: User):
assert isinstance(data.get("RegistrationTS"), datetime)
def test_user_is_trusted_user(user: User):
def test_user_is_package_maintainer(user: User):
with db.begin():
user.AccountTypeID = at.TRUSTED_USER_ID
assert user.is_trusted_user() is True
user.AccountTypeID = at.PACKAGE_MAINTAINER_ID
assert user.is_package_maintainer() is True
# Do it again with the combined role.
with db.begin():
user.AccountTypeID = at.TRUSTED_USER_AND_DEV_ID
assert user.is_trusted_user() is True
user.AccountTypeID = at.PACKAGE_MAINTAINER_AND_DEV_ID
assert user.is_package_maintainer() is True
def test_user_is_developer(user: User):
@ -273,7 +273,7 @@ def test_user_is_developer(user: User):
# Do it again with the combined role.
with db.begin():
user.AccountTypeID = at.TRUSTED_USER_AND_DEV_ID
user.AccountTypeID = at.PACKAGE_MAINTAINER_AND_DEV_ID
assert user.is_developer() is True