Esempio n. 1
0
    def test_add_tag_with_message_from_file(self):
        self.make_new_git(self.module)

        tag = 'v1.0'
        message = 'This is a release'

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir
        self.config_repo(cmd.path)

        message_file = os.path.join(moduledir, 'tag_message')

        with open(message_file, 'w') as f:
            f.write(message)

        cmd.add_tag(tag, file=message_file)

        self.assertEqual(self.get_tags(moduledir), [[tag, message]])
Esempio n. 2
0
    def test_clone_anonymous_with_namespace(self):
        self.module = 'rpms/module1'
        self.make_new_git(self.module)

        import pyrpkg
        cmd = pyrpkg.Commands(self.path,
                              self.lookaside,
                              self.lookasidehash,
                              self.lookaside_cgi,
                              self.gitbaseurl,
                              self.anongiturl,
                              self.branchre,
                              self.kojiprofile,
                              self.build_client,
                              self.user,
                              self.dist,
                              self.target,
                              self.quiet,
                              distgit_namespaced=True)
        cmd.clone_config = CLONE_CONFIG
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, 'module1')
        self.assertTrue(os.path.isdir(os.path.join(moduledir, '.git')))
        confgit = git.Git(moduledir)
        self.assertEqual(confgit.config('bz.default-component'), self.module)
        self.assertEqual(confgit.config('sendemail.to'),
                         "*****@*****.**" % self.module)
Esempio n. 3
0
    def test_add_tag(self):
        self.make_new_git(self.module)

        tag = 'v1.0'
        message = 'This is a release'

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir
        self.config_repo(cmd.path)

        # `git tag` will call $EDITOR to ask the user to write a message
        os.environ['GIT_EDITOR'] = ('/usr/bin/python -c "import sys; '
                                    'open(sys.argv[1], \'w\').write(\'%s\')"' %
                                    message)

        cmd.add_tag(tag)

        self.assertEqual(self.get_tags(moduledir), [[tag, message]])
Esempio n. 4
0
    def test_add_tag_force_replace_existing(self):
        self.make_new_git(self.module)

        tag = 'v1.0'
        message = 'This is a release'

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir
        self.config_repo(cmd.path)

        cmd.add_tag(tag, message=message)

        # Now add the same tag again by force
        newmessage = 'No, THIS is a release'
        cmd.add_tag(tag, message=newmessage, force=True)

        self.assertEqual(self.get_tags(moduledir), [[tag, newmessage]])
Esempio n. 5
0
    def test_push_outside_repo(self):
        """push from outside repo with --path option"""

        self.make_new_git(self.module)

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone_config = CLONE_CONFIG
        cmd.clone(self.module, anon=True)
        cmd.path = os.path.join(self.path, self.module)
        os.chdir(os.path.join(self.path, self.module))

        spec_file = 'module.spec'
        with open(spec_file, 'w') as f:
            f.write(SPECFILE_TEMPLATE % '')

        cmd.repo.index.add([spec_file])
        cmd.repo.index.commit("add SPEC")

        # Now, change directory to parent and test the push
        os.chdir(self.path)
        cmd.push()
Esempio n. 6
0
    def test_clone_into_dir_with_namespace(self):
        self.module = 'rpms/module1'
        self.make_new_git(self.module,
                          branches=['rpkg-tests-1', 'rpkg-tests-2'])

        import pyrpkg
        cmd = pyrpkg.Commands(self.path,
                              self.lookaside,
                              self.lookasidehash,
                              self.lookaside_cgi,
                              self.gitbaseurl,
                              self.anongiturl,
                              self.branchre,
                              self.kojiprofile,
                              self.build_client,
                              self.user,
                              self.dist,
                              self.target,
                              self.quiet,
                              distgit_namespaced=True)
        cmd.clone(self.module,
                  anon=True,
                  branch='rpkg-tests-1',
                  target='new_clone')

        with open(os.path.join(self.path, 'new_clone', '.git',
                               'HEAD')) as HEAD:
            self.assertEqual(HEAD.read(), 'ref: refs/heads/rpkg-tests-1\n')
Esempio n. 7
0
    def test_delete_tag(self):
        self.make_new_git(self.module)

        tag = 'v1.0'
        message = 'This is a release'

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir
        self.config_repo(cmd.path)

        # First, add a tag
        cmd.add_tag(tag, message=message)
        self.assertEqual(self.get_tags(moduledir), [[tag, message]])

        # Now delete it
        cmd.delete_tag(tag)
        tags = [t for (t, m) in self.get_tags(moduledir)]
        self.assertFalse(tag in tags)
Esempio n. 8
0
    def test_list_tag_inexistent(self):
        self.make_new_git(self.module)

        tags = [['v1.0', 'This is a release'],
                ['v2.0', 'This is another release']]

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir
        self.config_repo(cmd.path)

        for tag, message in tags:
            cmd.add_tag(tag, message=message)

        with self.hijack_stdout() as out:
            cmd.list_tag(tagname='v1.1')

        result = out.read().strip().split('\n')

        self.assertEqual(result, [''])
Esempio n. 9
0
    def test_add_tag_fails_with_existing(self):
        self.make_new_git(self.module)

        tag = 'v1.0'
        message = 'This is a release'

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir
        self.config_repo(cmd.path)

        cmd.add_tag(tag, message=message)

        # Now add the same tag again
        def raises():
            cmd.add_tag(tag, message='No, THIS is a release')

        self.assertRaises(pyrpkg.rpkgError, raises)
Esempio n. 10
0
 def test_byte_offset_first_line(self):
     import pyrpkg
     cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                           self.lookaside_cgi, self.gitbaseurl,
                           self.anongiturl, self.branchre, self.kojiprofile,
                           self.build_client, self.user, self.dist,
                           self.target, self.quiet)
     line, offset = cmd._byte_offset_to_line_number(self.text_ascii, 10)
     # 10 byte offset mean line 1 and character 11
     self.assertEqual(line, 1)
     self.assertEqual(offset, 11)
Esempio n. 11
0
 def test_byte_offset_utf8(self):
     import pyrpkg
     cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                           self.lookaside_cgi, self.gitbaseurl,
                           self.anongiturl, self.branchre, self.kojiprofile,
                           self.build_client, self.user, self.dist,
                           self.target, self.quiet)
     text = self.text_utf8.decode('UTF-8', 'ignore')
     line, offset = cmd._byte_offset_to_line_number(text, 9)
     # 9 byte offset mean line 3 and second character
     self.assertEqual(line, 3)
     self.assertEqual(offset, 2)
Esempio n. 12
0
    def test_byte_offset_next_line(self):
        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)

        line, offset = cmd._byte_offset_to_line_number(self.text_ascii, 46)
        # 46 byte offset is first character on second line
        self.assertEqual(line, 2)
        self.assertEqual(offset, 1)
Esempio n. 13
0
    def test_clone_anonymous_with_bare_dir(self):
        self.make_new_git(self.module)

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True, bare_dir='%s.git' % self.module)

        clonedir = os.path.join(self.path, '%s.git' % self.module)
        self.assertTrue(os.path.isdir(clonedir))
        self.assertFalse(os.path.exists(os.path.join(clonedir, 'index')))
Esempio n. 14
0
    def test_name_is_not_unicode(self):
        self.make_new_git(self.module)

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir

        self.assertNotEqual(type(cmd.module_name), six.binary_type)
        self.assertEqual(type(cmd.module_name), six.text_type)
Esempio n. 15
0
    def test_clone_fails_with_both_branch_and_bare_dir(self):
        self.make_new_git(self.module,
                          branches=['rpkg-tests-1', 'rpkg-tests-2'])

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)

        def raises():
            cmd.clone(self.module,
                      anon=True,
                      branch='rpkg-tests-1',
                      bare_dir='test.git')

        self.assertRaises(pyrpkg.rpkgError, raises)
Esempio n. 16
0
    def test_list_tag_no_tags(self):
        self.make_new_git(self.module)

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir
        self.config_repo(cmd.path)

        with self.hijack_stdout() as out:
            cmd.list_tag()

        self.assertEqual(out.read().strip(), '')
Esempio n. 17
0
    def test_clone_anonymous_with_path(self):
        self.make_new_git(self.module)

        altpath = tempfile.mkdtemp(prefix='rpkg-tests.')

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True, path=altpath)

        moduledir = os.path.join(altpath, self.module)
        self.assertTrue(os.path.isdir(os.path.join(moduledir, '.git')))

        notmoduledir = os.path.join(self.path, self.module)
        self.assertFalse(os.path.isdir(os.path.join(notmoduledir, '.git')))

        shutil.rmtree(altpath)
Esempio n. 18
0
    def test_delete_tag_fails_inexistent(self):
        self.make_new_git(self.module)

        tag = 'v1.0'

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir
        self.config_repo(cmd.path)

        # Try deleting an inexistent tag
        def raises():
            cmd.delete_tag(tag)
        self.assertRaises(pyrpkg.rpkgError, raises)
Esempio n. 19
0
    def setUp(self):
        super(TestPushWithPatches, self).setUp()

        self.make_new_git(self.module)

        import pyrpkg
        self.cmd = pyrpkg.Commands(self.path, self.lookaside,
                                   self.lookasidehash, self.lookaside_cgi,
                                   self.gitbaseurl, self.anongiturl,
                                   self.branchre, self.kojiprofile,
                                   self.build_client, self.user, self.dist,
                                   self.target, self.quiet)
        self.cmd.clone_config = CLONE_CONFIG
        self.cmd.clone(self.module, anon=True)
        self.cmd.path = os.path.join(self.path, self.module)
        os.chdir(os.path.join(self.path, self.module))

        # Track SPEC and a.patch in git
        spec_file = 'module.spec'
        with open(spec_file, 'w') as f:
            f.write(SPECFILE_TEMPLATE % '''Patch0: a.patch
Patch1: b.path
Patch2: c.path
Patch3: d.path
''')

        for patch_file in ('a.patch', 'b.patch', 'c.patch', 'd.patch'):
            with open(patch_file, 'w') as f:
                f.write(patch_file)

        # Track c.patch in sources
        from pyrpkg.sources import SourcesFile
        sources_file = SourcesFile(self.cmd.sources_filename,
                                   self.cmd.source_entry_type)
        file_hash = self.cmd.lookasidecache.hash_file('c.patch')
        sources_file.add_entry(self.cmd.lookasidehash, 'c.patch', file_hash)
        sources_file.write()

        self.cmd.repo.index.add([spec_file, 'a.patch', 'sources'])
        self.cmd.repo.index.commit('add SPEC and patches')
Esempio n. 20
0
    def test_add_tag_many(self):
        self.make_new_git(self.module)

        tags = [['v1.0', 'This is a release'],
                ['v2.0', 'This is another release']]

        import pyrpkg
        cmd = pyrpkg.Commands(self.path, self.lookaside, self.lookasidehash,
                              self.lookaside_cgi, self.gitbaseurl,
                              self.anongiturl, self.branchre, self.kojiprofile,
                              self.build_client, self.user, self.dist,
                              self.target, self.quiet)
        cmd.clone(self.module, anon=True)

        moduledir = os.path.join(self.path, self.module)
        cmd.path = moduledir
        self.config_repo(cmd.path)

        for tag, message in tags:
            cmd.add_tag(tag, message=message)

        self.assertEqual(self.get_tags(moduledir), tags)