示例#1
0
    def test__get_version_from_effective_pom(self, ET_mock, join_mock, log_mock):
        def t(suffix=''):
            def a(key):
                mock = MagicMock()
                if 'version' in key:
                    mock.text = '1.0.0{}'.format('-' + suffix if suffix else '')
                elif 'groupId' in key:
                    mock.text = 'group'
                elif 'artifactId' in key:
                    mock.text = 'artifact'
                else:
                    mock.text = ''

                return mock

            return a

        root_mock = MagicMock()
        root_mock.tag.split = MagicMock(return_value=['', 'project'])
        pom_mock = MagicMock()
        pom_mock.getroot = MagicMock(return_value=root_mock)
        ET_mock.parse = MagicMock(return_value=pom_mock)

        cfg = BuildConfig()
        cfg._genroot_dir = ''
        m = maven.build(cfg)
        m._mvn = MagicMock()

        # NO SUFFIX
        pom_mock.find = MagicMock(side_effect=t())
        m._get_version_from_effective_pom()
        assert cfg.version() == '1.0.0'

        # SUFFIX in pom version
        # SNAPSHOT
        pom_mock.find = MagicMock(side_effect=t('SNAPSHOT'))
        m._get_version_from_effective_pom()
        assert cfg.version() == '1.0.0'

        # RELEASE
        pom_mock.find = MagicMock(side_effect=t('RELEASE'))
        m._get_version_from_effective_pom()
        assert cfg.version() == '1.0.0'

        # MILESTONE
        pom_mock.find = MagicMock(side_effect=t('MILESTONE'))
        m._get_version_from_effective_pom()
        assert cfg.version() == '1.0.0'

        # NO SUFFIX in pom version but in build_config._version_suffix
        pom_mock.find = MagicMock(side_effect=t())

        # BLALA
        cfg._version_suffix = 'BLABLA'
        m._get_version_from_effective_pom()
        assert cfg.version() == '1.0.0-BLABLA'
示例#2
0
    def test_storePromoteProps_nogav(self, log_mock, StagingAPI_mock, open_mock):
        configParser_mock = Mock()
        ConfigParser.ConfigParser = MagicMock(return_value=configParser_mock)
        api = StagingAPI_mock()
        api.getrepositorystatus = MagicMock(return_value= {'repositoryURI': 'http://mo-49a5bdc06.mo.sap.corp:8081/nexus/content/repositories/repoIdtotto', 'releaseRepositoryId': 'deploy.milestones'})
        buildConfig = BuildConfig()
        buildConfig.promote_props_file = MagicMock(return_value= "promote.properties")
        buildConfig.version = MagicMock(return_value= "4.5.0")
        buildConfig.base_group = MagicMock(return_value= None)
        buildConfig.base_artifact = MagicMock(return_value= None)

        promote._storePromoteProps(api, buildConfig, "toto", "a", "4.5.0")
        assert(configParser_mock.set.call_count == 2)
        assert (open_mock.call_count == 1)
示例#3
0
    def test_storePromoteProps_fail(self, log_mock, StagingAPI_mock, open_mock):
        configParser_mock = Mock()
        ConfigParser.ConfigParser = MagicMock(return_value=configParser_mock)
        api = StagingAPI_mock()
        api.getrepositorystatus = MagicMock(return_value= {})
        buildConfig = BuildConfig()
        buildConfig.promote_props_file = MagicMock(return_value= "promote.properties")
        buildConfig.version = MagicMock(return_value= "4.5.0")
        buildConfig.base_group = MagicMock(return_value= "com.sap.prd.dita")
        buildConfig.base_artifact = MagicMock(return_value= "com.sap.prd.dita.projectmap.api")

        promote._storePromoteProps(api, buildConfig, "toto", "a", "4.5.0")
        log_mock.error.assert_called_once_with('impossible to store promote properties. Can not have repository status: {} ')

        assert(configParser_mock.set.call_count == 0)
        assert (open_mock.call_count == 0)
示例#4
0
    def test_storePromoteProps_base(self, log_mock, StagingAPI_mock, open_mock):
        configParser_mock = Mock()
        ConfigParser.ConfigParser = MagicMock(return_value=configParser_mock)
        api = StagingAPI_mock()
        api.getrepositorystatus = MagicMock(return_value= {'repositoryURI': 'http://mo-49a5bdc06.mo.sap.corp:8081/nexus/content/repositories/repoIdtotto', 'releaseRepositoryId': 'deploy.milestones'})
        buildConfig = BuildConfig()
        buildConfig.promote_props_file = MagicMock(return_value= "promote.properties")
        buildConfig.version = MagicMock(return_value= "4.5.0")
        buildConfig.base_group = MagicMock(return_value= "com.sap.prd.dita")
        buildConfig.base_artifact = MagicMock(return_value= "com.sap.prd.dita.projectmap.api")

        promote._storePromoteProps(api, buildConfig, "toto", "a", "4.5.0")
        configParser_mock.set.assert_any_call('promote','release.metadata.url','http://mo-49a5bdc06.mo.sap.corp:8081/nexus/content/repositories/deploy.milestones/com/sap/prd/dita/com.sap.prd.dita.projectmap.api/4.5.0/com.sap.prd.dita.projectmap.api-4.5.0-releaseMetadata.zip')
        configParser_mock.set.assert_any_call('promote','base.group','com.sap.prd.dita')
        configParser_mock.set.assert_any_call('promote','base.artifact','com.sap.prd.dita.projectmap.api')
        configParser_mock.set.assert_any_call('promote','base.version','4.5.0')
        configParser_mock.set.assert_any_call('promote','base.treeish','a')

        assert(configParser_mock.set.call_count == 5)
        assert (open_mock.call_count == 1)