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