Skip to content

Commit

Permalink
t: add tests for --force option
Browse files Browse the repository at this point in the history
Problem: There exist no tests for calling delete_user() with the force
option set.

Add some tests.
  • Loading branch information
cmoussa1 committed Jan 30, 2025
1 parent fe5d4ee commit eba4b2c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
34 changes: 34 additions & 0 deletions t/python/t1002_user_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,40 @@ def test_16_edit_user_fairshare(self):
fairshare = cur.fetchall()
self.assertEqual(fairshare[0][0], 0.95)

# actually remove a user from the association_table
def test_17_delete_user_force(self):
cur = acct_conn.cursor()
select_stmt = "SELECT * FROM association_table WHERE username='test_user5'"
cur.execute(select_stmt)
result = cur.fetchall()
self.assertEqual(len(result), 1)

# pass force=True to actually remove the user row from the table
u.delete_user(acct_conn, username="test_user5", bank="A", force=True)
cur.execute(select_stmt)
result = cur.fetchall()
self.assertEqual(len(result), 0)

# actually remove a user from the association_table where their default
# bank needs to be updated
def test_18_delete_user_force_update_bank(self):
cur = acct_conn.cursor()
select_stmt = (
"SELECT default_bank FROM association_table WHERE username='test_user6'"
)
# add two associations
u.add_user(acct_conn, username="test_user6", bank="A")
u.add_user(acct_conn, username="test_user6", bank="B")
cur.execute(select_stmt)
default_bank = cur.fetchall()
self.assertEqual(default_bank[0][0], "A")

# delete one of the rows with force=True
u.delete_user(acct_conn, username="test_user6", bank="A", force=True)
cur.execute(select_stmt)
default_bank = cur.fetchall()
self.assertEqual(default_bank[0][0], "B")

# remove database and log file
@classmethod
def tearDownClass(self):
Expand Down
15 changes: 15 additions & 0 deletions t/t1007-flux-account-users.t
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ test_expect_success 'remove a user account' '
grep -f ${EXPECTED_FILES}/deleted_user.expected deleted_user.out
'

test_expect_success 'remove a user with --force' '
flux account delete-user user5011 A --force &&
test_must_fail flux account view-user user5011 > user5011_nonexistent.out 2>&1 &&
grep "view-user: user user5011 not found in association_table" user5011_nonexistent.out
'

test_expect_success 'remove a user with --force/make sure default bank gets updated' '
flux account add-user --username=user5201 --bank=A &&
flux account add-user --username=user5201 --bank=B &&
flux account add-user --username=user5201 --bank=C &&
flux account delete-user --force user5201 A &&
flux account view-user user5201 > user5201.out &&
test $(grep -c "\"default_bank\": \"B\"" user5201.out) -eq 2
'

test_expect_success 'remove flux-accounting DB' '
rm $(pwd)/FluxAccountingTest.db
'
Expand Down

0 comments on commit eba4b2c

Please sign in to comment.