churchyard / centos / centpkg

Forked from centos/centpkg 2 months ago
Clone

Blame tests/test_distgit.py

c0555c
import unittest
b201d4
import unittest.mock
c0555c
4588ec
import git
4588ec
Brian Stinson 02d712
from .mixins import CatchWarningsMixin
c0555c
from centpkg import DistGitDirectory
b201d4
from centpkg import git as centpkg_git
b201d4
c0555c
b9126c
class TestDistGitNothing(unittest.TestCase):
c0555c
    def test_distgit_emptystring(self):
c0555c
        with self.assertRaises(TypeError):
c0555c
            d = DistGitDirectory()
c0555c
6c0f8d
class TestDistGitInvalid(unittest.TestCase):
6c0f8d
    def test_invalid_branchstring_raises(self):
6c0f8d
        self.branchstring = 'nope-not-a-branch'
6c0f8d
6c0f8d
        with self.assertRaises(ValueError):
6c0f8d
            self.d = DistGitDirectory(self.branchstring)
6c0f8d
b9126c
class TestDistgitOnlySig(unittest.TestCase):
b9126c
    def setUp(self):
Brian Stinson 02d712
        self.branchstring = 'c7-sig-cloud'
b9126c
        self.d = DistGitDirectory(self.branchstring)
c0555c
b9126c
    def test_signame_gets_set(self):
b9126c
        self.assertEqual(self.d.signame, 'cloud')
c0555c
b9126c
    def test_centosversion_gets_set(self):
b9126c
        self.assertEqual(self.d.centosversion, '7')
c0555c
b9126c
    def test_projectname_gets_set(self):
b9126c
        self.assertEqual(self.d.projectname, None)
c0555c
b9126c
    def test_releasename_gets_set(self):
b9126c
        self.assertEqual(self.d.releasename, None)
c0555c
47c4aa
    def test_target_gets_set(self):
47c4aa
        self.assertEqual(self.d.target, 'cloud7-common-el7')
47c4aa
3a7531
class TestDistgitSigAndCommon(unittest.TestCase):
3a7531
    def setUp(self):
Brian Stinson 02d712
        self.branchstring = 'c7-sig-cloud-common'
3a7531
        self.d = DistGitDirectory(self.branchstring)
3a7531
3a7531
    def test_signame_gets_set(self):
3a7531
        self.assertEqual(self.d.signame, 'cloud')
3a7531
3a7531
    def test_centosversion_gets_set(self):
3a7531
        self.assertEqual(self.d.centosversion, '7')
3a7531
3a7531
    def test_projectname_gets_set(self):
3a7531
        self.assertEqual(self.d.projectname, None)
3a7531
3a7531
    def test_releasename_gets_set(self):
3a7531
        self.assertEqual(self.d.releasename, None)
3a7531
3a7531
    def test_target_gets_set(self):
3a7531
        self.assertEqual(self.d.target, 'cloud7-common-el7')
3a7531
b9126c
class TestDistgitSigAndProject(unittest.TestCase):
b9126c
    def setUp(self):
Brian Stinson 02d712
        self.branchstring = 'c7-sig-cloud-openstack'
b9126c
        self.d = DistGitDirectory(self.branchstring)
c0555c
b9126c
    def test_signame_gets_set(self):
b9126c
        self.assertEqual(self.d.signame, 'cloud')
b9126c
b9126c
    def test_centosversion_gets_set(self):
b9126c
        self.assertEqual(self.d.centosversion, '7')
b9126c
b9126c
    def test_projectname_gets_set(self):
b9126c
        self.assertEqual(self.d.projectname, 'openstack')
b9126c
b9126c
    def test_releasename_gets_set(self):
b9126c
        self.assertEqual(self.d.releasename, None)
b9126c
f7e2af
    def test_target_gets_set(self):
f7e2af
        self.assertEqual(self.d.target, 'cloud7-openstack-common-el7')
f7e2af
3a7531
class TestDistgitSigProjectAndCommon(unittest.TestCase):
3a7531
    def setUp(self):
Brian Stinson 02d712
        self.branchstring = 'c7-sig-cloud-openstack-common'
3a7531
        self.d = DistGitDirectory(self.branchstring)
3a7531
3a7531
    def test_signame_gets_set(self):
3a7531
        self.assertEqual(self.d.signame, 'cloud')
3a7531
3a7531
    def test_centosversion_gets_set(self):
3a7531
        self.assertEqual(self.d.centosversion, '7')
3a7531
3a7531
    def test_projectname_gets_set(self):
3a7531
        self.assertEqual(self.d.projectname, 'openstack')
3a7531
3a7531
    def test_releasename_gets_set(self):
3a7531
        self.assertEqual(self.d.releasename, None)
3a7531
3a7531
    def test_target_gets_set(self):
3a7531
        self.assertEqual(self.d.target, 'cloud7-openstack-common-el7')
3a7531
b9126c
class TestDistgitSigProjectAndRelease(unittest.TestCase):
b9126c
    def setUp(self):
Brian Stinson 02d712
        self.branchstring = 'c7-sig-cloud-openstack-kilo'
b9126c
        self.d = DistGitDirectory(self.branchstring)
b9126c
b9126c
    def test_signame_gets_set(self):
b9126c
        self.assertEqual(self.d.signame, 'cloud')
b9126c
b9126c
    def test_centosversion_gets_set(self):
b9126c
        self.assertEqual(self.d.centosversion, '7')
b9126c
b9126c
    def test_projectname_gets_set(self):
b9126c
        self.assertEqual(self.d.projectname, 'openstack')
b9126c
b9126c
    def test_releasename_gets_set(self):
b9126c
        self.assertEqual(self.d.releasename, 'kilo')
c8beba
c8beba
    def test_target_gets_set(self):
c8beba
        self.assertEqual(self.d.target, 'cloud7-openstack-kilo-el7')
c8beba
a6e9d6
class TestDistgitC7DistroBranch(unittest.TestCase):
a6e9d6
    def setUp(self):
a6e9d6
        self.branchstring = 'c7'
a6e9d6
        self.d = DistGitDirectory(self.branchstring)
a6e9d6
a6e9d6
    def test_signame_gets_set(self):
a6e9d6
        self.assertEqual(self.d.signame, 'centos')
a6e9d6
a6e9d6
    def test_centosversion_gets_set(self):
a6e9d6
        self.assertEqual(self.d.centosversion, '7')
a6e9d6
a6e9d6
    def test_projectname_gets_set(self):
a6e9d6
        self.assertEqual(self.d.projectname, None)
a6e9d6
a6e9d6
    def test_releasename_gets_set(self):
a6e9d6
        self.assertEqual(self.d.releasename, None)
a6e9d6
a6e9d6
    def test_target_gets_set(self):
a6e9d6
        self.assertEqual(self.d.target, 'c7')
a6e9d6
bb525a
class TestDistgitStream9Module(unittest.TestCase):
bb525a
    def setUp(self):
bb525a
        self.branchstring = '3.0-rhel-9.0.0-beta'
bb525a
        self.d = DistGitDirectory(self.branchstring)
bb525a
bb525a
    def test_signame_gets_set(self):
bb525a
        self.assertEqual(self.d.signame, 'centos')
bb525a
bb525a
    def test_centosversion_gets_set(self):
bb525a
        self.assertEqual(self.d.centosversion, '9')
bb525a
bb525a
    def test_projectname_gets_set(self):
bb525a
        self.assertEqual(self.d.projectname, None)
bb525a
bb525a
    def test_releasename_gets_set(self):
bb525a
        self.assertEqual(self.d.releasename, None)
bb525a
bb525a
    def test_target_gets_set(self):
bb525a
        self.assertEqual(self.d.target, 'c9s-candidate')
bb525a
bb525a
class TestDistgitStream9ModuleComponent(unittest.TestCase):
bb525a
    def setUp(self):
bb525a
        self.branchstring = 'stream-container-tools-3.0-rhel-9.0.0-beta'
bb525a
        self.d = DistGitDirectory(self.branchstring)
bb525a
bb525a
    def test_signame_gets_set(self):
bb525a
        self.assertEqual(self.d.signame, 'centos')
bb525a
bb525a
    def test_centosversion_gets_set(self):
bb525a
        self.assertEqual(self.d.centosversion, '9')
bb525a
bb525a
    def test_projectname_gets_set(self):
bb525a
        self.assertEqual(self.d.projectname, None)
bb525a
bb525a
    def test_releasename_gets_set(self):
bb525a
        self.assertEqual(self.d.releasename, None)
bb525a
bb525a
    def test_target_gets_set(self):
bb525a
        self.assertEqual(self.d.target, 'c9s-candidate')
bb525a
a6e9d6
class TestDistgitC6DistroBranch(unittest.TestCase):
a6e9d6
    def setUp(self):
a6e9d6
        self.branchstring = 'c6'
a6e9d6
        self.d = DistGitDirectory(self.branchstring)
a6e9d6
a6e9d6
    def test_signame_gets_set(self):
a6e9d6
        self.assertEqual(self.d.signame, 'centos')
a6e9d6
a6e9d6
    def test_centosversion_gets_set(self):
a6e9d6
        self.assertEqual(self.d.centosversion, '6')
a6e9d6
a6e9d6
    def test_projectname_gets_set(self):
a6e9d6
        self.assertEqual(self.d.projectname, None)
a6e9d6
a6e9d6
    def test_releasename_gets_set(self):
a6e9d6
        self.assertEqual(self.d.releasename, None)
a6e9d6
a6e9d6
    def test_target_gets_set(self):
a6e9d6
        self.assertEqual(self.d.target, 'c6')
867964
867964
class TestDistgitC6PlusDistroBranch(unittest.TestCase):
867964
    def setUp(self):
867964
        self.branchstring = 'c6-plus'
867964
        self.d = DistGitDirectory(self.branchstring)
867964
867964
    def test_signame_gets_set(self):
867964
        self.assertEqual(self.d.signame, 'centos')
867964
867964
    def test_centosversion_gets_set(self):
867964
        self.assertEqual(self.d.centosversion, '6')
867964
867964
    def test_projectname_gets_set(self):
867964
        self.assertEqual(self.d.projectname, 'plus')
867964
867964
    def test_releasename_gets_set(self):
867964
        self.assertEqual(self.d.releasename, None)
867964
867964
    def test_target_gets_set(self):
867964
        self.assertEqual(self.d.target, 'c6-plus')
cf167f
cf167f
class TestOldGitBranch(unittest.TestCase, CatchWarningsMixin):
cf167f
    def test_old_branch_warns(self):
cf167f
       with self.assertWarns(DeprecationWarning):
cf167f
           branchstring = 'virt7'
cf167f
           d = DistGitDirectory(branchstring)
b201d4
b201d4
class TestIsFork(unittest.TestCase):
b201d4
    def setUp(self):
b201d4
        self.branchstring = 'c9s'
b201d4
b201d4
    def test_none(self):
b201d4
        d = DistGitDirectory(self.branchstring)
b201d4
        self.assertFalse(d.is_fork())
b201d4
4588ec
    @unittest.mock.patch.object(centpkg_git.repo.Repo, 'remotes', new=dict(origin=type('Remote', (object,), {'urls': ['ssh://git@git.centos.org/forks/lrossett/centos/centpkg.git']})))
4588ec
    @unittest.mock.patch.object(centpkg_git.repo.Repo, '__init__', new=lambda s, p: None)
b201d4
    def test_fork_url(self):
b201d4
        d = DistGitDirectory(self.branchstring, 'binutils')
b201d4
        self.assertTrue(d.is_fork())
4588ec
    
4588ec
    @unittest.mock.patch.object(centpkg_git.repo.Repo, 'remotes', new=dict(origin=type('Remote', (object,), {'urls': ['git+ssh://git@gitlab.com/redhat/centos-stream/rpms/binutils.git']})))
4588ec
    @unittest.mock.patch.object(centpkg_git.repo.Repo, '__init__', new=lambda s, p: None)
b201d4
    def test_upstream_url(self):
b201d4
        d = DistGitDirectory(self.branchstring, 'binutils')
b201d4
        self.assertFalse(d.is_fork())