def testCleanupUninstalledProducts(self): from plone.app.upgrade.v43.final import cleanupUninstalledProducts qi = getToolByName(self.portal, 'portal_quickinstaller') setup = getToolByName(self.portal, 'portal_setup') # Register three profiles. I wanted to take 'new' as product # id, but there is already a python module 'new', so that goes # wrong. profile_registry.registerProfile( 'default', '', '', '/my/path', product='newproduct', profile_type=EXTENSION) profile_registry.registerProfile( 'default', '', '', '/my/path', product='installed', profile_type=EXTENSION) profile_registry.registerProfile( 'default', '', '', '/my/path', product='uninstalled', profile_type=EXTENSION) # Mark as installed. setup.setLastVersionForProfile('newproduct:default', '1') setup.setLastVersionForProfile('installed:default', '1') setup.setLastVersionForProfile('uninstalled:default', '1') # Notify of installation of three products. qi.notifyInstalled('newproduct', status='new') qi.notifyInstalled('installed', status='installed') qi.notifyInstalled('uninstalled', status='uninstalled') # The status differs, so QI does not think all are actually # installed. self.assertFalse(qi.isProductInstalled('newproduct')) self.assertTrue(qi.isProductInstalled('installed')) self.assertFalse(qi.isProductInstalled('uninstalled')) # But all three have an object in the QI. self.assertTrue('newproduct' in qi) self.assertTrue('installed' in qi) self.assertTrue('uninstalled' in qi) # And all three have a version in GS. self.assertEqual( setup.getLastVersionForProfile('newproduct:default'), ('1',)) self.assertEqual( setup.getLastVersionForProfile('installed:default'), ('1',)) self.assertEqual( setup.getLastVersionForProfile('uninstalled:default'), ('1',)) # Call our cleanup function. cleanupUninstalledProducts(setup) # Same results for isProductInstalled. self.assertFalse(qi.isProductInstalled('newproduct')) self.assertTrue(qi.isProductInstalled('installed')) self.assertFalse(qi.isProductInstalled('uninstalled')) # The two not installed items are removed. self.assertFalse('newproduct' in qi) self.assertTrue('installed' in qi) self.assertFalse('uninstalled' in qi) # Those twee are unknown in GS. self.assertEqual( setup.getLastVersionForProfile('newproduct:default'), 'unknown') self.assertEqual( setup.getLastVersionForProfile('installed:default'), ('1',)) self.assertEqual( setup.getLastVersionForProfile('uninstalled:default'), 'unknown') # Cleanup test. profile_registry.unregisterProfile('default', 'newproduct') profile_registry.unregisterProfile('default', 'installed') profile_registry.unregisterProfile('default', 'uninstalled')
def testCleanupUninstalledProducts(self): from plone.app.upgrade.v43.final import cleanupUninstalledProducts qi = getToolByName(self.portal, 'portal_quickinstaller', None) if qi is None: # Newer Plone without qi. return setup = getToolByName(self.portal, 'portal_setup') # Register three profiles. I wanted to take 'new' as product # id, but there is already a python module 'new', so that goes # wrong. profile_registry.registerProfile('default', '', '', '/my/path', product='newproduct', profile_type=EXTENSION) profile_registry.registerProfile('default', '', '', '/my/path', product='installed', profile_type=EXTENSION) profile_registry.registerProfile('default', '', '', '/my/path', product='uninstalled', profile_type=EXTENSION) # Mark as installed. setup.setLastVersionForProfile('newproduct:default', '1') setup.setLastVersionForProfile('installed:default', '1') setup.setLastVersionForProfile('uninstalled:default', '1') # Notify of installation of three products. qi.notifyInstalled('newproduct', status='new') qi.notifyInstalled('installed', status='installed') qi.notifyInstalled('uninstalled', status='uninstalled') # The status differs, so QI does not think all are actually # installed. self.assertFalse(qi.isProductInstalled('newproduct')) self.assertTrue(qi.isProductInstalled('installed')) self.assertFalse(qi.isProductInstalled('uninstalled')) # But all three have an object in the QI. self.assertTrue('newproduct' in qi) self.assertTrue('installed' in qi) self.assertTrue('uninstalled' in qi) # And all three have a version in GS. self.assertEqual(setup.getLastVersionForProfile('newproduct:default'), ('1', )) self.assertEqual(setup.getLastVersionForProfile('installed:default'), ('1', )) self.assertEqual(setup.getLastVersionForProfile('uninstalled:default'), ('1', )) # Call our cleanup function. cleanupUninstalledProducts(setup) # Same results for isProductInstalled. self.assertFalse(qi.isProductInstalled('newproduct')) self.assertTrue(qi.isProductInstalled('installed')) self.assertFalse(qi.isProductInstalled('uninstalled')) # The two not installed items are removed. self.assertFalse('newproduct' in qi) self.assertTrue('installed' in qi) self.assertFalse('uninstalled' in qi) # Those twee are unknown in GS. self.assertEqual(setup.getLastVersionForProfile('newproduct:default'), 'unknown') self.assertEqual(setup.getLastVersionForProfile('installed:default'), ('1', )) self.assertEqual(setup.getLastVersionForProfile('uninstalled:default'), 'unknown') # Cleanup test. profile_registry.unregisterProfile('default', 'newproduct') profile_registry.unregisterProfile('default', 'installed') profile_registry.unregisterProfile('default', 'uninstalled')