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_bank() with the force
option set.

Add some tests.
  • Loading branch information
cmoussa1 committed Jan 30, 2025
1 parent ca012bc commit 39b9755
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions t/python/t1003_bank_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@ def test_12_reactivate_bank(self):
rows = cur.fetchall()
self.assertEqual(rows[0][0], 1)

# actually remove a bank row from the bank_table
def test_13_delete_bank_force(self):
b.delete_bank(acct_conn, bank="G", force=True)
cur.execute("SELECT * FROM bank_table WHERE bank='G'")
rows = cur.fetchall()
self.assertEqual(len(rows), 0)

# actually delete multiple banks from bank_table by deleting a parent bank
def test_14_delete_parent_bank_force(self):
b.delete_bank(acct_conn, bank="C", force=True)
cur.execute("SELECT * FROM bank_table WHERE bank='C'")
rows = cur.fetchall()
self.assertEqual(len(rows), 0)
cur.execute("SELECT * FROM bank_table WHERE parent_bank='C'")
rows = cur.fetchall()
self.assertEqual(len(rows), 0)

# remove database and log file
@classmethod
def tearDownClass(self):
Expand Down
18 changes: 18 additions & 0 deletions t/t1023-flux-account-banks.t
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ test_expect_success 'combining --tree with --fields does not work' '
grep "tree option does not support custom formatting" error.out
'

test_expect_success 'delete a bank with --force; ensure users also get deleted' '
flux account delete-bank C --force &&
test_must_fail flux account view-bank C > nonexistent_bank.out 2>&1 &&
grep "view-bank: bank C not found in bank_table" nonexistent_bank.out &&
test_must_fail flux account view-user user5014 > nonexistent_user.out 2>&1 &&
grep "view-user: user user5014 not found in association_table" nonexistent_user.out
'

test_expect_success 'delete a bank with multiple sub-banks and users with --force' '
flux account delete-bank D --force &&
test_must_fail flux account view-bank E > bankE_noexist.out 2>&1 &&
grep "view-bank: bank E not found in bank_table" bankE_noexist.out &&
test_must_fail flux account view-bank F > bankF_noexist.out 2>&1 &&
grep "view-bank: bank F not found in bank_table" bankF_noexist.out &&
test_must_fail flux account view-user user5030 > nonexistent_user.out 2>&1 &&
grep "view-user: user user5030 not found in association_table" nonexistent_user.out
'

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

0 comments on commit 39b9755

Please sign in to comment.