From 39b97552fb7283c47c5195dcdbcc4131529c9fa0 Mon Sep 17 00:00:00 2001 From: Christopher Moussa Date: Wed, 29 Jan 2025 16:01:11 -0800 Subject: [PATCH] t: add tests for --force option Problem: There exist no tests for calling delete_bank() with the force option set. Add some tests. --- t/python/t1003_bank_cmds.py | 17 +++++++++++++++++ t/t1023-flux-account-banks.t | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/t/python/t1003_bank_cmds.py b/t/python/t1003_bank_cmds.py index b38f9e88..8532f483 100755 --- a/t/python/t1003_bank_cmds.py +++ b/t/python/t1003_bank_cmds.py @@ -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): diff --git a/t/t1023-flux-account-banks.t b/t/t1023-flux-account-banks.t index bd121aa8..c72817fc 100755 --- a/t/t1023-flux-account-banks.t +++ b/t/t1023-flux-account-banks.t @@ -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 '