|
| 1 | +from os import EX_UNAVAILABLE, EX_OK |
| 2 | + |
| 3 | +from hypernode_api_python.commands import destroy_brancher |
| 4 | +from tests.testcase import TestCase |
| 5 | + |
| 6 | + |
| 7 | +class TestDestroyBrancher(TestCase): |
| 8 | + def setUp(self): |
| 9 | + self.exit = self.set_up_patch("hypernode_api_python.commands.exit") |
| 10 | + self.print = self.set_up_patch("hypernode_api_python.commands.print") |
| 11 | + self.print_response = self.set_up_patch( |
| 12 | + "hypernode_api_python.commands.print_response" |
| 13 | + ) |
| 14 | + self.get_client = self.set_up_patch("hypernode_api_python.commands.get_client") |
| 15 | + self.client = self.get_client.return_value |
| 16 | + |
| 17 | + def test_destroy_brancher_gets_client(self): |
| 18 | + destroy_brancher(["myappname-eph1234"]) |
| 19 | + |
| 20 | + self.get_client.assert_called_once_with() |
| 21 | + |
| 22 | + def test_destroy_brancher_destroys_brancher(self): |
| 23 | + destroy_brancher(["myappname-eph1234"]) |
| 24 | + |
| 25 | + self.client.destroy_brancher.assert_called_once_with("myappname-eph1234") |
| 26 | + |
| 27 | + def test_destroy_brancher_prints_app_name_is_valid(self): |
| 28 | + destroy_brancher(["myappname-eph1234"]) |
| 29 | + |
| 30 | + self.print.assert_called_once_with( |
| 31 | + "A job has been posted to cancel the 'myappname-eph1234' brancher app." |
| 32 | + ) |
| 33 | + |
| 34 | + def test_destroy_brancher_prints_app_name_is_invalid(self): |
| 35 | + self.client.destroy_brancher.side_effect = MemoryError("Killed") |
| 36 | + |
| 37 | + destroy_brancher(["myappname-eph1234"]) |
| 38 | + |
| 39 | + self.print.assert_called_once_with( |
| 40 | + "Brancher app 'myappname-eph1234' failed to be cancelled: Killed" |
| 41 | + ) |
| 42 | + |
| 43 | + def test_destroy_brancher_exits_zero_when_cancel_job_posted(self): |
| 44 | + destroy_brancher(["myappname-eph1234"]) |
| 45 | + |
| 46 | + self.exit.assert_called_once_with(EX_OK) |
| 47 | + |
| 48 | + def test_destroy_brancher_exits_nonzero_when_unexpected_exception_occurs(self): |
| 49 | + self.client.destroy_brancher.side_effect = RuntimeError |
| 50 | + |
| 51 | + destroy_brancher(["myappname-eph1234"]) |
| 52 | + |
| 53 | + self.exit.assert_called_once_with(EX_UNAVAILABLE) |
0 commit comments