|
24 | 24 |
|
25 | 25 | import io |
26 | 26 | import os |
| 27 | +import shutil |
27 | 28 | import tempfile |
28 | 29 | import sys |
29 | 30 |
|
@@ -727,6 +728,64 @@ def test_131_set_get_default_whitelist(self, mock_subprocess): |
727 | 728 | self.assertEqual(whitelist, self.ext.get_default_whitelist(tpl)) |
728 | 729 |
|
729 | 730 |
|
| 731 | + @unittest.mock.patch('subprocess.check_call') |
| 732 | + def test_140_remove_cleans_menu_files(self, mock_subprocess): |
| 733 | + tpl = TestVM('test-inst-tpl', |
| 734 | + klass='TemplateVM', |
| 735 | + virt_mode='pvh', |
| 736 | + updateable=True, |
| 737 | + provides_network=False, |
| 738 | + label=self.app.labels[1]) |
| 739 | + self.ext.appmenus_init(tpl) |
| 740 | + appvm = TestVM('test-inst-app', |
| 741 | + klass='AppVM', |
| 742 | + template=tpl, |
| 743 | + virt_mode='pvh', |
| 744 | + updateable=False, |
| 745 | + provides_network=False, |
| 746 | + label=self.app.labels[1]) |
| 747 | + self.ext.appmenus_init(appvm) |
| 748 | + self.ext.appmenus_create(appvm, refresh_cache=False) |
| 749 | + |
| 750 | + config_dir = tempfile.mkdtemp() |
| 751 | + try: |
| 752 | + menus_dir = os.path.join(config_dir, 'menus', 'applications-merged') |
| 753 | + os.makedirs(menus_dir) |
| 754 | + escaped = qubesappmenus.vm_name_escape(appvm.name) |
| 755 | + # current-format .menu file |
| 756 | + menu_file = os.path.join(menus_dir, |
| 757 | + 'user-qubes-vm-directory' + escaped + '.menu') |
| 758 | + # old-format .menu file (pre-escaping) |
| 759 | + old_menu_file = os.path.join(menus_dir, |
| 760 | + 'user-qubes-vm-directory-' + appvm.name + '.menu') |
| 761 | + for path in (menu_file, old_menu_file): |
| 762 | + with open(path, 'w', encoding='utf-8') as f: |
| 763 | + f.write('<Menu/>\n') |
| 764 | + |
| 765 | + with unittest.mock.patch('xdg.BaseDirectory.xdg_config_home', |
| 766 | + config_dir): |
| 767 | + self.ext.appmenus_remove(appvm, refresh_cache=False) |
| 768 | + |
| 769 | + self.assertPathNotExists(menu_file) |
| 770 | + self.assertPathNotExists(old_menu_file) |
| 771 | + finally: |
| 772 | + shutil.rmtree(config_dir) |
| 773 | + |
| 774 | + def test_141_remove_menu_files_missing_dir(self): |
| 775 | + config_dir = tempfile.mkdtemp() |
| 776 | + try: |
| 777 | + menus_dir = os.path.join(config_dir, 'menus', 'applications-merged') |
| 778 | + with unittest.mock.patch('xdg.BaseDirectory.xdg_config_home', |
| 779 | + config_dir), \ |
| 780 | + unittest.mock.patch('os.unlink') as mock_unlink: |
| 781 | + # Missing applications-merged directory should be ignored. |
| 782 | + qubesappmenus.Appmenus._remove_menu_files('test-vm') |
| 783 | + mock_unlink.assert_not_called() |
| 784 | + self.assertFalse(os.path.exists(menus_dir)) |
| 785 | + finally: |
| 786 | + shutil.rmtree(config_dir) |
| 787 | + |
| 788 | + |
730 | 789 | def list_tests(): |
731 | 790 | return (TC_00_Appmenus,) |
732 | 791 |
|
|
0 commit comments