mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
housekeep: TU rename - test suite
Rename tests: Function names, variables, etc. Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
4efb2a543a
commit
203c0c32a8
15 changed files with 332 additions and 332 deletions
|
@ -98,9 +98,9 @@ AUTH_KEYTYPE_USER=ssh-rsa
|
|||
AUTH_KEYTEXT_USER=AAAAB3NzaC1yc2EAAAADAQABAAABAQCeUafDK4jqUiRHNQfwHcYjBKLZ4Rc1sNUofHApBP6j91nIvDHZe2VUqeBmFUhBz7kXK4VbXD9nlHMun2HeshL8hXnMzymZ8Wk7+IKefj61pajJkIdttw9Tnayfg7uhg5RbFy9zpEjmGjnIVjSzOXKCwppNT+CNujpKM5FD8gso/Z+l3fD+IwrPwS1SzF1Z99nqI9n2FM/JWZqluvTqnW9WdAvBDfutXxp0R5ZiLI5TAKL2Ssp5rpL70pkLXhv+9sK545zKKlXUFmw6Pi2iVBdqdRsk9ocl49dLiNIh8CYDCO3CRQn+8EnpBhTor2TKQxGJI3mzoBwWJJxoKhD/XlYJ
|
||||
AUTH_FINGERPRINT_USER=SHA256:F/OFtYAy0JCytAGUi4RUZnOsThhQtFMK7fH1YvFBCpo
|
||||
|
||||
AUTH_KEYTYPE_TU=ssh-rsa
|
||||
AUTH_KEYTEXT_TU=AAAAB3NzaC1yc2EAAAADAQABAAABAQC4Q2Beg6jf2r1LZ4vwT5y10dK8+/c5RaNyTwv77wF2OSLXh32xW0ovhE2lW2gqoakdGsxgM2fTtqMTl29WOsAxlGF7x9XbWhFXFUT88Daq1fAeuihkiRjfBbInSW/WcrFZ+biLBch67addtfkkd4PmAafDeeCtszAXqza+ltBG1oxAGiTXgI3LOhA1/GtLLxsi5sPUO3ZlhvwDn4Sy0aXYx8l9hop/PU4Cjn82hyRa9r+SRxQ3KtjKxcVMnZ8IyXOrBwXTukgSBR/6nSdEmO0JPkYUFuNwh3UGFKuNkrPguL5T+4YDym6czYmZJzQ7NNl2pLKYmYgBwBe5rORlWfN5
|
||||
AUTH_FINGERPRINT_TU=SHA256:xQGC6j/U1Q3NDXLl04pm+Shr1mjYUXbGMUzlm9vby4k
|
||||
AUTH_KEYTYPE_PM=ssh-rsa
|
||||
AUTH_KEYTEXT_PM=AAAAB3NzaC1yc2EAAAADAQABAAABAQC4Q2Beg6jf2r1LZ4vwT5y10dK8+/c5RaNyTwv77wF2OSLXh32xW0ovhE2lW2gqoakdGsxgM2fTtqMTl29WOsAxlGF7x9XbWhFXFUT88Daq1fAeuihkiRjfBbInSW/WcrFZ+biLBch67addtfkkd4PmAafDeeCtszAXqza+ltBG1oxAGiTXgI3LOhA1/GtLLxsi5sPUO3ZlhvwDn4Sy0aXYx8l9hop/PU4Cjn82hyRa9r+SRxQ3KtjKxcVMnZ8IyXOrBwXTukgSBR/6nSdEmO0JPkYUFuNwh3UGFKuNkrPguL5T+4YDym6czYmZJzQ7NNl2pLKYmYgBwBe5rORlWfN5
|
||||
AUTH_FINGERPRINT_PM=SHA256:xQGC6j/U1Q3NDXLl04pm+Shr1mjYUXbGMUzlm9vby4k
|
||||
|
||||
AUTH_KEYTYPE_MISSING=sha-rsa
|
||||
AUTH_KEYTEXT_MISSING=AAAAB3NzaC1yc2EAAAADAQABAAABAQC9UTpssBunuTBCT3KFtv+yb+cN0VmI2C9O9U7wHlkEZWxNBK8is6tnDHXBxRuvRk0LHILkTidLLFX22ZF0+TFgSz7uuEvGZVNpa2Fn2+vKJJYMvZEvb/f8VHF5/Jddt21VOyu23royTN/duiT7WIZdCtEmq5C9Y43NPfsB8FbUc+FVSYT2Lq7g1/bzvFF+CZxwCrGjC3qC7p3pshICfFR8bbWgRN33ClxIQ7MvkcDtfNu38dLotJqdfEa7NdQgba5/S586f1A4OWKc/mQJFyTaGhRBxw/cBSjqonvO0442VYLHFxlrTHoUunKyOJ8+BJfKgjWmfENC9ESY3mL/IEn5
|
||||
|
@ -116,17 +116,17 @@ export SSH_CLIENT SSH_CONNECTION SSH_TTY
|
|||
python -m aurweb.initdb --no-alembic
|
||||
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (1, 'user', '!', 'user@localhost', 'en', 1);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (2, 'tu', '!', 'tu@localhost', 'en', 2);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (2, 'pm', '!', 'pm@localhost', 'en', 2);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (3, 'dev', '!', 'dev@localhost', 'en', 3);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (4, 'user2', '!', 'user2@localhost', 'en', 1);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (5, 'user3', '!', 'user3@localhost', 'en', 1);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (6, 'user4', '!', 'user4@localhost', 'en', 1);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (7, 'tu2', '!', 'tu2@localhost', 'en', 2);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (8, 'tu3', '!', 'tu3@localhost', 'en', 2);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (9, 'tu4', '!', 'tu4@localhost', 'en', 2);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (7, 'pm2', '!', 'pm2@localhost', 'en', 2);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (8, 'pm3', '!', 'pm3@localhost', 'en', 2);" | sqlite3 aur.db
|
||||
echo "INSERT INTO Users (ID, UserName, Passwd, Email, LangPreference, AccountTypeID) VALUES (9, 'pm4', '!', 'pm4@localhost', 'en', 2);" | sqlite3 aur.db
|
||||
|
||||
echo "INSERT INTO SSHPubKeys (UserID, Fingerprint, PubKey) VALUES (1, '$AUTH_FINGERPRINT_USER', '$AUTH_KEYTYPE_USER $AUTH_KEYTEXT_USER');" | sqlite3 aur.db
|
||||
echo "INSERT INTO SSHPubKeys (UserID, Fingerprint, PubKey) VALUES (2, '$AUTH_FINGERPRINT_TU', '$AUTH_KEYTYPE_TU $AUTH_KEYTEXT_TU');" | sqlite3 aur.db
|
||||
echo "INSERT INTO SSHPubKeys (UserID, Fingerprint, PubKey) VALUES (2, '$AUTH_FINGERPRINT_PM', '$AUTH_KEYTYPE_PM $AUTH_KEYTEXT_PM');" | sqlite3 aur.db
|
||||
|
||||
echo "INSERT INTO Bans (IPAddress, BanTS) VALUES ('1.3.3.7', 0);" | sqlite3 aur.db
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ test_expect_success 'Test basic authentication.' '
|
|||
'
|
||||
|
||||
test_expect_success 'Test Package Maintainer authentication.' '
|
||||
cover "$GIT_AUTH" "$AUTH_KEYTYPE_TU" "$AUTH_KEYTEXT_TU" >out &&
|
||||
grep -q AUR_USER=tu out &&
|
||||
cover "$GIT_AUTH" "$AUTH_KEYTYPE_PM" "$AUTH_KEYTEXT_PM" >out &&
|
||||
grep -q AUR_USER=pm out &&
|
||||
grep -q AUR_PRIVILEGED=1 out
|
||||
'
|
||||
|
||||
|
|
|
@ -126,12 +126,12 @@ test_expect_success "Try to push to someone else's repository." '
|
|||
|
||||
test_expect_success "Try to push to someone else's repository as Package Maintainer." '
|
||||
cat >expected <<-EOF &&
|
||||
tu
|
||||
pm
|
||||
foobar
|
||||
foobar
|
||||
EOF
|
||||
SSH_ORIGINAL_COMMAND="git-receive-pack /foobar.git/" \
|
||||
AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
@ -163,16 +163,16 @@ test_expect_success "Try to restore an existing package base." '
|
|||
'
|
||||
|
||||
test_expect_success "Disown all package bases." '
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
cat >expected <<-EOF &&
|
||||
EOF
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
|
||||
cover "$GIT_SERVE" 2>&1 >actual &&
|
||||
test_cmp expected actual &&
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
@ -196,12 +196,12 @@ test_expect_success "Adopt an already adopted package base." '
|
|||
'
|
||||
|
||||
test_expect_success "Adopt a package base as a Package Maintainer." '
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
cat >expected <<-EOF &&
|
||||
*foobar2
|
||||
EOF
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
@ -217,17 +217,17 @@ test_expect_success "Disown one's own package base as a regular user." '
|
|||
'
|
||||
|
||||
test_expect_success "Disown one's own package base as a Package Maintainer." '
|
||||
SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
cat >expected <<-EOF &&
|
||||
EOF
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success "Try to steal another user's package as a regular user." '
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
test_must_fail \
|
||||
env SSH_ORIGINAL_COMMAND="adopt foobar2" \
|
||||
|
@ -241,17 +241,17 @@ test_expect_success "Try to steal another user's package as a regular user." '
|
|||
cat >expected <<-EOF &&
|
||||
*foobar2
|
||||
EOF
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 >actual &&
|
||||
test_cmp expected actual &&
|
||||
SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1
|
||||
'
|
||||
|
||||
test_expect_success "Try to steal another user's package as a Package Maintainer." '
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
cat >expected <<-EOF &&
|
||||
EOF
|
||||
|
@ -261,15 +261,15 @@ test_expect_success "Try to steal another user's package as a Package Maintainer
|
|||
cat >expected <<-EOF &&
|
||||
foobar
|
||||
EOF
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 >actual &&
|
||||
test_cmp expected actual &&
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1
|
||||
'
|
||||
|
||||
test_expect_success "Try to disown another user's package as a regular user." '
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
test_must_fail \
|
||||
env SSH_ORIGINAL_COMMAND="disown foobar2" \
|
||||
|
@ -278,24 +278,24 @@ test_expect_success "Try to disown another user's package as a regular user." '
|
|||
cat >expected <<-EOF &&
|
||||
*foobar2
|
||||
EOF
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 >actual &&
|
||||
test_cmp expected actual &&
|
||||
SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1
|
||||
'
|
||||
|
||||
test_expect_success "Try to disown another user's package as a Package Maintainer." '
|
||||
SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
cat >expected <<-EOF &&
|
||||
EOF
|
||||
SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
|
||||
cover "$GIT_SERVE" 2>&1 >actual &&
|
||||
test_cmp expected actual &&
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1
|
||||
'
|
||||
|
||||
|
@ -362,7 +362,7 @@ test_expect_success "Disown a package base and check (co-)maintainer list." '
|
|||
'
|
||||
|
||||
test_expect_success "Force-disown a package base and check (co-)maintainer list." '
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
|
||||
SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=pm AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_SERVE" 2>&1 &&
|
||||
cat >expected <<-EOF &&
|
||||
EOF
|
||||
|
|
|
@ -132,7 +132,7 @@ test_expect_success 'Performing a non-fast-forward ref update as Package Maintai
|
|||
error: denying non-fast-forward (you should pull first)
|
||||
EOD
|
||||
test_must_fail \
|
||||
env AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
|
||||
env AUR_USER=pm AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
@ -152,7 +152,7 @@ test_expect_success 'Performing a non-fast-forward ref update as normal user wit
|
|||
test_expect_success 'Performing a non-fast-forward ref update as Package Maintainer with AUR_OVERWRITE=1.' '
|
||||
old=$(git -C aur.git rev-parse HEAD) &&
|
||||
new=$(git -C aur.git rev-parse HEAD^) &&
|
||||
AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 AUR_OVERWRITE=1 \
|
||||
AUR_USER=pm AUR_PKGBASE=foobar AUR_PRIVILEGED=1 AUR_OVERWRITE=1 \
|
||||
cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
|
||||
'
|
||||
|
||||
|
@ -545,7 +545,7 @@ test_expect_success 'Pushing a blacklisted package as Package Maintainer.' '
|
|||
cat >expected <<-EOD &&
|
||||
warning: package is blacklisted: forbidden
|
||||
EOD
|
||||
AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
|
||||
AUR_USER=pm AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
@ -574,7 +574,7 @@ test_expect_success 'Pushing a package already in the official repositories as P
|
|||
cat >expected <<-EOD &&
|
||||
warning: package already provided by [core]: official
|
||||
EOD
|
||||
AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
|
||||
AUR_USER=pm AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
|
||||
cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
|
|
@ -96,7 +96,7 @@ def user() -> User:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_user(user: User):
|
||||
def pm_user(user: User):
|
||||
with db.begin():
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_AND_DEV_ID
|
||||
yield user
|
||||
|
@ -657,13 +657,13 @@ def test_post_register_with_ssh_pubkey(client: TestClient):
|
|||
assert response.status_code == int(HTTPStatus.OK)
|
||||
|
||||
|
||||
def test_get_account_edit_tu_as_tu(client: TestClient, tu_user: User):
|
||||
def test_get_account_edit_pm_as_pm(client: TestClient, pm_user: User):
|
||||
"""Test edit get route of another TU as a TU."""
|
||||
with db.begin():
|
||||
user2 = create_user("test2")
|
||||
user2.AccountTypeID = at.PACKAGE_MAINTAINER_ID
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
|
||||
with client as request:
|
||||
|
@ -684,12 +684,12 @@ def test_get_account_edit_tu_as_tu(client: TestClient, tu_user: User):
|
|||
assert email.attrib["value"] == user2.Email
|
||||
|
||||
|
||||
def test_get_account_edit_as_tu(client: TestClient, tu_user: User):
|
||||
def test_get_account_edit_as_tu(client: TestClient, pm_user: User):
|
||||
"""Test edit get route of another user as a TU."""
|
||||
with db.begin():
|
||||
user2 = create_user("test2")
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
|
||||
with client as request:
|
||||
|
@ -723,11 +723,11 @@ def test_get_account_edit_type(client: TestClient, user: User):
|
|||
assert "id_type" not in response.text
|
||||
|
||||
|
||||
def test_get_account_edit_type_as_tu(client: TestClient, tu_user: User):
|
||||
def test_get_account_edit_type_as_tu(client: TestClient, pm_user: User):
|
||||
with db.begin():
|
||||
user2 = create_user("test_tu")
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
|
||||
with client as request:
|
||||
|
@ -764,9 +764,9 @@ def test_get_account_edit_unauthorized(client: TestClient, user: User):
|
|||
assert response.headers.get("location") == expected
|
||||
|
||||
|
||||
def test_get_account_edit_not_exists(client: TestClient, tu_user: User):
|
||||
def test_get_account_edit_not_exists(client: TestClient, pm_user: User):
|
||||
"""Test that users do not have an Account Type field."""
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = "/account/doesnotexist/edit"
|
||||
|
||||
with client as request:
|
||||
|
@ -795,11 +795,11 @@ def test_post_account_edit(client: TestClient, user: User):
|
|||
assert expected in response.content.decode()
|
||||
|
||||
|
||||
def test_post_account_edit_type_as_tu(client: TestClient, tu_user: User):
|
||||
def test_post_account_edit_type_as_tu(client: TestClient, pm_user: User):
|
||||
with db.begin():
|
||||
user2 = create_user("test_tu")
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
data = {
|
||||
"U": user2.Username,
|
||||
|
@ -813,12 +813,12 @@ def test_post_account_edit_type_as_tu(client: TestClient, tu_user: User):
|
|||
assert resp.status_code == int(HTTPStatus.OK)
|
||||
|
||||
|
||||
def test_post_account_edit_type_as_dev(client: TestClient, tu_user: User):
|
||||
def test_post_account_edit_type_as_dev(client: TestClient, pm_user: User):
|
||||
with db.begin():
|
||||
user2 = create_user("test2")
|
||||
tu_user.AccountTypeID = at.DEVELOPER_ID
|
||||
pm_user.AccountTypeID = at.DEVELOPER_ID
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
data = {
|
||||
"U": user2.Username,
|
||||
|
@ -833,12 +833,12 @@ def test_post_account_edit_type_as_dev(client: TestClient, tu_user: User):
|
|||
assert user2.AccountTypeID == at.DEVELOPER_ID
|
||||
|
||||
|
||||
def test_post_account_edit_invalid_type_as_tu(client: TestClient, tu_user: User):
|
||||
def test_post_account_edit_invalid_type_as_tu(client: TestClient, pm_user: User):
|
||||
with db.begin():
|
||||
user2 = create_user("test_tu")
|
||||
tu_user.AccountTypeID = at.PACKAGE_MAINTAINER_ID
|
||||
pm_user.AccountTypeID = at.PACKAGE_MAINTAINER_ID
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
data = {
|
||||
"U": user2.Username,
|
||||
|
@ -860,19 +860,19 @@ def test_post_account_edit_invalid_type_as_tu(client: TestClient, tu_user: User)
|
|||
assert errors[0].text.strip() == expected
|
||||
|
||||
|
||||
def test_post_account_edit_dev(client: TestClient, tu_user: User):
|
||||
def test_post_account_edit_dev(client: TestClient, pm_user: User):
|
||||
# Modify our user to be a "Package Maintainer & Developer"
|
||||
name = "Package Maintainer & Developer"
|
||||
tu_or_dev = query(AccountType, AccountType.AccountType == name).first()
|
||||
pm_or_dev = query(AccountType, AccountType.AccountType == name).first()
|
||||
with db.begin():
|
||||
user.AccountType = tu_or_dev
|
||||
user.AccountType = pm_or_dev
|
||||
|
||||
request = Request()
|
||||
sid = tu_user.login(request, "testPassword")
|
||||
sid = pm_user.login(request, "testPassword")
|
||||
|
||||
post_data = {"U": "test", "E": "test666@example.org", "passwd": "testPassword"}
|
||||
|
||||
endpoint = f"/account/{tu_user.Username}/edit"
|
||||
endpoint = f"/account/{pm_user.Username}/edit"
|
||||
with client as request:
|
||||
request.cookies = {"AURSID": sid}
|
||||
response = request.post(endpoint, data=post_data)
|
||||
|
@ -883,9 +883,9 @@ def test_post_account_edit_dev(client: TestClient, tu_user: User):
|
|||
assert expected in response.content.decode()
|
||||
|
||||
|
||||
def test_post_account_edit_not_exists(client: TestClient, tu_user: User):
|
||||
def test_post_account_edit_not_exists(client: TestClient, pm_user: User):
|
||||
request = Request()
|
||||
sid = tu_user.login(request, "testPassword")
|
||||
sid = pm_user.login(request, "testPassword")
|
||||
|
||||
post_data = {"U": "test", "E": "test666@example.org", "passwd": "testPassword"}
|
||||
|
||||
|
@ -1250,9 +1250,9 @@ def test_post_account_edit_other_user_as_user(client: TestClient, user: User):
|
|||
assert resp.headers.get("location") == f"/account/{user2.Username}"
|
||||
|
||||
|
||||
def test_post_account_edit_self_type_as_tu(client: TestClient, tu_user: User):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{tu_user.Username}/edit"
|
||||
def test_post_account_edit_self_type_as_tu(client: TestClient, pm_user: User):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{pm_user.Username}/edit"
|
||||
|
||||
# We cannot see the Account Type field on our own edit page.
|
||||
with client as request:
|
||||
|
@ -1263,8 +1263,8 @@ def test_post_account_edit_self_type_as_tu(client: TestClient, tu_user: User):
|
|||
|
||||
# We cannot modify our own account type.
|
||||
data = {
|
||||
"U": tu_user.Username,
|
||||
"E": tu_user.Email,
|
||||
"U": pm_user.Username,
|
||||
"E": pm_user.Email,
|
||||
"T": USER_ID,
|
||||
"passwd": "testPassword",
|
||||
}
|
||||
|
@ -1273,18 +1273,18 @@ def test_post_account_edit_self_type_as_tu(client: TestClient, tu_user: User):
|
|||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.OK)
|
||||
|
||||
assert tu_user.AccountTypeID == USER_ID
|
||||
assert pm_user.AccountTypeID == USER_ID
|
||||
|
||||
|
||||
def test_post_account_edit_other_user_type_as_tu(
|
||||
client: TestClient, tu_user: User, caplog: pytest.LogCaptureFixture
|
||||
client: TestClient, pm_user: User, caplog: pytest.LogCaptureFixture
|
||||
):
|
||||
caplog.set_level(DEBUG)
|
||||
|
||||
with db.begin():
|
||||
user2 = create_user("test2")
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
|
||||
# As a TU, we can see the Account Type field for other users.
|
||||
|
@ -1312,14 +1312,14 @@ def test_post_account_edit_other_user_type_as_tu(
|
|||
|
||||
# and also that this got logged out at DEBUG level.
|
||||
expected = (
|
||||
f"Package Maintainer '{tu_user.Username}' has "
|
||||
f"Package Maintainer '{pm_user.Username}' has "
|
||||
f"modified '{user2.Username}' account's type to"
|
||||
f" {PACKAGE_MAINTAINER}."
|
||||
)
|
||||
assert expected in caplog.text
|
||||
|
||||
|
||||
def test_post_account_edit_other_user_suspend_as_tu(client: TestClient, tu_user: User):
|
||||
def test_post_account_edit_other_user_suspend_as_tu(client: TestClient, pm_user: User):
|
||||
with db.begin():
|
||||
user = create_user("test3")
|
||||
# Create a session for user
|
||||
|
@ -1327,7 +1327,7 @@ def test_post_account_edit_other_user_suspend_as_tu(client: TestClient, tu_user:
|
|||
assert sid is not None
|
||||
|
||||
# `user` needs its own TestClient, to keep its AURSID cookies
|
||||
# apart from `tu_user`s during our testing.
|
||||
# apart from `pm_user`s during our testing.
|
||||
user_client = TestClient(app=app)
|
||||
user_client.headers.update(TEST_REFERER)
|
||||
user_client.follow_redirects = False
|
||||
|
@ -1340,7 +1340,7 @@ def test_post_account_edit_other_user_suspend_as_tu(client: TestClient, tu_user:
|
|||
resp = request.get(endpoint)
|
||||
assert resp.status_code == HTTPStatus.OK
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
assert cookies is not None # This is useless, we create the dict here ^
|
||||
# As a TU, we can see the Account for other users.
|
||||
with client as request:
|
||||
|
@ -1374,13 +1374,13 @@ def test_post_account_edit_other_user_suspend_as_tu(client: TestClient, tu_user:
|
|||
assert errors[0].text.strip() == "Account Suspended"
|
||||
|
||||
|
||||
def test_post_account_edit_other_user_type_as_tu_invalid_type(
|
||||
client: TestClient, tu_user: User, caplog: pytest.LogCaptureFixture
|
||||
def test_post_account_edit_other_user_type_as_pm_invalid_type(
|
||||
client: TestClient, pm_user: User, caplog: pytest.LogCaptureFixture
|
||||
):
|
||||
with db.begin():
|
||||
user2 = create_user("test2")
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
|
||||
# As a TU, we can modify other user's account types.
|
||||
|
@ -1426,7 +1426,7 @@ def test_get_account_unauthenticated(client: TestClient, user: User):
|
|||
assert "You must log in to view user information." in content
|
||||
|
||||
|
||||
def test_get_accounts(client: TestClient, user: User, tu_user: User):
|
||||
def test_get_accounts(client: TestClient, user: User, pm_user: User):
|
||||
"""Test that we can GET request /accounts and receive
|
||||
a form which can be used to POST /accounts."""
|
||||
sid = user.login(Request(), "testPassword")
|
||||
|
@ -1486,7 +1486,7 @@ def get_rows(html):
|
|||
return root.xpath('//table[contains(@class, "users")]/tbody/tr')
|
||||
|
||||
|
||||
def test_post_accounts(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts(client: TestClient, user: User, pm_user: User):
|
||||
# Set a PGPKey.
|
||||
with db.begin():
|
||||
user.PGPKey = "5F18B20346188419750745D7335F2CB41F253D30"
|
||||
|
@ -1539,7 +1539,7 @@ def test_post_accounts(client: TestClient, user: User, tu_user: User):
|
|||
)
|
||||
|
||||
|
||||
def test_post_accounts_username(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts_username(client: TestClient, user: User, pm_user: User):
|
||||
# Test the U parameter path.
|
||||
sid = user.login(Request(), "testPassword")
|
||||
cookies = {"AURSID": sid}
|
||||
|
@ -1559,7 +1559,7 @@ def test_post_accounts_username(client: TestClient, user: User, tu_user: User):
|
|||
assert username.text.strip() == user.Username
|
||||
|
||||
|
||||
def test_post_accounts_account_type(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts_account_type(client: TestClient, user: User, pm_user: User):
|
||||
# Check the different account type options.
|
||||
sid = user.login(Request(), "testPassword")
|
||||
cookies = {"AURSID": sid}
|
||||
|
@ -1656,7 +1656,7 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
|
|||
assert type.text.strip() == "Package Maintainer & Developer"
|
||||
|
||||
|
||||
def test_post_accounts_status(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts_status(client: TestClient, user: User, pm_user: User):
|
||||
# Test the functionality of Suspended.
|
||||
sid = user.login(Request(), "testPassword")
|
||||
cookies = {"AURSID": sid}
|
||||
|
@ -1689,7 +1689,7 @@ def test_post_accounts_status(client: TestClient, user: User, tu_user: User):
|
|||
assert status.text.strip() == "Suspended"
|
||||
|
||||
|
||||
def test_post_accounts_email(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts_email(client: TestClient, user: User, pm_user: User):
|
||||
sid = user.login(Request(), "testPassword")
|
||||
cookies = {"AURSID": sid}
|
||||
|
||||
|
@ -1703,7 +1703,7 @@ def test_post_accounts_email(client: TestClient, user: User, tu_user: User):
|
|||
assert len(rows) == 1
|
||||
|
||||
|
||||
def test_post_accounts_realname(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts_realname(client: TestClient, user: User, pm_user: User):
|
||||
# Test the R parameter path.
|
||||
sid = user.login(Request(), "testPassword")
|
||||
cookies = {"AURSID": sid}
|
||||
|
@ -1717,7 +1717,7 @@ def test_post_accounts_realname(client: TestClient, user: User, tu_user: User):
|
|||
assert len(rows) == 1
|
||||
|
||||
|
||||
def test_post_accounts_irc(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts_irc(client: TestClient, user: User, pm_user: User):
|
||||
# Test the I parameter path.
|
||||
sid = user.login(Request(), "testPassword")
|
||||
cookies = {"AURSID": sid}
|
||||
|
@ -1731,7 +1731,7 @@ def test_post_accounts_irc(client: TestClient, user: User, tu_user: User):
|
|||
assert len(rows) == 1
|
||||
|
||||
|
||||
def test_post_accounts_sortby(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts_sortby(client: TestClient, user: User, pm_user: User):
|
||||
# Create a second user so we can compare sorts.
|
||||
with db.begin():
|
||||
user_ = create_user("test2")
|
||||
|
@ -1811,7 +1811,7 @@ def test_post_accounts_sortby(client: TestClient, user: User, tu_user: User):
|
|||
assert compare_text_values(1, first_rows, reversed(rows))
|
||||
|
||||
|
||||
def test_post_accounts_pgp_key(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts_pgp_key(client: TestClient, user: User, pm_user: User):
|
||||
with db.begin():
|
||||
user.PGPKey = "5F18B20346188419750745D7335F2CB41F253D30"
|
||||
|
||||
|
@ -1828,7 +1828,7 @@ def test_post_accounts_pgp_key(client: TestClient, user: User, tu_user: User):
|
|||
assert len(rows) == 1
|
||||
|
||||
|
||||
def test_post_accounts_paged(client: TestClient, user: User, tu_user: User):
|
||||
def test_post_accounts_paged(client: TestClient, user: User, pm_user: User):
|
||||
# Create 150 users.
|
||||
users = [user]
|
||||
account_type = query(AccountType, AccountType.AccountType == "User").first()
|
||||
|
@ -2050,7 +2050,7 @@ def test_accounts_unauthorized(client: TestClient, user: User):
|
|||
assert resp.headers.get("location") == "/"
|
||||
|
||||
|
||||
def test_account_delete_self_unauthorized(client: TestClient, tu_user: User):
|
||||
def test_account_delete_self_unauthorized(client: TestClient, pm_user: User):
|
||||
with db.begin():
|
||||
user = create_user("some_user")
|
||||
user2 = create_user("user2")
|
||||
|
@ -2066,7 +2066,7 @@ def test_account_delete_self_unauthorized(client: TestClient, tu_user: User):
|
|||
assert resp.status_code == HTTPStatus.UNAUTHORIZED
|
||||
|
||||
# But a TU does have access
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with TestClient(app=app) as request:
|
||||
request.cookies = cookies
|
||||
resp = request.get(endpoint)
|
||||
|
@ -2167,11 +2167,11 @@ def test_account_delete_self_with_ssh_public_key(client: TestClient, user: User)
|
|||
assert sshpubkey_record is None
|
||||
|
||||
|
||||
def test_account_delete_as_tu(client: TestClient, tu_user: User):
|
||||
def test_account_delete_as_tu(client: TestClient, pm_user: User):
|
||||
with db.begin():
|
||||
user = create_user("user2")
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
username = user.Username
|
||||
endpoint = f"/account/{username}/delete"
|
||||
|
||||
|
|
|
@ -544,7 +544,7 @@ This is a test closure comment.
|
|||
assert email.body == expected
|
||||
|
||||
|
||||
def test_tu_vote_reminders(user: User):
|
||||
def test_pm_vote_reminders(user: User):
|
||||
set_tu([user])
|
||||
|
||||
vote_id = 1
|
||||
|
|
|
@ -89,26 +89,26 @@ def client():
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_user():
|
||||
tu_type = db.query(
|
||||
def pm_user():
|
||||
pm_type = db.query(
|
||||
AccountType, AccountType.AccountType == "Package Maintainer"
|
||||
).first()
|
||||
with db.begin():
|
||||
tu_user = db.create(
|
||||
pm_user = db.create(
|
||||
User,
|
||||
Username="test_tu",
|
||||
Email="test_tu@example.org",
|
||||
RealName="Test TU",
|
||||
Passwd="testPassword",
|
||||
AccountType=tu_type,
|
||||
AccountType=pm_type,
|
||||
)
|
||||
yield tu_user
|
||||
yield pm_user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_user2():
|
||||
def pm_user2():
|
||||
with db.begin():
|
||||
tu_user2 = db.create(
|
||||
pm_user2 = db.create(
|
||||
User,
|
||||
Username="test_tu2",
|
||||
Email="test_tu2@example.org",
|
||||
|
@ -116,7 +116,7 @@ def tu_user2():
|
|||
Passwd="testPassword",
|
||||
AccountTypeID=PACKAGE_MAINTAINER_ID,
|
||||
)
|
||||
yield tu_user2
|
||||
yield pm_user2
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -135,7 +135,7 @@ def user():
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def proposal(user, tu_user):
|
||||
def proposal(user, pm_user):
|
||||
ts = time.utcnow()
|
||||
agenda = "Test proposal."
|
||||
start = ts - 5
|
||||
|
@ -147,14 +147,14 @@ def proposal(user, tu_user):
|
|||
Agenda=agenda,
|
||||
Quorum=0.0,
|
||||
User=user.Username,
|
||||
Submitter=tu_user,
|
||||
Submitter=pm_user,
|
||||
Submitted=start,
|
||||
End=end,
|
||||
)
|
||||
yield (tu_user, user, voteinfo)
|
||||
yield (pm_user, user, voteinfo)
|
||||
|
||||
|
||||
def test_tu_index_guest(client):
|
||||
def test_pm_index_guest(client):
|
||||
headers = {"referer": config.get("options", "aur_location") + "/package-maintainer"}
|
||||
with client as request:
|
||||
response = request.get("/package-maintainer", headers=headers)
|
||||
|
@ -164,7 +164,7 @@ def test_tu_index_guest(client):
|
|||
assert response.headers.get("location") == f"/login?{params}"
|
||||
|
||||
|
||||
def test_tu_index_unauthorized(client: TestClient, user: User):
|
||||
def test_pm_index_unauthorized(client: TestClient, user: User):
|
||||
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
# Login as a normal user, not a TU.
|
||||
|
@ -174,11 +174,11 @@ def test_tu_index_unauthorized(client: TestClient, user: User):
|
|||
assert response.headers.get("location") == "/"
|
||||
|
||||
|
||||
def test_tu_empty_index(client, tu_user):
|
||||
def test_pm_empty_index(client, pm_user):
|
||||
"""Check an empty index when we don't create any records."""
|
||||
|
||||
# Make a default get request to /package-maintainer.
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get("/package-maintainer")
|
||||
|
@ -196,7 +196,7 @@ def test_tu_empty_index(client, tu_user):
|
|||
assert len(tables) == 0
|
||||
|
||||
|
||||
def test_tu_index(client, tu_user):
|
||||
def test_pm_index(client, pm_user):
|
||||
ts = time.utcnow()
|
||||
|
||||
# Create some test votes: (Agenda, Start, End).
|
||||
|
@ -212,11 +212,11 @@ def test_tu_index(client, tu_user):
|
|||
db.create(
|
||||
TUVoteInfo,
|
||||
Agenda=agenda,
|
||||
User=tu_user.Username,
|
||||
User=pm_user.Username,
|
||||
Submitted=start,
|
||||
End=end,
|
||||
Quorum=0.0,
|
||||
Submitter=tu_user,
|
||||
Submitter=pm_user,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -225,9 +225,9 @@ def test_tu_index(client, tu_user):
|
|||
vote_record = vote_records[1]
|
||||
vote_record.Yes += 1
|
||||
vote_record.ActiveTUs += 1
|
||||
db.create(TUVote, VoteInfo=vote_record, User=tu_user)
|
||||
db.create(TUVote, VoteInfo=vote_record, User=pm_user)
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
# Pass an invalid cby and pby; let them default to "desc".
|
||||
request.cookies = cookies
|
||||
|
@ -244,7 +244,7 @@ def test_tu_index(client, tu_user):
|
|||
r"Test agenda 1",
|
||||
DATETIME_REGEX,
|
||||
DATETIME_REGEX,
|
||||
tu_user.Username,
|
||||
pm_user.Username,
|
||||
r"^(Yes|No)$",
|
||||
)
|
||||
]
|
||||
|
@ -271,7 +271,7 @@ def test_tu_index(client, tu_user):
|
|||
r"Test agenda 2",
|
||||
DATETIME_REGEX,
|
||||
DATETIME_REGEX,
|
||||
tu_user.Username,
|
||||
pm_user.Username,
|
||||
r"^\d+$",
|
||||
r"^\d+$",
|
||||
r"^(Yes|No)$",
|
||||
|
@ -292,12 +292,12 @@ def test_tu_index(client, tu_user):
|
|||
username, vote_id = rows[0]
|
||||
username = username.xpath("./a")[0]
|
||||
vote_id = vote_id.xpath("./a")[0]
|
||||
assert username.text.strip() == tu_user.Username
|
||||
assert username.text.strip() == pm_user.Username
|
||||
assert int(vote_id.text.strip()) == vote_records[1].ID
|
||||
|
||||
|
||||
def test_tu_stats(client: TestClient, tu_user: User):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
def test_pm_stats(client: TestClient, pm_user: User):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get("/package-maintainer")
|
||||
|
@ -318,7 +318,7 @@ def test_tu_stats(client: TestClient, tu_user: User):
|
|||
assert int(count.text.strip()) == 1
|
||||
|
||||
with db.begin():
|
||||
tu_user.InactivityTS = time.utcnow()
|
||||
pm_user.InactivityTS = time.utcnow()
|
||||
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -340,7 +340,7 @@ def test_tu_stats(client: TestClient, tu_user: User):
|
|||
assert int(count.text.strip()) == 0
|
||||
|
||||
|
||||
def test_tu_index_table_paging(client, tu_user):
|
||||
def test_pm_index_table_paging(client, pm_user):
|
||||
ts = time.utcnow()
|
||||
|
||||
with db.begin():
|
||||
|
@ -349,11 +349,11 @@ def test_tu_index_table_paging(client, tu_user):
|
|||
db.create(
|
||||
TUVoteInfo,
|
||||
Agenda=f"Agenda #{i}",
|
||||
User=tu_user.Username,
|
||||
User=pm_user.Username,
|
||||
Submitted=(ts - 5),
|
||||
End=(ts + 1000),
|
||||
Quorum=0.0,
|
||||
Submitter=tu_user,
|
||||
Submitter=pm_user,
|
||||
)
|
||||
|
||||
for i in range(25):
|
||||
|
@ -361,14 +361,14 @@ def test_tu_index_table_paging(client, tu_user):
|
|||
db.create(
|
||||
TUVoteInfo,
|
||||
Agenda=f"Agenda #{25 + i}",
|
||||
User=tu_user.Username,
|
||||
User=pm_user.Username,
|
||||
Submitted=(ts - 1000),
|
||||
End=(ts - 5),
|
||||
Quorum=0.0,
|
||||
Submitter=tu_user,
|
||||
Submitter=pm_user,
|
||||
)
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get("/package-maintainer")
|
||||
|
@ -386,7 +386,7 @@ def test_tu_index_table_paging(client, tu_user):
|
|||
f"Agenda #{offset + i}",
|
||||
DATETIME_REGEX,
|
||||
DATETIME_REGEX,
|
||||
tu_user.Username,
|
||||
pm_user.Username,
|
||||
r"^(Yes|No)$",
|
||||
]
|
||||
|
||||
|
@ -455,7 +455,7 @@ def test_tu_index_table_paging(client, tu_user):
|
|||
assert "Next" in past_directions[0].text
|
||||
|
||||
|
||||
def test_tu_index_sorting(client, tu_user):
|
||||
def test_pm_index_sorting(client, pm_user):
|
||||
ts = time.utcnow()
|
||||
|
||||
with db.begin():
|
||||
|
@ -464,11 +464,11 @@ def test_tu_index_sorting(client, tu_user):
|
|||
db.create(
|
||||
TUVoteInfo,
|
||||
Agenda=f"Agenda #{i + 1}",
|
||||
User=tu_user.Username,
|
||||
User=pm_user.Username,
|
||||
Submitted=(ts + 5),
|
||||
End=(ts + 1000),
|
||||
Quorum=0.0,
|
||||
Submitter=tu_user,
|
||||
Submitter=pm_user,
|
||||
)
|
||||
|
||||
# Let's order each vote one day after the other.
|
||||
|
@ -477,7 +477,7 @@ def test_tu_index_sorting(client, tu_user):
|
|||
ts += 86405
|
||||
|
||||
# Make a default request to /package-maintainer.
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get("/package-maintainer")
|
||||
|
@ -499,7 +499,7 @@ def test_tu_index_sorting(client, tu_user):
|
|||
expected[i],
|
||||
DATETIME_REGEX,
|
||||
DATETIME_REGEX,
|
||||
tu_user.Username,
|
||||
pm_user.Username,
|
||||
r"^(Yes|No)$",
|
||||
],
|
||||
)
|
||||
|
@ -526,14 +526,14 @@ def test_tu_index_sorting(client, tu_user):
|
|||
rev_expected[i],
|
||||
DATETIME_REGEX,
|
||||
DATETIME_REGEX,
|
||||
tu_user.Username,
|
||||
pm_user.Username,
|
||||
r"^(Yes|No)$",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def test_tu_index_last_votes(
|
||||
client: TestClient, tu_user: User, tu_user2: User, user: User
|
||||
def test_pm_index_last_votes(
|
||||
client: TestClient, pm_user: User, pm_user2: User, user: User
|
||||
):
|
||||
ts = time.utcnow()
|
||||
|
||||
|
@ -549,15 +549,15 @@ def test_tu_index_last_votes(
|
|||
No=1,
|
||||
ActiveTUs=1,
|
||||
Quorum=0.0,
|
||||
Submitter=tu_user,
|
||||
Submitter=pm_user,
|
||||
)
|
||||
|
||||
# Create a vote on it from tu_user.
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=tu_user)
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=tu_user2)
|
||||
# Create a vote on it from pm_user.
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=pm_user)
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=pm_user2)
|
||||
|
||||
# Now, check that tu_user got populated in the .last-votes table.
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
# Now, check that pm_user got populated in the .last-votes table.
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get("/package-maintainer")
|
||||
|
@ -570,17 +570,17 @@ def test_tu_index_last_votes(
|
|||
|
||||
last_vote = rows[0]
|
||||
user, vote_id = last_vote.xpath("./td/a")
|
||||
assert user.text.strip() == tu_user.Username
|
||||
assert user.text.strip() == pm_user.Username
|
||||
assert int(vote_id.text.strip()) == voteinfo.ID
|
||||
|
||||
last_vote = rows[1]
|
||||
user, vote_id = last_vote.xpath("./td/a")
|
||||
assert int(vote_id.text.strip()) == voteinfo.ID
|
||||
assert user.text.strip() == tu_user2.Username
|
||||
assert user.text.strip() == pm_user2.Username
|
||||
|
||||
|
||||
def test_tu_proposal_not_found(client, tu_user):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
def test_pm_proposal_not_found(client, pm_user):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get(
|
||||
|
@ -589,7 +589,7 @@ def test_tu_proposal_not_found(client, tu_user):
|
|||
assert response.status_code == int(HTTPStatus.NOT_FOUND)
|
||||
|
||||
|
||||
def test_tu_proposal_unauthorized(
|
||||
def test_pm_proposal_unauthorized(
|
||||
client: TestClient, user: User, proposal: Tuple[User, User, TUVoteInfo]
|
||||
):
|
||||
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||
|
@ -607,16 +607,16 @@ def test_tu_proposal_unauthorized(
|
|||
assert response.headers.get("location") == "/package-maintainer"
|
||||
|
||||
|
||||
def test_tu_running_proposal(
|
||||
def test_pm_running_proposal(
|
||||
client: TestClient, proposal: Tuple[User, User, TUVoteInfo]
|
||||
):
|
||||
tu_user, user, voteinfo = proposal
|
||||
pm_user, user, voteinfo = proposal
|
||||
with db.begin():
|
||||
voteinfo.ActiveTUs = 1
|
||||
|
||||
# Initiate an authenticated GET request to /package-maintainer/{proposal_id}.
|
||||
proposal_id = voteinfo.ID
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get(f"/package-maintainer/{proposal_id}")
|
||||
|
@ -647,8 +647,8 @@ def test_tu_running_proposal(
|
|||
is not None
|
||||
)
|
||||
submitter = details.xpath('./div[contains(@class, "submitted")]/a')[0]
|
||||
assert submitter.text.strip() == tu_user.Username
|
||||
assert submitter.attrib["href"] == f"/account/{tu_user.Username}"
|
||||
assert submitter.text.strip() == pm_user.Username
|
||||
assert submitter.attrib["href"] == f"/account/{pm_user.Username}"
|
||||
|
||||
end = details.xpath('./div[contains(@class, "end")]')[0]
|
||||
end_label = end.xpath("./text()")[0]
|
||||
|
@ -683,7 +683,7 @@ def test_tu_running_proposal(
|
|||
|
||||
# Create a vote.
|
||||
with db.begin():
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=tu_user)
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=pm_user)
|
||||
voteinfo.ActiveTUs += 1
|
||||
voteinfo.Yes += 1
|
||||
|
||||
|
@ -707,8 +707,8 @@ def test_tu_running_proposal(
|
|||
assert status == "You've already voted for this proposal."
|
||||
|
||||
|
||||
def test_tu_ended_proposal(client, proposal):
|
||||
tu_user, user, voteinfo = proposal
|
||||
def test_pm_ended_proposal(client, proposal):
|
||||
pm_user, user, voteinfo = proposal
|
||||
|
||||
ts = time.utcnow()
|
||||
with db.begin():
|
||||
|
@ -716,7 +716,7 @@ def test_tu_ended_proposal(client, proposal):
|
|||
|
||||
# Initiate an authenticated GET request to /package-maintainer/{proposal_id}.
|
||||
proposal_id = voteinfo.ID
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get(f"/package-maintainer/{proposal_id}")
|
||||
|
@ -746,9 +746,9 @@ def test_tu_ended_proposal(client, proposal):
|
|||
assert status == "Voting is closed for this proposal."
|
||||
|
||||
|
||||
def test_tu_proposal_vote_not_found(client, tu_user):
|
||||
def test_pm_proposal_vote_not_found(client, pm_user):
|
||||
"""Test POST request to a missing vote."""
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
data = {"decision": "Yes"}
|
||||
request.cookies = cookies
|
||||
|
@ -756,13 +756,13 @@ def test_tu_proposal_vote_not_found(client, tu_user):
|
|||
assert response.status_code == int(HTTPStatus.NOT_FOUND)
|
||||
|
||||
|
||||
def test_tu_proposal_vote(client, proposal):
|
||||
tu_user, user, voteinfo = proposal
|
||||
def test_pm_proposal_vote(client, proposal):
|
||||
pm_user, user, voteinfo = proposal
|
||||
|
||||
# Store the current related values.
|
||||
yes = voteinfo.Yes
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
data = {"decision": "Yes"}
|
||||
request.cookies = cookies
|
||||
|
@ -773,7 +773,7 @@ def test_tu_proposal_vote(client, proposal):
|
|||
assert voteinfo.Yes == yes + 1
|
||||
|
||||
# Check that the new TUVote exists.
|
||||
vote = db.query(TUVote, TUVote.VoteInfo == voteinfo, TUVote.User == tu_user).first()
|
||||
vote = db.query(TUVote, TUVote.VoteInfo == voteinfo, TUVote.User == pm_user).first()
|
||||
assert vote is not None
|
||||
|
||||
root = parse_root(response.text)
|
||||
|
@ -783,15 +783,15 @@ def test_tu_proposal_vote(client, proposal):
|
|||
assert status == "You've already voted for this proposal."
|
||||
|
||||
|
||||
def test_tu_proposal_vote_unauthorized(
|
||||
def test_pm_proposal_vote_unauthorized(
|
||||
client: TestClient, proposal: Tuple[User, User, TUVoteInfo]
|
||||
):
|
||||
tu_user, user, voteinfo = proposal
|
||||
pm_user, user, voteinfo = proposal
|
||||
|
||||
with db.begin():
|
||||
tu_user.AccountTypeID = DEVELOPER_ID
|
||||
pm_user.AccountTypeID = DEVELOPER_ID
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
data = {"decision": "Yes"}
|
||||
request.cookies = cookies
|
||||
|
@ -813,14 +813,14 @@ def test_tu_proposal_vote_unauthorized(
|
|||
assert status == "Only Package Maintainers are allowed to vote."
|
||||
|
||||
|
||||
def test_tu_proposal_vote_cant_self_vote(client, proposal):
|
||||
tu_user, user, voteinfo = proposal
|
||||
def test_pm_proposal_vote_cant_self_vote(client, proposal):
|
||||
pm_user, user, voteinfo = proposal
|
||||
|
||||
# Update voteinfo.User.
|
||||
with db.begin():
|
||||
voteinfo.User = tu_user.Username
|
||||
voteinfo.User = pm_user.Username
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
data = {"decision": "Yes"}
|
||||
request.cookies = cookies
|
||||
|
@ -842,15 +842,15 @@ def test_tu_proposal_vote_cant_self_vote(client, proposal):
|
|||
assert status == "You cannot vote in an proposal about you."
|
||||
|
||||
|
||||
def test_tu_proposal_vote_already_voted(client, proposal):
|
||||
tu_user, user, voteinfo = proposal
|
||||
def test_pm_proposal_vote_already_voted(client, proposal):
|
||||
pm_user, user, voteinfo = proposal
|
||||
|
||||
with db.begin():
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=tu_user)
|
||||
db.create(TUVote, VoteInfo=voteinfo, User=pm_user)
|
||||
voteinfo.Yes += 1
|
||||
voteinfo.ActiveTUs += 1
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
data = {"decision": "Yes"}
|
||||
request.cookies = cookies
|
||||
|
@ -872,10 +872,10 @@ def test_tu_proposal_vote_already_voted(client, proposal):
|
|||
assert status == "You've already voted for this proposal."
|
||||
|
||||
|
||||
def test_tu_proposal_vote_invalid_decision(client, proposal):
|
||||
tu_user, user, voteinfo = proposal
|
||||
def test_pm_proposal_vote_invalid_decision(client, proposal):
|
||||
pm_user, user, voteinfo = proposal
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
data = {"decision": "EVIL"}
|
||||
request.cookies = cookies
|
||||
|
@ -884,15 +884,15 @@ def test_tu_proposal_vote_invalid_decision(client, proposal):
|
|||
assert response.text == "Invalid 'decision' value."
|
||||
|
||||
|
||||
def test_tu_addvote(client: TestClient, tu_user: User):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
def test_pm_addvote(client: TestClient, pm_user: User):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get("/addvote")
|
||||
assert response.status_code == int(HTTPStatus.OK)
|
||||
|
||||
|
||||
def test_tu_addvote_unauthorized(
|
||||
def test_pm_addvote_unauthorized(
|
||||
client: TestClient, user: User, proposal: Tuple[User, User, TUVoteInfo]
|
||||
):
|
||||
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||
|
@ -909,8 +909,8 @@ def test_tu_addvote_unauthorized(
|
|||
assert response.headers.get("location") == "/package-maintainer"
|
||||
|
||||
|
||||
def test_tu_addvote_invalid_type(client: TestClient, tu_user: User):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
def test_pm_addvote_invalid_type(client: TestClient, pm_user: User):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
response = request.get("/addvote", params={"type": "faketype"})
|
||||
|
@ -921,8 +921,8 @@ def test_tu_addvote_invalid_type(client: TestClient, tu_user: User):
|
|||
assert error.strip() == "Invalid type."
|
||||
|
||||
|
||||
def test_tu_addvote_post(client: TestClient, tu_user: User, user: User):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
def test_pm_addvote_post(client: TestClient, pm_user: User, user: User):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
|
||||
data = {"user": user.Username, "type": "add_pm", "agenda": "Blah"}
|
||||
|
||||
|
@ -935,10 +935,10 @@ def test_tu_addvote_post(client: TestClient, tu_user: User, user: User):
|
|||
assert voteinfo is not None
|
||||
|
||||
|
||||
def test_tu_addvote_post_cant_duplicate_username(
|
||||
client: TestClient, tu_user: User, user: User
|
||||
def test_pm_addvote_post_cant_duplicate_username(
|
||||
client: TestClient, pm_user: User, user: User
|
||||
):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
|
||||
data = {"user": user.Username, "type": "add_pm", "agenda": "Blah"}
|
||||
|
||||
|
@ -956,8 +956,8 @@ def test_tu_addvote_post_cant_duplicate_username(
|
|||
assert response.status_code == int(HTTPStatus.BAD_REQUEST)
|
||||
|
||||
|
||||
def test_tu_addvote_post_invalid_username(client: TestClient, tu_user: User):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
def test_pm_addvote_post_invalid_username(client: TestClient, pm_user: User):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
data = {"user": "fakeusername"}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -965,8 +965,8 @@ def test_tu_addvote_post_invalid_username(client: TestClient, tu_user: User):
|
|||
assert response.status_code == int(HTTPStatus.NOT_FOUND)
|
||||
|
||||
|
||||
def test_tu_addvote_post_invalid_type(client: TestClient, tu_user: User, user: User):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
def test_pm_addvote_post_invalid_type(client: TestClient, pm_user: User, user: User):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
data = {"user": user.Username}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -974,8 +974,8 @@ def test_tu_addvote_post_invalid_type(client: TestClient, tu_user: User, user: U
|
|||
assert response.status_code == int(HTTPStatus.BAD_REQUEST)
|
||||
|
||||
|
||||
def test_tu_addvote_post_invalid_agenda(client: TestClient, tu_user: User, user: User):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
def test_pm_addvote_post_invalid_agenda(client: TestClient, pm_user: User, user: User):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
data = {"user": user.Username, "type": "add_pm"}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -983,9 +983,9 @@ def test_tu_addvote_post_invalid_agenda(client: TestClient, tu_user: User, user:
|
|||
assert response.status_code == int(HTTPStatus.BAD_REQUEST)
|
||||
|
||||
|
||||
def test_tu_addvote_post_bylaws(client: TestClient, tu_user: User):
|
||||
def test_pm_addvote_post_bylaws(client: TestClient, pm_user: User):
|
||||
# Bylaws votes do not need a user specified.
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
data = {"type": "bylaws", "agenda": "Blah blah!"}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
|
@ -113,20 +113,20 @@ def maintainer() -> User:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_user():
|
||||
tu_type = db.query(
|
||||
def pm_user():
|
||||
pm_type = db.query(
|
||||
AccountType, AccountType.AccountType == "Package Maintainer"
|
||||
).first()
|
||||
with db.begin():
|
||||
tu_user = db.create(
|
||||
pm_user = db.create(
|
||||
User,
|
||||
Username="test_tu",
|
||||
Email="test_tu@example.org",
|
||||
RealName="Test TU",
|
||||
Passwd="testPassword",
|
||||
AccountType=tu_type,
|
||||
AccountType=pm_type,
|
||||
)
|
||||
yield tu_user
|
||||
yield pm_user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -614,9 +614,9 @@ def test_package_authenticated_maintainer(
|
|||
|
||||
|
||||
def test_package_authenticated_tu(
|
||||
client: TestClient, tu_user: User, package: Package, pkgreq: PackageRequest
|
||||
client: TestClient, pm_user: User, package: Package, pkgreq: PackageRequest
|
||||
):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.get(package_endpoint(package))
|
||||
|
@ -1572,10 +1572,10 @@ def test_packages_post_disown_as_maintainer(
|
|||
|
||||
|
||||
def test_packages_post_disown(
|
||||
client: TestClient, tu_user: User, maintainer: User, package: Package
|
||||
client: TestClient, pm_user: User, maintainer: User, package: Package
|
||||
):
|
||||
"""Disown packages as a Package Maintainer, which cannot bypass idle time."""
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.post(
|
||||
|
@ -1592,7 +1592,7 @@ def test_packages_post_delete(
|
|||
caplog: pytest.fixture,
|
||||
client: TestClient,
|
||||
user: User,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
package: Package,
|
||||
):
|
||||
# First, let's try to use the delete action with no packages IDs.
|
||||
|
@ -1635,9 +1635,9 @@ def test_packages_post_delete(
|
|||
# Now, let's switch over to making the requests as a TU.
|
||||
# However, this next request will be rejected due to supplying
|
||||
# an invalid package ID.
|
||||
tu_cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
pm_cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = tu_cookies
|
||||
request.cookies = pm_cookies
|
||||
resp = request.post(
|
||||
"/packages",
|
||||
data={"action": "delete", "IDs": [0], "confirm": True},
|
||||
|
@ -1647,10 +1647,10 @@ def test_packages_post_delete(
|
|||
expected = "One of the packages you selected does not exist."
|
||||
assert errors[0].text.strip() == expected
|
||||
|
||||
# Whoo. Now, let's finally make a valid request as `tu_user`
|
||||
# Whoo. Now, let's finally make a valid request as `pm_user`
|
||||
# to delete `package`.
|
||||
with client as request:
|
||||
request.cookies = tu_cookies
|
||||
request.cookies = pm_cookies
|
||||
resp = request.post(
|
||||
"/packages",
|
||||
data={"action": "delete", "IDs": [package.ID], "confirm": True},
|
||||
|
@ -1663,7 +1663,7 @@ def test_packages_post_delete(
|
|||
# Expect that the package deletion was logged.
|
||||
pkgbases = [package.PackageBase.Name]
|
||||
expected = (
|
||||
f"Privileged user '{tu_user.Username}' deleted the "
|
||||
f"Privileged user '{pm_user.Username}' deleted the "
|
||||
f"following package bases: {str(pkgbases)}."
|
||||
)
|
||||
assert expected in caplog.text
|
||||
|
|
|
@ -116,20 +116,20 @@ def comaintainer() -> User:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_user():
|
||||
tu_type = db.query(
|
||||
def pm_user():
|
||||
pm_type = db.query(
|
||||
AccountType, AccountType.AccountType == "Package Maintainer"
|
||||
).first()
|
||||
with db.begin():
|
||||
tu_user = db.create(
|
||||
pm_user = db.create(
|
||||
User,
|
||||
Username="test_tu",
|
||||
Email="test_tu@example.org",
|
||||
RealName="Test TU",
|
||||
Passwd="testPassword",
|
||||
AccountType=tu_type,
|
||||
AccountType=pm_type,
|
||||
)
|
||||
yield tu_user
|
||||
yield pm_user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -304,25 +304,25 @@ def test_pkgbase_maintainer(
|
|||
assert comaint == f"({user.Username})"
|
||||
|
||||
|
||||
def test_pkgbase_voters(client: TestClient, tu_user: User, package: Package):
|
||||
def test_pkgbase_voters(client: TestClient, pm_user: User, package: Package):
|
||||
pkgbase = package.PackageBase
|
||||
endpoint = f"/pkgbase/{pkgbase.Name}/voters"
|
||||
|
||||
now = time.utcnow()
|
||||
with db.begin():
|
||||
db.create(PackageVote, User=tu_user, PackageBase=pkgbase, VoteTS=now)
|
||||
db.create(PackageVote, User=pm_user, PackageBase=pkgbase, VoteTS=now)
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.get(endpoint)
|
||||
assert resp.status_code == int(HTTPStatus.OK)
|
||||
|
||||
# We should've gotten one link to the voter, tu_user.
|
||||
# We should've gotten one link to the voter, pm_user.
|
||||
root = parse_root(resp.text)
|
||||
rows = root.xpath('//div[@class="box"]//ul/li/a')
|
||||
assert len(rows) == 1
|
||||
assert rows[0].text.strip() == tu_user.Username
|
||||
assert rows[0].text.strip() == pm_user.Username
|
||||
|
||||
|
||||
def test_pkgbase_voters_unauthorized(client: TestClient, user: User, package: Package):
|
||||
|
@ -1304,7 +1304,7 @@ def test_pkgbase_disown(
|
|||
|
||||
|
||||
def test_pkgbase_adopt(
|
||||
client: TestClient, user: User, tu_user: User, maintainer: User, package: Package
|
||||
client: TestClient, user: User, pm_user: User, maintainer: User, package: Package
|
||||
):
|
||||
# Unset the maintainer as if package is orphaned.
|
||||
with db.begin():
|
||||
|
@ -1329,13 +1329,13 @@ def test_pkgbase_adopt(
|
|||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert package.PackageBase.Maintainer == maintainer
|
||||
|
||||
# Steal the package as a TU.
|
||||
tu_cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
# Steal the package as a PM.
|
||||
pm_cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = tu_cookies
|
||||
request.cookies = pm_cookies
|
||||
resp = request.post(endpoint)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert package.PackageBase.Maintainer == tu_user
|
||||
assert package.PackageBase.Maintainer == pm_user
|
||||
|
||||
|
||||
def test_pkgbase_delete_unauthorized(client: TestClient, user: User, package: Package):
|
||||
|
@ -1358,11 +1358,11 @@ def test_pkgbase_delete_unauthorized(client: TestClient, user: User, package: Pa
|
|||
assert resp.headers.get("location") == f"/pkgbase/{pkgbase.Name}"
|
||||
|
||||
|
||||
def test_pkgbase_delete(client: TestClient, tu_user: User, package: Package):
|
||||
def test_pkgbase_delete(client: TestClient, pm_user: User, package: Package):
|
||||
pkgbase = package.PackageBase
|
||||
|
||||
# Test that the GET request works.
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/pkgbase/{pkgbase.Name}/delete"
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -1396,13 +1396,13 @@ def test_pkgbase_delete(client: TestClient, tu_user: User, package: Package):
|
|||
|
||||
|
||||
def test_pkgbase_delete_with_request(
|
||||
client: TestClient, tu_user: User, pkgbase: PackageBase, pkgreq: PackageRequest
|
||||
client: TestClient, pm_user: User, pkgbase: PackageBase, pkgreq: PackageRequest
|
||||
):
|
||||
# TODO: Test that a previously existing request gets Accepted when
|
||||
# a TU deleted the package.
|
||||
|
||||
# Delete the package as `tu_user` via POST request.
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
# Delete the package as `pm_user` via POST request.
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/pkgbase/{pkgbase.Name}/delete"
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -1479,8 +1479,8 @@ def test_pkgbase_merge_unauthorized(client: TestClient, user: User, package: Pac
|
|||
assert resp.status_code == int(HTTPStatus.UNAUTHORIZED)
|
||||
|
||||
|
||||
def test_pkgbase_merge(client: TestClient, tu_user: User, package: Package):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
def test_pkgbase_merge(client: TestClient, pm_user: User, package: Package):
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/pkgbase/{package.PackageBase.Name}/merge"
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -1501,9 +1501,9 @@ def test_pkgbase_merge_post_unauthorized(
|
|||
|
||||
|
||||
def test_pkgbase_merge_post_unconfirmed(
|
||||
client: TestClient, tu_user: User, package: Package
|
||||
client: TestClient, pm_user: User, package: Package
|
||||
):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/pkgbase/{package.PackageBase.Name}/merge"
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -1518,9 +1518,9 @@ def test_pkgbase_merge_post_unconfirmed(
|
|||
|
||||
|
||||
def test_pkgbase_merge_post_invalid_into(
|
||||
client: TestClient, tu_user: User, package: Package
|
||||
client: TestClient, pm_user: User, package: Package
|
||||
):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/pkgbase/{package.PackageBase.Name}/merge"
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -1532,9 +1532,9 @@ def test_pkgbase_merge_post_invalid_into(
|
|||
|
||||
|
||||
def test_pkgbase_merge_post_self_invalid(
|
||||
client: TestClient, tu_user: User, package: Package
|
||||
client: TestClient, pm_user: User, package: Package
|
||||
):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/pkgbase/{package.PackageBase.Name}/merge"
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
@ -1550,7 +1550,7 @@ def test_pkgbase_merge_post_self_invalid(
|
|||
|
||||
def test_pkgbase_merge_post(
|
||||
client: TestClient,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
package: Package,
|
||||
pkgbase: PackageBase,
|
||||
target: PackageBase,
|
||||
|
@ -1567,7 +1567,7 @@ def test_pkgbase_merge_post(
|
|||
pkgreq.MergeBaseName = target.Name
|
||||
|
||||
# Vote for the package.
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/pkgbase/{package.PackageBase.Name}/vote"
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
|
|
|
@ -28,10 +28,10 @@ def user() -> User:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_voteinfo(user: User) -> TUVoteInfo:
|
||||
def pm_voteinfo(user: User) -> TUVoteInfo:
|
||||
ts = time.utcnow()
|
||||
with db.begin():
|
||||
tu_voteinfo = db.create(
|
||||
pm_voteinfo = db.create(
|
||||
TUVoteInfo,
|
||||
Agenda="Blah blah.",
|
||||
User=user.Username,
|
||||
|
@ -40,24 +40,24 @@ def tu_voteinfo(user: User) -> TUVoteInfo:
|
|||
Quorum=0.5,
|
||||
Submitter=user,
|
||||
)
|
||||
yield tu_voteinfo
|
||||
yield pm_voteinfo
|
||||
|
||||
|
||||
def test_tu_vote_creation(user: User, tu_voteinfo: TUVoteInfo):
|
||||
def test_pm_vote_creation(user: User, pm_voteinfo: TUVoteInfo):
|
||||
with db.begin():
|
||||
tu_vote = db.create(TUVote, User=user, VoteInfo=tu_voteinfo)
|
||||
pm_vote = db.create(TUVote, User=user, VoteInfo=pm_voteinfo)
|
||||
|
||||
assert tu_vote.VoteInfo == tu_voteinfo
|
||||
assert tu_vote.User == user
|
||||
assert tu_vote in user.tu_votes
|
||||
assert tu_vote in tu_voteinfo.tu_votes
|
||||
assert pm_vote.VoteInfo == pm_voteinfo
|
||||
assert pm_vote.User == user
|
||||
assert pm_vote in user.tu_votes
|
||||
assert pm_vote in pm_voteinfo.tu_votes
|
||||
|
||||
|
||||
def test_tu_vote_null_user_raises_exception(tu_voteinfo: TUVoteInfo):
|
||||
def test_pm_vote_null_user_raises_exception(pm_voteinfo: TUVoteInfo):
|
||||
with pytest.raises(IntegrityError):
|
||||
TUVote(VoteInfo=tu_voteinfo)
|
||||
TUVote(VoteInfo=pm_voteinfo)
|
||||
|
||||
|
||||
def test_tu_vote_null_voteinfo_raises_exception(user: User):
|
||||
def test_pm_vote_null_voteinfo_raises_exception(user: User):
|
||||
with pytest.raises(IntegrityError):
|
||||
TUVote(User=user)
|
|
@ -27,10 +27,10 @@ def user() -> User:
|
|||
yield user
|
||||
|
||||
|
||||
def test_tu_voteinfo_creation(user: User):
|
||||
def test_pm_voteinfo_creation(user: User):
|
||||
ts = time.utcnow()
|
||||
with db.begin():
|
||||
tu_voteinfo = create(
|
||||
pm_voteinfo = create(
|
||||
TUVoteInfo,
|
||||
Agenda="Blah blah.",
|
||||
User=user.Username,
|
||||
|
@ -39,25 +39,25 @@ def test_tu_voteinfo_creation(user: User):
|
|||
Quorum=0.5,
|
||||
Submitter=user,
|
||||
)
|
||||
assert bool(tu_voteinfo.ID)
|
||||
assert tu_voteinfo.Agenda == "Blah blah."
|
||||
assert tu_voteinfo.User == user.Username
|
||||
assert tu_voteinfo.Submitted == ts
|
||||
assert tu_voteinfo.End == ts + 5
|
||||
assert tu_voteinfo.Quorum == 0.5
|
||||
assert tu_voteinfo.Submitter == user
|
||||
assert tu_voteinfo.Yes == 0
|
||||
assert tu_voteinfo.No == 0
|
||||
assert tu_voteinfo.Abstain == 0
|
||||
assert tu_voteinfo.ActiveTUs == 0
|
||||
assert bool(pm_voteinfo.ID)
|
||||
assert pm_voteinfo.Agenda == "Blah blah."
|
||||
assert pm_voteinfo.User == user.Username
|
||||
assert pm_voteinfo.Submitted == ts
|
||||
assert pm_voteinfo.End == ts + 5
|
||||
assert pm_voteinfo.Quorum == 0.5
|
||||
assert pm_voteinfo.Submitter == user
|
||||
assert pm_voteinfo.Yes == 0
|
||||
assert pm_voteinfo.No == 0
|
||||
assert pm_voteinfo.Abstain == 0
|
||||
assert pm_voteinfo.ActiveTUs == 0
|
||||
|
||||
assert tu_voteinfo in user.tu_voteinfo_set
|
||||
assert pm_voteinfo in user.tu_voteinfo_set
|
||||
|
||||
|
||||
def test_tu_voteinfo_is_running(user: User):
|
||||
def test_pm_voteinfo_is_running(user: User):
|
||||
ts = time.utcnow()
|
||||
with db.begin():
|
||||
tu_voteinfo = create(
|
||||
pm_voteinfo = create(
|
||||
TUVoteInfo,
|
||||
Agenda="Blah blah.",
|
||||
User=user.Username,
|
||||
|
@ -66,17 +66,17 @@ def test_tu_voteinfo_is_running(user: User):
|
|||
Quorum=0.5,
|
||||
Submitter=user,
|
||||
)
|
||||
assert tu_voteinfo.is_running() is True
|
||||
assert pm_voteinfo.is_running() is True
|
||||
|
||||
with db.begin():
|
||||
tu_voteinfo.End = ts - 5
|
||||
assert tu_voteinfo.is_running() is False
|
||||
pm_voteinfo.End = ts - 5
|
||||
assert pm_voteinfo.is_running() is False
|
||||
|
||||
|
||||
def test_tu_voteinfo_total_votes(user: User):
|
||||
def test_pm_voteinfo_total_votes(user: User):
|
||||
ts = time.utcnow()
|
||||
with db.begin():
|
||||
tu_voteinfo = create(
|
||||
pm_voteinfo = create(
|
||||
TUVoteInfo,
|
||||
Agenda="Blah blah.",
|
||||
User=user.Username,
|
||||
|
@ -86,15 +86,15 @@ def test_tu_voteinfo_total_votes(user: User):
|
|||
Submitter=user,
|
||||
)
|
||||
|
||||
tu_voteinfo.Yes = 1
|
||||
tu_voteinfo.No = 3
|
||||
tu_voteinfo.Abstain = 5
|
||||
pm_voteinfo.Yes = 1
|
||||
pm_voteinfo.No = 3
|
||||
pm_voteinfo.Abstain = 5
|
||||
|
||||
# total_votes() should be the sum of Yes, No and Abstain: 1 + 3 + 5 = 9.
|
||||
assert tu_voteinfo.total_votes() == 9
|
||||
assert pm_voteinfo.total_votes() == 9
|
||||
|
||||
|
||||
def test_tu_voteinfo_null_submitter_raises(user: User):
|
||||
def test_pm_voteinfo_null_submitter_raises(user: User):
|
||||
with pytest.raises(IntegrityError):
|
||||
with db.begin():
|
||||
create(
|
||||
|
@ -108,7 +108,7 @@ def test_tu_voteinfo_null_submitter_raises(user: User):
|
|||
rollback()
|
||||
|
||||
|
||||
def test_tu_voteinfo_null_agenda_raises(user: User):
|
||||
def test_pm_voteinfo_null_agenda_raises(user: User):
|
||||
with pytest.raises(IntegrityError):
|
||||
with db.begin():
|
||||
create(
|
||||
|
@ -122,7 +122,7 @@ def test_tu_voteinfo_null_agenda_raises(user: User):
|
|||
rollback()
|
||||
|
||||
|
||||
def test_tu_voteinfo_null_user_raises(user: User):
|
||||
def test_pm_voteinfo_null_user_raises(user: User):
|
||||
with pytest.raises(IntegrityError):
|
||||
with db.begin():
|
||||
create(
|
||||
|
@ -136,7 +136,7 @@ def test_tu_voteinfo_null_user_raises(user: User):
|
|||
rollback()
|
||||
|
||||
|
||||
def test_tu_voteinfo_null_submitted_raises(user: User):
|
||||
def test_pm_voteinfo_null_submitted_raises(user: User):
|
||||
with pytest.raises(IntegrityError):
|
||||
with db.begin():
|
||||
create(
|
||||
|
@ -150,7 +150,7 @@ def test_tu_voteinfo_null_submitted_raises(user: User):
|
|||
rollback()
|
||||
|
||||
|
||||
def test_tu_voteinfo_null_end_raises(user: User):
|
||||
def test_pm_voteinfo_null_end_raises(user: User):
|
||||
with pytest.raises(IntegrityError):
|
||||
with db.begin():
|
||||
create(
|
||||
|
@ -164,7 +164,7 @@ def test_tu_voteinfo_null_end_raises(user: User):
|
|||
rollback()
|
||||
|
||||
|
||||
def test_tu_voteinfo_null_quorum_default(user: User):
|
||||
def test_pm_voteinfo_null_quorum_default(user: User):
|
||||
with db.begin():
|
||||
vi = create(
|
||||
TUVoteInfo,
|
|
@ -77,7 +77,7 @@ def voteinfo(user: User) -> TUVoteInfo:
|
|||
yield voteinfo
|
||||
|
||||
|
||||
def test_tu_vote_reminders(user: User, user2: User, user3: User, voteinfo: TUVoteInfo):
|
||||
def test_pm_vote_reminders(user: User, user2: User, user3: User, voteinfo: TUVoteInfo):
|
||||
reminder.main()
|
||||
assert Email.count() == 3
|
||||
|
||||
|
@ -96,7 +96,7 @@ def test_tu_vote_reminders(user: User, user2: User, user3: User, voteinfo: TUVot
|
|||
assert emails[i].body == content
|
||||
|
||||
|
||||
def test_tu_vote_reminders_only_unvoted(
|
||||
def test_pm_vote_reminders_only_unvoted(
|
||||
user: User, user2: User, user3: User, voteinfo: TUVoteInfo
|
||||
):
|
||||
# Vote with user2 and user3; leaving only user to be notified.
|
|
@ -157,9 +157,9 @@ def requests(
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_user() -> User:
|
||||
"""Yield an authenticated Trusted User instance."""
|
||||
user = create_user("test_tu", "test_tu@example.org")
|
||||
def pm_user() -> User:
|
||||
"""Yield an authenticated Package Maintainer instance."""
|
||||
user = create_user("test_pm", "test_pm@example.org")
|
||||
with db.begin():
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_ID
|
||||
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||
|
@ -416,7 +416,7 @@ def test_request_post_orphan(client: TestClient, auser: User, pkgbase: PackageBa
|
|||
def test_deletion_request(
|
||||
client: TestClient,
|
||||
user: User,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
pkgbase: PackageBase,
|
||||
pkgreq: PackageRequest,
|
||||
):
|
||||
|
@ -433,7 +433,7 @@ def test_deletion_request(
|
|||
comments = "Test closure."
|
||||
data = {"comments": comments, "confirm": True}
|
||||
with client as request:
|
||||
request.cookies = tu_user.cookies
|
||||
request.cookies = pm_user.cookies
|
||||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert resp.headers.get("location") == "/packages"
|
||||
|
@ -456,17 +456,17 @@ def test_deletion_request(
|
|||
email = Email(3).parse()
|
||||
subject = r"^AUR Package deleted: [^ ]+$"
|
||||
assert re.match(subject, email.headers.get("Subject"))
|
||||
body = r"%s [1] deleted %s [2]." % (tu_user.Username, pkgbase.Name)
|
||||
body = r"%s [1] deleted %s [2]." % (pm_user.Username, pkgbase.Name)
|
||||
assert body in email.body
|
||||
|
||||
|
||||
def test_deletion_autorequest(client: TestClient, tu_user: User, pkgbase: PackageBase):
|
||||
def test_deletion_autorequest(client: TestClient, pm_user: User, pkgbase: PackageBase):
|
||||
"""Test deleting a package without a request."""
|
||||
# `pkgreq`.ReqTypeID is already DELETION_ID.
|
||||
endpoint = f"/pkgbase/{pkgbase.Name}/delete"
|
||||
data = {"confirm": True}
|
||||
with client as request:
|
||||
request.cookies = tu_user.cookies
|
||||
request.cookies = pm_user.cookies
|
||||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
|
||||
|
@ -480,14 +480,14 @@ def test_deletion_autorequest(client: TestClient, tu_user: User, pkgbase: Packag
|
|||
|
||||
|
||||
def test_deletion_autorequest_with_comment(
|
||||
client: TestClient, tu_user: User, pkgbase: PackageBase
|
||||
client: TestClient, pm_user: User, pkgbase: PackageBase
|
||||
):
|
||||
"""Test deleting a package without a request and a comment."""
|
||||
# `pkgreq`.ReqTypeID is already DELETION_ID.
|
||||
endpoint = f"/pkgbase/{pkgbase.Name}/delete"
|
||||
data = {"confirm": True, "comments": "deleted with comment"}
|
||||
with client as request:
|
||||
request.cookies = tu_user.cookies
|
||||
request.cookies = pm_user.cookies
|
||||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
|
||||
|
@ -503,7 +503,7 @@ def test_deletion_autorequest_with_comment(
|
|||
def test_merge_request(
|
||||
client: TestClient,
|
||||
user: User,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
pkgbase: PackageBase,
|
||||
target: PackageBase,
|
||||
pkgreq: PackageRequest,
|
||||
|
@ -526,7 +526,7 @@ def test_merge_request(
|
|||
comments = "Test merge closure."
|
||||
data = {"into": target.Name, "comments": comments, "confirm": True}
|
||||
with client as request:
|
||||
request.cookies = tu_user.cookies
|
||||
request.cookies = pm_user.cookies
|
||||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert resp.headers.get("location") == f"/pkgbase/{target.Name}"
|
||||
|
@ -561,7 +561,7 @@ def test_merge_request(
|
|||
def test_merge_autorequest(
|
||||
client: TestClient,
|
||||
user: User,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
pkgbase: PackageBase,
|
||||
target: PackageBase,
|
||||
):
|
||||
|
@ -574,7 +574,7 @@ def test_merge_autorequest(
|
|||
endpoint = f"/pkgbase/{pkgbase.Name}/merge"
|
||||
data = {"into": target.Name, "confirm": True}
|
||||
with client as request:
|
||||
request.cookies = tu_user.cookies
|
||||
request.cookies = pm_user.cookies
|
||||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert resp.headers.get("location") == f"/pkgbase/{target.Name}"
|
||||
|
@ -592,7 +592,7 @@ def test_merge_autorequest(
|
|||
def test_merge_autorequest_with_comment(
|
||||
client: TestClient,
|
||||
user: User,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
pkgbase: PackageBase,
|
||||
target: PackageBase,
|
||||
):
|
||||
|
@ -605,7 +605,7 @@ def test_merge_autorequest_with_comment(
|
|||
endpoint = f"/pkgbase/{pkgbase.Name}/merge"
|
||||
data = {"into": target.Name, "confirm": True, "comments": "merged with comment"}
|
||||
with client as request:
|
||||
request.cookies = tu_user.cookies
|
||||
request.cookies = pm_user.cookies
|
||||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert resp.headers.get("location") == f"/pkgbase/{target.Name}"
|
||||
|
@ -623,7 +623,7 @@ def test_merge_autorequest_with_comment(
|
|||
def test_orphan_request(
|
||||
client: TestClient,
|
||||
user: User,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
pkgbase: PackageBase,
|
||||
pkgreq: PackageRequest,
|
||||
):
|
||||
|
@ -643,7 +643,7 @@ def test_orphan_request(
|
|||
comments = "Test orphan closure."
|
||||
data = {"comments": comments, "confirm": True}
|
||||
with client as request:
|
||||
request.cookies = tu_user.cookies
|
||||
request.cookies = pm_user.cookies
|
||||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert resp.headers.get("location") == f"/pkgbase/{pkgbase.Name}"
|
||||
|
@ -665,7 +665,7 @@ def test_orphan_request(
|
|||
|
||||
|
||||
def test_request_post_orphan_autogenerated_closure(
|
||||
client: TestClient, tu_user: User, pkgbase: PackageBase, pkgreq: PackageRequest
|
||||
client: TestClient, pm_user: User, pkgbase: PackageBase, pkgreq: PackageRequest
|
||||
):
|
||||
idle_time = config.getint("options", "request_idle_time")
|
||||
now = time.utcnow()
|
||||
|
@ -677,7 +677,7 @@ def test_request_post_orphan_autogenerated_closure(
|
|||
endpoint = f"/pkgbase/{pkgbase.Name}/disown"
|
||||
data = {"confirm": True}
|
||||
with client as request:
|
||||
request.cookies = tu_user.cookies
|
||||
request.cookies = pm_user.cookies
|
||||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert resp.headers.get("location") == f"/pkgbase/{pkgbase.Name}"
|
||||
|
@ -752,13 +752,13 @@ def test_orphan_as_maintainer(client: TestClient, auser: User, pkgbase: PackageB
|
|||
|
||||
|
||||
def test_orphan_without_requests(
|
||||
client: TestClient, tu_user: User, pkgbase: PackageBase
|
||||
client: TestClient, pm_user: User, pkgbase: PackageBase
|
||||
):
|
||||
"""Test orphans are automatically accepted past a certain date."""
|
||||
endpoint = f"/pkgbase/{pkgbase.Name}/disown"
|
||||
data = {"confirm": True}
|
||||
with client as request:
|
||||
request.cookies = tu_user.cookies
|
||||
request.cookies = pm_user.cookies
|
||||
resp = request.post(endpoint, data=data)
|
||||
assert resp.status_code == int(HTTPStatus.BAD_REQUEST)
|
||||
|
||||
|
@ -792,11 +792,11 @@ def test_requests_unauthorized(client: TestClient):
|
|||
|
||||
def test_requests(
|
||||
client: TestClient,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
packages: list[Package],
|
||||
requests: list[PackageRequest],
|
||||
):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.get(
|
||||
|
@ -835,11 +835,11 @@ def test_requests(
|
|||
|
||||
def test_requests_with_filters(
|
||||
client: TestClient,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
packages: list[Package],
|
||||
requests: list[PackageRequest],
|
||||
):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.get(
|
||||
|
@ -893,11 +893,11 @@ def test_requests_with_filters(
|
|||
|
||||
def test_requests_for_maintainer_requests(
|
||||
client: TestClient,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
packages: list[Package],
|
||||
requests: list[PackageRequest],
|
||||
):
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.get(
|
||||
|
@ -914,13 +914,13 @@ def test_requests_for_maintainer_requests(
|
|||
|
||||
def test_requests_with_package_name_filter(
|
||||
client: TestClient,
|
||||
tu_user: User,
|
||||
pm_user: User,
|
||||
user2: User,
|
||||
packages: list[Package],
|
||||
requests: list[PackageRequest],
|
||||
):
|
||||
# test as TU
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.get(
|
||||
|
@ -965,12 +965,12 @@ def test_requests_with_package_name_filter(
|
|||
|
||||
|
||||
def test_requests_by_deleted_users(
|
||||
client: TestClient, user: User, tu_user: User, pkgreq: PackageRequest
|
||||
client: TestClient, user: User, pm_user: User, pkgreq: PackageRequest
|
||||
):
|
||||
with db.begin():
|
||||
db.delete(user)
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": pm_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.get("/requests")
|
||||
|
|
|
@ -116,10 +116,10 @@ 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("package_maintainer_count")
|
||||
pms_before = stats.get_count("package_maintainer_count")
|
||||
|
||||
assert pkgs_before == 10
|
||||
assert tus_before == 1
|
||||
assert pms_before == 1
|
||||
|
||||
# Let's delete a package and promote a user to TU
|
||||
with db.begin():
|
||||
|
@ -131,12 +131,12 @@ def test_get_count_change(stats: Statistics, test_data):
|
|||
|
||||
# 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("package_maintainer_count") == tus_before
|
||||
assert stats.get_count("package_maintainer_count") == pms_before
|
||||
|
||||
# Let's clear the cache and check again
|
||||
cache._redis.flushall()
|
||||
assert stats.get_count("package_count") != pkgs_before
|
||||
assert stats.get_count("package_maintainer_count") != tus_before
|
||||
assert stats.get_count("package_maintainer_count") != pms_before
|
||||
|
||||
|
||||
def test_update_prometheus_metrics(test_data):
|
||||
|
|
|
@ -52,7 +52,7 @@ def user() -> User:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_user() -> User:
|
||||
def pm_user() -> User:
|
||||
user = create_user("test_tu", PACKAGE_MAINTAINER_ID)
|
||||
yield user
|
||||
|
||||
|
@ -64,8 +64,8 @@ def dev_user() -> User:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def tu_and_dev_user() -> User:
|
||||
user = create_user("test_tu_and_dev", PACKAGE_MAINTAINER_AND_DEV_ID)
|
||||
def pm_and_dev_user() -> User:
|
||||
user = create_user("test_pm_and_dev", PACKAGE_MAINTAINER_AND_DEV_ID)
|
||||
yield user
|
||||
|
||||
|
||||
|
@ -297,34 +297,34 @@ def test_user_packages(user: User, package: Package):
|
|||
|
||||
|
||||
def test_can_edit_user(
|
||||
user: User, tu_user: User, dev_user: User, tu_and_dev_user: User
|
||||
user: User, pm_user: User, dev_user: User, pm_and_dev_user: User
|
||||
):
|
||||
# User can edit.
|
||||
assert user.can_edit_user(user)
|
||||
|
||||
# User cannot edit.
|
||||
assert not user.can_edit_user(tu_user)
|
||||
assert not user.can_edit_user(pm_user)
|
||||
assert not user.can_edit_user(dev_user)
|
||||
assert not user.can_edit_user(tu_and_dev_user)
|
||||
assert not user.can_edit_user(pm_and_dev_user)
|
||||
|
||||
# Trusted User can edit.
|
||||
assert tu_user.can_edit_user(user)
|
||||
assert tu_user.can_edit_user(tu_user)
|
||||
assert pm_user.can_edit_user(user)
|
||||
assert pm_user.can_edit_user(pm_user)
|
||||
|
||||
# Trusted User cannot edit.
|
||||
assert not tu_user.can_edit_user(dev_user)
|
||||
assert not tu_user.can_edit_user(tu_and_dev_user)
|
||||
assert not pm_user.can_edit_user(dev_user)
|
||||
assert not pm_user.can_edit_user(pm_and_dev_user)
|
||||
|
||||
# Developer can edit.
|
||||
assert dev_user.can_edit_user(user)
|
||||
assert dev_user.can_edit_user(tu_user)
|
||||
assert dev_user.can_edit_user(pm_user)
|
||||
assert dev_user.can_edit_user(dev_user)
|
||||
|
||||
# Developer cannot edit.
|
||||
assert not dev_user.can_edit_user(tu_and_dev_user)
|
||||
assert not dev_user.can_edit_user(pm_and_dev_user)
|
||||
|
||||
# Trusted User & Developer can edit.
|
||||
assert tu_and_dev_user.can_edit_user(user)
|
||||
assert tu_and_dev_user.can_edit_user(tu_user)
|
||||
assert tu_and_dev_user.can_edit_user(dev_user)
|
||||
assert tu_and_dev_user.can_edit_user(tu_and_dev_user)
|
||||
assert pm_and_dev_user.can_edit_user(user)
|
||||
assert pm_and_dev_user.can_edit_user(pm_user)
|
||||
assert pm_and_dev_user.can_edit_user(dev_user)
|
||||
assert pm_and_dev_user.can_edit_user(pm_and_dev_user)
|
||||
|
|
Loading…
Add table
Reference in a new issue