def testDel(self):
     """Test to delete a key"""
     o = ScmOverride({ 'del' : [ 'branch' ] })
     self.assertEqual(o.mangle(self.scm), {
         'scm' : "git",
         'url' : "[email protected]:foo/bar.git",
     })
Beispiel #2
0
 def testDel(self):
     """Test to delete a key"""
     o = ScmOverride({'del': ['branch']})
     self.assertEqual(o.mangle(self.scm), {
         'scm': "git",
         'url': "[email protected]:foo/bar.git",
     })
 def testOverwrite(self):
     """Test to overwrite existing key"""
     o = ScmOverride({ 'set' : { 'branch' : "master" } })
     self.assertEqual(o.mangle(self.scm), {
         'scm' : "git",
         'url' : "[email protected]:foo/bar.git",
         'branch' : "master"
     })
Beispiel #4
0
 def testOverwrite(self):
     """Test to overwrite existing key"""
     o = ScmOverride({'set': {'branch': "master"}})
     self.assertEqual(o.mangle(self.scm), {
         'scm': "git",
         'url': "[email protected]:foo/bar.git",
         'branch': "master"
     })
 def testAdd(self):
     """Test to add a new key"""
     o = ScmOverride({ 'set' : { 'commit' : '1234' } })
     self.assertEqual(o.mangle(self.scm), {
         'scm' : "git",
         'url' : "[email protected]:foo/bar.git",
         'branch' : "develop",
         'commit' : "1234"
     })
Beispiel #6
0
 def testAdd(self):
     """Test to add a new key"""
     o = ScmOverride({'set': {'commit': '1234'}})
     self.assertEqual(
         o.mangle(self.scm), {
             'scm': "git",
             'url': "[email protected]:foo/bar.git",
             'branch': "develop",
             'commit': "1234"
         })
Beispiel #7
0
 def testReplaceInvalid(self):
     """Test that invalid regexes are handled gracefully"""
     with self.assertRaises(ParseError):
         o = ScmOverride(
             {'replace': {
                 'url': {
                     'pattern': "*",
                     'replacement': "foo"
                 }
             }})
         o.mangle(self.scm, Env())
 def testMatchGlob(self):
     """Test that matching uses globbing"""
     o = ScmOverride({
         'match' : { 'url' : "*git.com*" },
         'set' : { 'url' : "mirror" }
     })
     self.assertEqual(o.mangle(self.scm), {
         'scm' : "git",
         'url' : "mirror",
         'branch' : "develop"
     })
Beispiel #9
0
 def testReplace(self):
     """Test replacement via regex"""
     o = ScmOverride({
         'replace': {
             'url': {
                 'pattern': "@.*:",
                 'replacement': "@acme.test:"
             }
         }
     })
     self.assertEqual(o.mangle(self.scm), {
         'scm': "git",
         'url': "[email protected]:foo/bar.git",
         'branch': "develop"
     })
Beispiel #10
0
 def testMatchGlob(self):
     """Test that matching uses globbing"""
     o = ScmOverride({
         'match': {
             'url': "*git.com*"
         },
         'set': {
             'url': "mirror"
         }
     })
     self.assertEqual(o.mangle(self.scm), {
         'scm': "git",
         'url': "mirror",
         'branch': "develop"
     })
 def testReplace(self):
     """Test replacement via regex"""
     o = ScmOverride({
         'replace' : {
             'url' : {
                 'pattern'     : "@.*:",
                 'replacement' : "@acme.test:"
             }
         }
     })
     self.assertEqual(o.mangle(self.scm), {
         'scm' : "git",
         'url' : "[email protected]:foo/bar.git",
         'branch' : "develop"
     })
Beispiel #12
0
    def testDel(self):
        """Test to delete a key"""
        o = ScmOverride({ 'del' : [ 'branch' ] })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
        })

        o = ScmOverride({ 'del' : [ "${DEL}" ] })
        e = Env({"DEL" : "branch"})
        match, scm = o.mangle(self.scm, e)
        self.assertEqual(scm, {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
        })
Beispiel #13
0
    def testOverwrite(self):
        """Test to overwrite existing key"""
        o = ScmOverride({ 'set' : { 'branch' : "master" } })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "master"
        })

        # test substitution
        o = ScmOverride({'set' : { 'branch' : "${BRANCH}" } })
        e = Env({"BRANCH" : "master"})
        match, scm = o.mangle(self.scm, e)
        self.assertEqual(scm, {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "master"
        })
    def testMatch(self):
        """Test matching (multiple) keys"""

        # match single key
        o = ScmOverride({
            'match' : { 'branch' : "develop" },
            'set' : { 'branch' : "master" }
        })
        self.assertEqual(o.mangle(self.scm), {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "master"
        })

        # mismatch single key
        o = ScmOverride({
            'match' : { 'branch' : "upstream" },
            'set' : { 'branch' : "master" }
        })
        self.assertEqual(o.mangle(self.scm), {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "develop"
        })

        # match multiple keys
        o = ScmOverride({
            'match' : {
                'branch' : "develop",
                'url' : "[email protected]:foo/bar.git",
            },
            'set' : { 'branch' : "master" }
        })
        self.assertEqual(o.mangle(self.scm), {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "master"
        })

        # mismatch one out of two keys
        o = ScmOverride({
            'match' : {
                'branch' : "develop",
                'url' : "asdfadgag",
            },
            'set' : { 'branch' : "master" }
        })
        self.assertEqual(o.mangle(self.scm), {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "develop"
        })
Beispiel #15
0
 def testAdd(self):
     """Test to add a new key"""
     o = ScmOverride({ 'set' : { 'commit' : '1234' } })
     match, scm = o.mangle(self.scm, Env())
     self.assertEqual(scm, {
         'scm' : "git",
         'url' : "[email protected]:foo/bar.git",
         'branch' : "develop",
         'commit' : "1234"
     }
     )
     o = ScmOverride({ 'set' : { 'commit' : "${COMMIT}" } })
     e = Env({"COMMIT" : "4321"})
     match, scm = o.mangle(self.scm, e)
     self.assertEqual(scm, {
         'scm' : "git",
         'url' : "[email protected]:foo/bar.git",
         'branch' : "develop",
         'commit' : "4321"
     })
Beispiel #16
0
    def testDump(self):
        """Test that a scmOverride correctly converts back to yaml"""
        spec = {
            'match': {
                'url': "*git.com*"
            },
            'set': {
                'url': "mirror",
                "branch": "feature"
            },
            'del': ['tag', 'commit'],
            'replace': {
                "url": {
                    "pattern": "pattern",
                    "replacement": "replacement",
                }
            }
        }

        o = ScmOverride(spec)
        self.assertEqual(spec, yaml.load(str(o)))
    def testDel(self):
        """Test to delete a key"""
        o = ScmOverride({'del': ['branch']})
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
        })

        o = ScmOverride({'del': ["${DEL}"]})
        e = Env({"DEL": "branch"})
        match, scm = o.mangle(self.scm, e)
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
        })
    def testOverwrite(self):
        """Test to overwrite existing key"""
        o = ScmOverride({'set': {'branch': "master"}})
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "master"
        })

        # test substitution
        o = ScmOverride({'set': {'branch': "${BRANCH}"}})
        e = Env({"BRANCH": "master"})
        match, scm = o.mangle(self.scm, e)
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "master"
        })
 def testAdd(self):
     """Test to add a new key"""
     o = ScmOverride({'set': {'commit': '1234'}})
     match, scm = o.mangle(self.scm, Env())
     self.assertEqual(
         scm, {
             'scm': "git",
             'url': "[email protected]:foo/bar.git",
             'branch': "develop",
             'commit': "1234"
         })
     o = ScmOverride({'set': {'commit': "${COMMIT}"}})
     e = Env({"COMMIT": "4321"})
     match, scm = o.mangle(self.scm, e)
     self.assertEqual(
         scm, {
             'scm': "git",
             'url': "[email protected]:foo/bar.git",
             'branch': "develop",
             'commit': "4321"
         })
Beispiel #20
0
    def testReplace(self):
        """Test replacement via regex"""
        o = ScmOverride({
            'replace': {
                'url': {
                    'pattern': "@.*:",
                    'replacement': "@acme.test:"
                }
            }
        })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "develop"
        })

        # test substitiution
        o = ScmOverride({
            'replace': {
                'url': {
                    'pattern': "@${FROM_HOST}:",
                    'replacement': "@${TO_HOST}:"
                }
            }
        })
        match, scm = o.mangle(
            self.scm, Env({
                "FROM_HOST": "git.com",
                "TO_HOST": "acme.test"
            }))
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "develop"
        })
    def testMatch(self):
        """Test matching (multiple) keys"""

        # match single key
        o = ScmOverride({
            'match': {
                'branch': "develop"
            },
            'set': {
                'branch': "master"
            }
        })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "master"
        })

        # mismatch single key
        o = ScmOverride({
            'match': {
                'branch': "upstream"
            },
            'set': {
                'branch': "master"
            }
        })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "develop"
        })

        # match multiple keys
        o = ScmOverride({
            'match': {
                'branch': "develop",
                'url': "[email protected]:foo/bar.git",
            },
            'set': {
                'branch': "master"
            }
        })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "master"
        })

        # mismatch one out of two keys
        o = ScmOverride({
            'match': {
                'branch': "develop",
                'url': "asdfadgag",
            },
            'set': {
                'branch': "master"
            }
        })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "develop"
        })

        # test substitution
        o = ScmOverride({
            'match': {
                'url': "git@${SERVER}:foo/${NAME}.git",
            },
            'set': {
                'branch': "master"
            }
        })
        e = Env({"SERVER": "git.com", "NAME": "bar"})
        match, scm = o.mangle(self.scm, e)
        self.assertEqual(match, True)
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "master"
        })
    def testMatch(self):
        """Test matching (multiple) keys"""

        # match single key
        o = ScmOverride({
            'match': {
                'branch': "develop"
            },
            'set': {
                'branch': "master"
            }
        })
        match, scm = o.mangle(self.scm)
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "master"
        })

        # mismatch single key
        o = ScmOverride({
            'match': {
                'branch': "upstream"
            },
            'set': {
                'branch': "master"
            }
        })
        match, scm = o.mangle(self.scm)
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "develop"
        })

        # match multiple keys
        o = ScmOverride({
            'match': {
                'branch': "develop",
                'url': "[email protected]:foo/bar.git",
            },
            'set': {
                'branch': "master"
            }
        })
        match, scm = o.mangle(self.scm)
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "master"
        })

        # mismatch one out of two keys
        o = ScmOverride({
            'match': {
                'branch': "develop",
                'url': "asdfadgag",
            },
            'set': {
                'branch': "master"
            }
        })
        match, scm = o.mangle(self.scm)
        self.assertEqual(scm, {
            'scm': "git",
            'url': "[email protected]:foo/bar.git",
            'branch': "develop"
        })
Beispiel #23
0
    def testMatch(self):
        """Test matching (multiple) keys"""

        # match single key
        o = ScmOverride({
            'match' : { 'branch' : "develop" },
            'set' : { 'branch' : "master" }
        })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "master"
        })

        # mismatch single key
        o = ScmOverride({
            'match' : { 'branch' : "upstream" },
            'set' : { 'branch' : "master" }
        })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "develop"
        })

        # match multiple keys
        o = ScmOverride({
            'match' : {
                'branch' : "develop",
                'url' : "[email protected]:foo/bar.git",
            },
            'set' : { 'branch' : "master" }
        })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "master"
        })

        # mismatch one out of two keys
        o = ScmOverride({
            'match' : {
                'branch' : "develop",
                'url' : "asdfadgag",
            },
            'set' : { 'branch' : "master" }
        })
        match, scm = o.mangle(self.scm, Env())
        self.assertEqual(scm, {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "develop"
        })

        # test substitution
        o = ScmOverride({'match' : {
                'url' : "git@${SERVER}:foo/${NAME}.git",
            },
            'set' : { 'branch' : "master" }
        })
        e = Env({"SERVER" : "git.com", "NAME" : "bar"})
        match, scm = o.mangle(self.scm, e)
        self.assertEqual(match, True)
        self.assertEqual(scm, {
            'scm' : "git",
            'url' : "[email protected]:foo/bar.git",
            'branch' : "master"
        })