What are the right way to test upgrade steps and running of registered profiles

in my test setup in the testing.py:

def setUpPloneSite(self, portal):
    applyProfile.....
    # load Upgrade Steps
    portal_setup = portal.portal_setup
    profile_id = "my.addon:default"
    portal_setup.setLastVersionForProfile(profile_id, "1000")
    portal_setup.upgradeProfile(profile_id)

the metadata.xml contains the version number:

<?xml version="1.0" encoding="utf-8"?>
<metadata>
  <version>1028</version>
</metadata>

in my test i do this:

def test_current_version(self):
    profile_id = "my.addon:default"
    portal_setup = self.portal.portal_setup
    version = portal_setup.getVersionForProfile(profile_id)
    last_version = portal_setup.getLastVersionForProfile(profile_id)[0]
    self.assertEqual(version, last_version)

Question: is this the right way to check the version and the running of upgrades to the last profile number?

That looks okay, as long as you keep in mind that you're testing a somewhat manufactured scenario where all the upgrade steps run even though the final state of the profile was already installed.

pytest-plone also has a profile_last_version fixture that you can use: GitHub - collective/pytest-plone: Pytest plugin to test Plone addons

2 Likes