示例#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_add_import_repo(self):
        nx_repos = ['http://nexus1', 'http://nexus2']
        docker_repos = ['http://docker1', 'http://docker2']

        cfg = BuildConfig()

        # non productive / non release build
        cfg._import_repos = {}
        cfg.add_import_repo(nx_repos[0])
        cfg.add_import_repo(nx_repos[1])
        cfg.add_import_repo(docker_repos[0], DOCKERREPO)
        cfg.add_import_repo(docker_repos[1], DOCKERREPO)
        assert cfg._import_repos[COMMONREPO] == nx_repos
        assert cfg._import_repos[DOCKERREPO] == docker_repos

        # productive build
        cfg._import_repos = {}
        cfg._productive = True
        cfg.add_import_repo(nx_repos[0])
        with self.assertRaisesRegexp(XmakeException, 'only one repository url is authorized'):
            cfg.add_import_repo(nx_repos[1])
        cfg.add_import_repo(docker_repos[0], DOCKERREPO)
        with self.assertRaisesRegexp(XmakeException, 'only one repository url is authorized'):
            cfg.add_import_repo(docker_repos[1], DOCKERREPO)

        assert cfg._import_repos[COMMONREPO] == [nx_repos[0]]
        assert cfg._import_repos[DOCKERREPO] == [docker_repos[0]]

        # xmake-ldi release build
        cfg._import_repos = {}
        cfg._productive = False
        cfg._release = 'release'
        cfg.add_import_repo(nx_repos[0])
        with self.assertRaisesRegexp(XmakeException, 'only one repository url is authorized'):
            cfg.add_import_repo(nx_repos[1])
        cfg.add_import_repo(docker_repos[0], DOCKERREPO)
        with self.assertRaisesRegexp(XmakeException, 'only one repository url is authorized'):
            cfg.add_import_repo(docker_repos[1], DOCKERREPO)
        assert cfg._import_repos[COMMONREPO] == [nx_repos[0]]
        assert cfg._import_repos[DOCKERREPO] == [docker_repos[0]]

        # xmake-dev release build
        cfg._import_repos = {}
        cfg._productive = True
        cfg._release = None
        cfg._version_suffix = None
        cfg.add_import_repo(nx_repos[0])
        with self.assertRaisesRegexp(XmakeException, 'only one repository url is authorized'):
            cfg.add_import_repo(nx_repos[1])
        cfg.add_import_repo(docker_repos[0], DOCKERREPO)
        with self.assertRaisesRegexp(XmakeException, 'only one repository url is authorized'):
            cfg.add_import_repo(docker_repos[1], DOCKERREPO)
        assert cfg._import_repos[COMMONREPO] == [nx_repos[0]]
        assert cfg._import_repos[DOCKERREPO] == [docker_repos[0]]
示例#3
0
    def test_import_repos(self):
        nx_repos = ['http://nexus1', 'http://nexus2', 'http://nexus3']
        docker_repos = ['http://docker1', 'http://docker2', 'http://docker3']
        npm_repos = ['http://npm1', 'http://npm2', 'http://npm3']


        # no repos
        cfg = BuildConfig()
        cfg._import_repos = {
            COMMONREPO: None,
            DOCKERREPO: None,
            NPMREPO: None
        }
        assert cfg.import_repos() == None
        assert cfg.import_repos(t=DOCKERREPO) == None
        assert cfg.import_repos(t=NPMREPO) == None

        # no repos productive build
        cfg._productive = True
        assert cfg.import_repos() == None
        assert cfg.import_repos(t=DOCKERREPO) == None
        assert cfg.import_repos(t=NPMREPO) == None

        # no repos
        cfg = BuildConfig()
        cfg._import_repos = {
            COMMONREPO: [],
            DOCKERREPO: [],
            NPMREPO: []
        }
        assert cfg.import_repos() == []
        assert cfg.import_repos(t=DOCKERREPO) == []
        assert cfg.import_repos(t=NPMREPO) == []

        # no repos productive build
        cfg._productive = True
        assert cfg.import_repos() == []
        assert cfg.import_repos(t=DOCKERREPO) == []
        assert cfg.import_repos(t=NPMREPO) == []

        cfg = BuildConfig()
        cfg._import_repos = {
            COMMONREPO: nx_repos,
            DOCKERREPO: docker_repos,
            NPMREPO: npm_repos
        }
        # non productive / non release build
        assert cfg.import_repos() == nx_repos
        assert cfg.import_repos(t=DOCKERREPO) == docker_repos
        assert cfg.import_repos(t=NPMREPO) == npm_repos

        # productive build
        cfg._productive = True
        assert cfg.import_repos() == [nx_repos[0]]
        assert cfg.import_repos(t=DOCKERREPO) == [docker_repos[0]]
        assert cfg.import_repos(t=NPMREPO) == [npm_repos[0]]

        # xmake-ldi release build
        cfg._productive = False
        cfg._release = 'release'
        assert cfg.import_repos() == [nx_repos[0]]
        assert cfg.import_repos(t=DOCKERREPO) == [docker_repos[0]]
        assert cfg.import_repos(t=NPMREPO) == [npm_repos[0]]

        # xmake-dev release build
        cfg._productive = True
        cfg._release = None
        cfg._version_suffix = None
        assert cfg.import_repos() == [nx_repos[0]]
        assert cfg.import_repos(t=DOCKERREPO) == [docker_repos[0]]
        assert cfg.import_repos(t=NPMREPO) == [npm_repos[0]]