|
farhaanbukhsh |
1df65f |
# -*- coding: utf-8 -*-
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
farhaanbukhsh |
1df65f |
import pkg_resources
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
60d445 |
import datetime
|
|
farhaanbukhsh |
1df65f |
import unittest
|
|
farhaanbukhsh |
1df65f |
import shutil
|
|
farhaanbukhsh |
1df65f |
import sys
|
|
farhaanbukhsh |
c4f329 |
import tempfile
|
|
farhaanbukhsh |
1df65f |
import os
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
import json
|
|
farhaanbukhsh |
c4f329 |
import pygit2
|
|
farhaanbukhsh |
1df65f |
from mock import patch
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
farhaanbukhsh |
1df65f |
os.path.abspath(__file__)), '..'))
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
import pagure.lib
|
|
farhaanbukhsh |
1df65f |
import tests
|
|
farhaanbukhsh |
c4f329 |
from pagure.lib.repo import PagureRepo
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
class PagurePrivateRepotest(tests.Modeltests):
|
|
farhaanbukhsh |
1df65f |
""" Tests for private repo in pagure """
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
def setUp(self):
|
|
farhaanbukhsh |
1df65f |
""" Set up the environnment, ran before every tests. """
|
|
farhaanbukhsh |
1df65f |
super(PagurePrivateRepotest, self).setUp()
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
4858f8 |
pagure.APP.config['TESTING'] = True
|
|
farhaanbukhsh |
4858f8 |
pagure.SESSION = self.session
|
|
farhaanbukhsh |
4858f8 |
pagure.lib.SESSION = self.session
|
|
farhaanbukhsh |
4858f8 |
pagure.ui.SESSION = self.session
|
|
farhaanbukhsh |
1df65f |
pagure.ui.app.SESSION = self.session
|
|
farhaanbukhsh |
1df65f |
pagure.ui.filters.SESSION = self.session
|
|
farhaanbukhsh |
4858f8 |
pagure.ui.fork.SESSION = self.session
|
|
farhaanbukhsh |
1df65f |
pagure.ui.repo.SESSION = self.session
|
|
farhaanbukhsh |
4858f8 |
pagure.ui.issues.SESSION = self.session
|
|
farhaanbukhsh |
60d445 |
pagure.api.SESSION = self.session
|
|
farhaanbukhsh |
60d445 |
pagure.api.project.SESSION = self.session
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
4858f8 |
pagure.APP.config['GIT_FOLDER'] = os.path.join(tests.HERE, 'repos')
|
|
farhaanbukhsh |
1df65f |
pagure.APP.config['FORK_FOLDER'] = os.path.join(
|
|
farhaanbukhsh |
1df65f |
tests.HERE, 'forks')
|
|
farhaanbukhsh |
1df65f |
pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
farhaanbukhsh |
1df65f |
tests.HERE, 'tickets')
|
|
farhaanbukhsh |
1df65f |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
farhaanbukhsh |
1df65f |
tests.HERE, 'docs')
|
|
farhaanbukhsh |
1df65f |
pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
|
|
farhaanbukhsh |
1df65f |
tests.HERE, 'requests')
|
|
farhaanbukhsh |
1df65f |
self.app = pagure.APP.test_client()
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
c4f329 |
def set_up_git_repo(
|
|
farhaanbukhsh |
c4f329 |
self, new_project=None, branch_from='feature', mtype='FF'):
|
|
farhaanbukhsh |
c4f329 |
""" Set up the git repo and create the corresponding PullRequest
|
|
farhaanbukhsh |
c4f329 |
object.
|
|
farhaanbukhsh |
c4f329 |
"""
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Create a git repo to play with
|
|
farhaanbukhsh |
4ea512 |
gitrepo = os.path.join(tests.HERE, 'repos', 'pmc.git')
|
|
farhaanbukhsh |
c4f329 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
4ea512 |
newpath = tempfile.mkdtemp(prefix='pagure-private-test')
|
|
farhaanbukhsh |
4858f8 |
repopath = os.path.join(newpath, 'test')
|
|
farhaanbukhsh |
c4f329 |
clone_repo = pygit2.clone_repository(gitrepo, repopath)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Create a file in that git repo
|
|
farhaanbukhsh |
c4f329 |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
farhaanbukhsh |
c4f329 |
stream.write('foo\n bar')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.add('sources')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.write()
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Commits the files added
|
|
farhaanbukhsh |
c4f329 |
tree = clone_repo.index.write_tree()
|
|
farhaanbukhsh |
c4f329 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Alice Author', 'alice@authors.tld')
|
|
farhaanbukhsh |
c4f329 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Cecil Committer', 'cecil@committers.tld')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.create_commit(
|
|
farhaanbukhsh |
c4f329 |
'refs/heads/master', # the name of the reference to update
|
|
farhaanbukhsh |
c4f329 |
author,
|
|
farhaanbukhsh |
c4f329 |
committer,
|
|
farhaanbukhsh |
c4f329 |
'Add sources file for testing',
|
|
farhaanbukhsh |
c4f329 |
# binary string representing the tree object ID
|
|
farhaanbukhsh |
c4f329 |
tree,
|
|
farhaanbukhsh |
c4f329 |
# list of binary strings representing parents of the new commit
|
|
farhaanbukhsh |
c4f329 |
[]
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
refname = 'refs/heads/master:refs/heads/master'
|
|
farhaanbukhsh |
c4f329 |
ori_remote = clone_repo.remotes[0]
|
|
farhaanbukhsh |
c4f329 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
first_commit = repo.revparse_single('HEAD')
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
if mtype == 'merge':
|
|
farhaanbukhsh |
c4f329 |
with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
|
|
farhaanbukhsh |
c4f329 |
stream.write('*~')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.add('.gitignore')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.write()
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Commits the files added
|
|
farhaanbukhsh |
c4f329 |
tree = clone_repo.index.write_tree()
|
|
farhaanbukhsh |
c4f329 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Alice Äuthòr', 'alice@äuthòrs.tld')
|
|
farhaanbukhsh |
c4f329 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Cecil Cõmmîttër', 'cecil@cõmmîttërs.tld')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.create_commit(
|
|
farhaanbukhsh |
c4f329 |
'refs/heads/master',
|
|
farhaanbukhsh |
c4f329 |
author,
|
|
farhaanbukhsh |
c4f329 |
committer,
|
|
farhaanbukhsh |
c4f329 |
'Add .gitignore file for testing',
|
|
farhaanbukhsh |
c4f329 |
# binary string representing the tree object ID
|
|
farhaanbukhsh |
c4f329 |
tree,
|
|
farhaanbukhsh |
c4f329 |
# list of binary strings representing parents of the new commit
|
|
farhaanbukhsh |
c4f329 |
[first_commit.oid.hex]
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
refname = 'refs/heads/master:refs/heads/master'
|
|
farhaanbukhsh |
c4f329 |
ori_remote = clone_repo.remotes[0]
|
|
farhaanbukhsh |
c4f329 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
if mtype == 'conflicts':
|
|
farhaanbukhsh |
c4f329 |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
farhaanbukhsh |
c4f329 |
stream.write('foo\n bar\nbaz')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.add('sources')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.write()
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Commits the files added
|
|
farhaanbukhsh |
c4f329 |
tree = clone_repo.index.write_tree()
|
|
farhaanbukhsh |
c4f329 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Alice Author', 'alice@authors.tld')
|
|
farhaanbukhsh |
c4f329 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Cecil Committer', 'cecil@committers.tld')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.create_commit(
|
|
farhaanbukhsh |
c4f329 |
'refs/heads/master',
|
|
farhaanbukhsh |
c4f329 |
author,
|
|
farhaanbukhsh |
c4f329 |
committer,
|
|
farhaanbukhsh |
c4f329 |
'Add sources conflicting',
|
|
farhaanbukhsh |
c4f329 |
# binary string representing the tree object ID
|
|
farhaanbukhsh |
c4f329 |
tree,
|
|
farhaanbukhsh |
c4f329 |
# list of binary strings representing parents of the new commit
|
|
farhaanbukhsh |
c4f329 |
[first_commit.oid.hex]
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
refname = 'refs/heads/master:refs/heads/master'
|
|
farhaanbukhsh |
c4f329 |
ori_remote = clone_repo.remotes[0]
|
|
farhaanbukhsh |
c4f329 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Set the second repo
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
new_gitrepo = repopath
|
|
farhaanbukhsh |
c4f329 |
if new_project:
|
|
farhaanbukhsh |
c4f329 |
# Create a new git repo to play with
|
|
farhaanbukhsh |
c4f329 |
new_gitrepo = os.path.join(newpath, new_project.fullname)
|
|
farhaanbukhsh |
c4f329 |
if not os.path.exists(new_gitrepo):
|
|
farhaanbukhsh |
c4f329 |
os.makedirs(new_gitrepo)
|
|
farhaanbukhsh |
c4f329 |
new_repo = pygit2.clone_repository(gitrepo, new_gitrepo)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
repo = pygit2.Repository(new_gitrepo)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
if mtype != 'nochanges':
|
|
farhaanbukhsh |
c4f329 |
# Edit the sources file again
|
|
farhaanbukhsh |
c4f329 |
with open(os.path.join(new_gitrepo, 'sources'), 'w') as stream:
|
|
farhaanbukhsh |
c4f329 |
stream.write('foo\n bar\nbaz\n boose')
|
|
farhaanbukhsh |
c4f329 |
repo.index.add('sources')
|
|
farhaanbukhsh |
c4f329 |
repo.index.write()
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Commits the files added
|
|
farhaanbukhsh |
c4f329 |
tree = repo.index.write_tree()
|
|
farhaanbukhsh |
c4f329 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Alice Author', 'alice@authors.tld')
|
|
farhaanbukhsh |
c4f329 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Cecil Committer', 'cecil@committers.tld')
|
|
farhaanbukhsh |
c4f329 |
repo.create_commit(
|
|
farhaanbukhsh |
c4f329 |
'refs/heads/%s' % branch_from,
|
|
farhaanbukhsh |
c4f329 |
author,
|
|
farhaanbukhsh |
c4f329 |
committer,
|
|
farhaanbukhsh |
c4f329 |
'A commit on branch %s' % branch_from,
|
|
farhaanbukhsh |
c4f329 |
tree,
|
|
farhaanbukhsh |
c4f329 |
[first_commit.oid.hex]
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
refname = 'refs/heads/%s' % (branch_from)
|
|
farhaanbukhsh |
c4f329 |
ori_remote = repo.remotes[0]
|
|
farhaanbukhsh |
c4f329 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Create a PR for these changes
|
|
farhaanbukhsh |
c4f329 |
project = pagure.lib.get_project(self.session, 'pmc')
|
|
farhaanbukhsh |
c4f329 |
req = pagure.lib.new_pull_request(
|
|
farhaanbukhsh |
c4f329 |
session=self.session,
|
|
farhaanbukhsh |
c4f329 |
repo_from=project,
|
|
farhaanbukhsh |
c4f329 |
branch_from=branch_from,
|
|
farhaanbukhsh |
c4f329 |
repo_to=project,
|
|
farhaanbukhsh |
c4f329 |
branch_to='master',
|
|
farhaanbukhsh |
c4f329 |
title='PR from the %s branch' % branch_from,
|
|
farhaanbukhsh |
c4f329 |
user='pingou',
|
|
farhaanbukhsh |
c4f329 |
requestfolder=None,
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
self.session.commit()
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(req.id, 1)
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(req.title, 'PR from the %s branch' % branch_from)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
shutil.rmtree(newpath)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
1df65f |
def test_index(self):
|
|
farhaanbukhsh |
1df65f |
""" Test the index endpoint. """
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
output = self.app.get('/')
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'All Projects '
|
|
farhaanbukhsh |
1df65f |
'0', output.data)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
tests.create_projects(self.session)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
# Add a private project
|
|
farhaanbukhsh |
1df65f |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
1df65f |
user_id=2, # foo
|
|
farhaanbukhsh |
1df65f |
name='test3',
|
|
farhaanbukhsh |
1df65f |
description='test project description',
|
|
farhaanbukhsh |
1df65f |
hook_token='aaabbbeee',
|
|
farhaanbukhsh |
1df65f |
private=True,
|
|
farhaanbukhsh |
1df65f |
)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.session.add(item)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
# Add a public project
|
|
farhaanbukhsh |
1df65f |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
1df65f |
user_id=2, # foo
|
|
farhaanbukhsh |
1df65f |
name='test4',
|
|
farhaanbukhsh |
1df65f |
description='test project description',
|
|
farhaanbukhsh |
1df65f |
hook_token='aaabbbeeeccceee',
|
|
farhaanbukhsh |
1df65f |
)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.session.add(item)
|
|
farhaanbukhsh |
1df65f |
self.session.commit()
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
output = self.app.get('/?page=abc')
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'All Projects '
|
|
farhaanbukhsh |
1df65f |
'3', output.data)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
user = tests.FakeUser(username='foo')
|
|
farhaanbukhsh |
1df65f |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
3604c1 |
output = self.app.get('/')
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
3604c1 |
'My Projects 2',
|
|
farhaanbukhsh |
1df65f |
output.data)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'Forks 0',
|
|
farhaanbukhsh |
1df65f |
output.data)
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(
|
|
farhaanbukhsh |
1df65f |
output.data.count('No group found '), 1)
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(
|
|
farhaanbukhsh |
1df65f |
output.data.count('
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
def test_view_user(self):
|
|
farhaanbukhsh |
1df65f |
""" Test the view_user endpoint. """
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
output = self.app.get('/user/foo?repopage=abc&forkpage=def')
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'Projects 0',
|
|
farhaanbukhsh |
1df65f |
output.data)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'Forks 0',
|
|
farhaanbukhsh |
1df65f |
output.data)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
# Add a private project
|
|
farhaanbukhsh |
1df65f |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
1df65f |
user_id=2, # foo
|
|
farhaanbukhsh |
1df65f |
name='test3',
|
|
farhaanbukhsh |
1df65f |
description='test project description',
|
|
farhaanbukhsh |
1df65f |
hook_token='aaabbbeee',
|
|
farhaanbukhsh |
1df65f |
private=True,
|
|
farhaanbukhsh |
1df65f |
)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.session.add(item)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
# Add a public project
|
|
farhaanbukhsh |
1df65f |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
1df65f |
user_id=2, # foo
|
|
farhaanbukhsh |
1df65f |
name='test4',
|
|
farhaanbukhsh |
1df65f |
description='test project description',
|
|
farhaanbukhsh |
1df65f |
hook_token='aaabbbeeeccceee',
|
|
farhaanbukhsh |
1df65f |
)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.session.add(item)
|
|
farhaanbukhsh |
1df65f |
self.session.commit()
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.gitrepos = tests.create_projects_git(
|
|
farhaanbukhsh |
1df65f |
pagure.APP.config['GIT_FOLDER'])
|
|
farhaanbukhsh |
1df65f |
|
|
Pierre-Yves Chibon |
3604c1 |
output = self.app.get('/user/foo')
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'Projects 1',
|
|
farhaanbukhsh |
1df65f |
output.data)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'Forks 0', output.data)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
user = tests.FakeUser(username='foo')
|
|
farhaanbukhsh |
1df65f |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
3604c1 |
output = self.app.get('/user/foo')
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'Projects 2',
|
|
farhaanbukhsh |
1df65f |
output.data)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'Forks 0',
|
|
farhaanbukhsh |
1df65f |
output.data)
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(
|
|
farhaanbukhsh |
1df65f |
output.data.count('No group found '), 1)
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(
|
|
farhaanbukhsh |
1df65f |
output.data.count('
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
b909de |
user.username = 'pingou'
|
|
farhaanbukhsh |
1df65f |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
3604c1 |
output = self.app.get('/user/foo')
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'Projects 1',
|
|
farhaanbukhsh |
1df65f |
output.data)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
farhaanbukhsh |
1df65f |
'Forks 0',
|
|
farhaanbukhsh |
1df65f |
output.data)
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(
|
|
farhaanbukhsh |
1df65f |
output.data.count('No group found '), 1)
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(
|
|
farhaanbukhsh |
1df65f |
output.data.count('
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
b6711e |
repo = pagure.lib.get_project(self.session, 'test3')
|
|
farhaanbukhsh |
b909de |
|
|
farhaanbukhsh |
b909de |
msg = pagure.lib.add_user_to_project(
|
|
farhaanbukhsh |
b6711e |
session=self.session,
|
|
farhaanbukhsh |
b6711e |
project=repo,
|
|
farhaanbukhsh |
b6711e |
new_user='pingou',
|
|
farhaanbukhsh |
b6711e |
user='foo',
|
|
farhaanbukhsh |
b6711e |
)
|
|
farhaanbukhsh |
b909de |
self.assertEqual(msg, 'User added')
|
|
farhaanbukhsh |
b6711e |
|
|
farhaanbukhsh |
b6711e |
# New user added to private projects
|
|
farhaanbukhsh |
b909de |
user.username = 'pingou'
|
|
farhaanbukhsh |
b6711e |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
b6711e |
output = self.app.get('/')
|
|
farhaanbukhsh |
b6711e |
self.assertIn(
|
|
farhaanbukhsh |
b6711e |
'My Projects 1',
|
|
farhaanbukhsh |
b6711e |
output.data)
|
|
farhaanbukhsh |
b6711e |
self.assertIn(
|
|
farhaanbukhsh |
b6711e |
'Forks 0',
|
|
farhaanbukhsh |
b6711e |
output.data)
|
|
farhaanbukhsh |
b6711e |
self.assertEqual(
|
|
farhaanbukhsh |
b6711e |
output.data.count('No group found '), 1)
|
|
farhaanbukhsh |
b6711e |
self.assertEqual(
|
|
farhaanbukhsh |
b6711e |
output.data.count('
|
|
farhaanbukhsh |
b6711e |
|
|
farhaanbukhsh |
c4f329 |
@patch('pagure.ui.repo.admin_session_timedout')
|
|
farhaanbukhsh |
c4f329 |
def test_private_settings_ui(self, ast):
|
|
farhaanbukhsh |
c4f329 |
""" Test UI for private repo"""
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
b909de |
# Add private repo
|
|
farhaanbukhsh |
0163a1 |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
0163a1 |
user_id=1, # pingou
|
|
farhaanbukhsh |
0163a1 |
name='test4',
|
|
farhaanbukhsh |
0163a1 |
description='test project description',
|
|
farhaanbukhsh |
0163a1 |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
0163a1 |
private=True,
|
|
farhaanbukhsh |
0163a1 |
)
|
|
farhaanbukhsh |
0163a1 |
self.session.add(item)
|
|
farhaanbukhsh |
0163a1 |
self.session.commit()
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
0163a1 |
# Add a git repo
|
|
farhaanbukhsh |
b909de |
repo_path = os.path.join(
|
|
farhaanbukhsh |
b909de |
pagure.APP.config.get('GIT_FOLDER'), 'test4.git')
|
|
farhaanbukhsh |
0163a1 |
if not os.path.exists(repo_path):
|
|
farhaanbukhsh |
0163a1 |
os.makedirs(repo_path)
|
|
farhaanbukhsh |
0163a1 |
pygit2.init_repository(repo_path)
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
c4f329 |
user = tests.FakeUser(username='pingou')
|
|
farhaanbukhsh |
c4f329 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
c4f329 |
tests.create_projects(self.session)
|
|
farhaanbukhsh |
4858f8 |
tests.create_projects_git(pagure.APP.config.get('GIT_FOLDER'))
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
ast.return_value = False
|
|
farhaanbukhsh |
c4f329 |
output = self.app.post('/test/settings')
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
0163a1 |
# Check for a public repo
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c4f329 |
self.assertIn(
|
|
farhaanbukhsh |
c4f329 |
'
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
0163a1 |
ast.return_value = False
|
|
farhaanbukhsh |
0163a1 |
output = self.app.post('/test4/settings')
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
0163a1 |
# Check for private repo
|
|
farhaanbukhsh |
0163a1 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
0163a1 |
self.assertIn(
|
|
farhaanbukhsh |
0163a1 |
'<input checked="" name="private" type="checkbox" value="private">', output.data)
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
fc046c |
# Check the new project form has 'private' checkbox
|
|
farhaanbukhsh |
fc046c |
output = self.app.get('/new')
|
|
farhaanbukhsh |
fc046c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
fc046c |
self.assertIn(
|
|
farhaanbukhsh |
fc046c |
'<input id="private" name="private" type="checkbox" value="y">', output.data)
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
4ea512 |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
4ea512 |
def test_private_pr(self, send_email):
|
|
farhaanbukhsh |
c4f329 |
"""Test pull request made to the private repo"""
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
4ea512 |
send_email.return_value = True
|
|
farhaanbukhsh |
c4f329 |
# Add a private project
|
|
farhaanbukhsh |
c4f329 |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
c4f329 |
user_id=1, # pingou
|
|
farhaanbukhsh |
c4f329 |
name='pmc',
|
|
farhaanbukhsh |
c4f329 |
description='test project description',
|
|
farhaanbukhsh |
c4f329 |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
c4f329 |
private=True,
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
self.session.add(item)
|
|
farhaanbukhsh |
c4f329 |
self.session.commit()
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
f889f7 |
repo = pagure.lib.get_project(self.session, 'pmc')
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
f889f7 |
msg = pagure.lib.add_user_to_project(
|
|
farhaanbukhsh |
f889f7 |
session=self.session,
|
|
farhaanbukhsh |
f889f7 |
project=repo,
|
|
farhaanbukhsh |
f889f7 |
new_user='foo',
|
|
farhaanbukhsh |
f889f7 |
user='pingou',
|
|
farhaanbukhsh |
f889f7 |
)
|
|
farhaanbukhsh |
f889f7 |
self.session.commit()
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(msg, 'User added')
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
c4f329 |
# Create all the git repos
|
|
farhaanbukhsh |
c4f329 |
tests.create_projects_git(
|
|
farhaanbukhsh |
c4f329 |
os.path.join(tests.HERE, 'requests'), bare=True)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
1432c1 |
# Add a git repo
|
|
farhaanbukhsh |
b909de |
repo_path = os.path.join(
|
|
farhaanbukhsh |
b909de |
pagure.APP.config.get('REQUESTS_FOLDER'), 'pmc.git')
|
|
farhaanbukhsh |
1432c1 |
if not os.path.exists(repo_path):
|
|
farhaanbukhsh |
1432c1 |
os.makedirs(repo_path)
|
|
farhaanbukhsh |
1432c1 |
pygit2.init_repository(repo_path, bare=True)
|
|
farhaanbukhsh |
1432c1 |
|
|
farhaanbukhsh |
c4f329 |
# Check repo was created
|
|
farhaanbukhsh |
c4f329 |
user = tests.FakeUser(username='pingou')
|
|
farhaanbukhsh |
c4f329 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
output = self.app.get('/user/pingou/')
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c4f329 |
self.assertIn(
|
|
farhaanbukhsh |
c4f329 |
'
|
|
farhaanbukhsh |
c4f329 |
'class="label label-default">1', output.data)
|
|
farhaanbukhsh |
c4f329 |
self.assertIn(
|
|
farhaanbukhsh |
c4f329 |
'Forks 0',
|
|
farhaanbukhsh |
c4f329 |
output.data)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
self.set_up_git_repo(new_project=None, branch_from='feature')
|
|
farhaanbukhsh |
c4f329 |
project = pagure.lib.get_project(self.session, 'pmc')
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(len(project.requests), 1)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
output = self.app.get('/pmc/pull-request/1')
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Check repo was created
|
|
farhaanbukhsh |
c4f329 |
user = tests.FakeUser()
|
|
farhaanbukhsh |
c4f329 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
c4f329 |
output = self.app.get('/pmc/pull-requests')
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
user = tests.FakeUser(username='pingou')
|
|
farhaanbukhsh |
c4f329 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
c4f329 |
output = self.app.get('/pmc/pull-requests')
|
|
farhaanbukhsh |
1432c1 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
f889f7 |
user = tests.FakeUser(username='foo')
|
|
farhaanbukhsh |
f889f7 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
f889f7 |
output = self.app.get('/pmc/pull-requests')
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
420a97 |
@patch('pagure.lib.git.update_git')
|
|
farhaanbukhsh |
420a97 |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
420a97 |
def test_private_repo_issues_ui(self, p_send_email, p_ugt):
|
|
farhaanbukhsh |
420a97 |
""" Test issues made to private repo"""
|
|
farhaanbukhsh |
420a97 |
p_send_email.return_value = True
|
|
farhaanbukhsh |
420a97 |
p_ugt.return_value = True
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Add private repo
|
|
farhaanbukhsh |
420a97 |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
420a97 |
user_id=1, # pingou
|
|
farhaanbukhsh |
420a97 |
name='test4',
|
|
farhaanbukhsh |
420a97 |
description='test project description',
|
|
farhaanbukhsh |
420a97 |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
420a97 |
private=True,
|
|
farhaanbukhsh |
420a97 |
)
|
|
farhaanbukhsh |
420a97 |
self.session.add(item)
|
|
farhaanbukhsh |
420a97 |
self.session.commit()
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Add a git repo
|
|
farhaanbukhsh |
420a97 |
repo_path = os.path.join(
|
|
farhaanbukhsh |
420a97 |
pagure.APP.config.get('GIT_FOLDER'), 'test4.git')
|
|
farhaanbukhsh |
420a97 |
if not os.path.exists(repo_path):
|
|
farhaanbukhsh |
420a97 |
os.makedirs(repo_path)
|
|
farhaanbukhsh |
420a97 |
pygit2.init_repository(repo_path)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Add a git repo
|
|
farhaanbukhsh |
420a97 |
repo_path = os.path.join(
|
|
farhaanbukhsh |
420a97 |
pagure.APP.config.get('TICKETS_FOLDER'), 'test4.git')
|
|
farhaanbukhsh |
420a97 |
if not os.path.exists(repo_path):
|
|
farhaanbukhsh |
420a97 |
os.makedirs(repo_path)
|
|
farhaanbukhsh |
420a97 |
pygit2.init_repository(repo_path, bare=True)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Check if the private repo issues are publicly accesible
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issues')
|
|
farhaanbukhsh |
420a97 |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Create issues to play with
|
|
farhaanbukhsh |
420a97 |
repo = pagure.lib.get_project(self.session, 'test4')
|
|
farhaanbukhsh |
420a97 |
msg = pagure.lib.new_issue(
|
|
farhaanbukhsh |
420a97 |
session=self.session,
|
|
farhaanbukhsh |
420a97 |
repo=repo,
|
|
farhaanbukhsh |
420a97 |
title='Test issue',
|
|
farhaanbukhsh |
420a97 |
content='We should work on this',
|
|
farhaanbukhsh |
420a97 |
user='pingou',
|
|
farhaanbukhsh |
420a97 |
ticketfolder=None
|
|
farhaanbukhsh |
420a97 |
)
|
|
farhaanbukhsh |
420a97 |
self.session.commit()
|
|
farhaanbukhsh |
420a97 |
self.assertEqual(msg.title, 'Test issue')
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
user = tests.FakeUser()
|
|
farhaanbukhsh |
420a97 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Whole list
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issues')
|
|
farhaanbukhsh |
420a97 |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Check single issue
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issue/1')
|
|
farhaanbukhsh |
420a97 |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
user = tests.FakeUser(username='pingou')
|
|
farhaanbukhsh |
420a97 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Whole list
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issues')
|
|
farhaanbukhsh |
420a97 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
420a97 |
self.assertIn('<title>Issues - test4 - Pagure</title>', output.data)
|
|
farhaanbukhsh |
420a97 |
self.assertTrue(
|
|
farhaanbukhsh |
420a97 |
'\n 1 Open Issues' in output.data)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Check single issue
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issue/1')
|
|
farhaanbukhsh |
420a97 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
f889f7 |
repo = pagure.lib.get_project(self.session, 'test4')
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
f889f7 |
msg = pagure.lib.add_user_to_project(
|
|
farhaanbukhsh |
f889f7 |
session=self.session,
|
|
farhaanbukhsh |
f889f7 |
project=repo,
|
|
farhaanbukhsh |
f889f7 |
new_user='foo',
|
|
farhaanbukhsh |
f889f7 |
user='pingou',
|
|
farhaanbukhsh |
f889f7 |
)
|
|
farhaanbukhsh |
f889f7 |
self.session.commit()
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(msg, 'User added')
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
f889f7 |
user.username='foo'
|
|
farhaanbukhsh |
f889f7 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
f889f7 |
# Whole list
|
|
farhaanbukhsh |
f889f7 |
output = self.app.get('/test4/issues')
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
f889f7 |
self.assertIn('<title>Issues - test4 - Pagure</title>', output.data)
|
|
farhaanbukhsh |
f889f7 |
self.assertTrue(
|
|
farhaanbukhsh |
f889f7 |
'\n 1 Open Issues' in output.data)
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
f889f7 |
# Check single issue
|
|
farhaanbukhsh |
f889f7 |
output = self.app.get('/test4/issue/1')
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
60d445 |
def test_api_private_repo(self):
|
|
farhaanbukhsh |
60d445 |
""" Test api points for private repo"""
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Add private repo
|
|
farhaanbukhsh |
60d445 |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
60d445 |
user_id=1, # pingou
|
|
farhaanbukhsh |
60d445 |
name='test4',
|
|
farhaanbukhsh |
60d445 |
description='test project description',
|
|
farhaanbukhsh |
60d445 |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
60d445 |
private=True,
|
|
farhaanbukhsh |
60d445 |
)
|
|
farhaanbukhsh |
60d445 |
self.session.add(item)
|
|
farhaanbukhsh |
60d445 |
self.session.commit()
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Create a git repo to play with
|
|
farhaanbukhsh |
60d445 |
gitrepo = os.path.join(tests.HERE, 'repos', 'test4.git')
|
|
farhaanbukhsh |
60d445 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
farhaanbukhsh |
60d445 |
repopath = os.path.join(newpath, 'test4')
|
|
farhaanbukhsh |
60d445 |
clone_repo = pygit2.clone_repository(gitrepo, repopath)
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Create a file in that git repo
|
|
farhaanbukhsh |
60d445 |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
farhaanbukhsh |
60d445 |
stream.write('foo\n bar')
|
|
farhaanbukhsh |
60d445 |
clone_repo.index.add('sources')
|
|
farhaanbukhsh |
60d445 |
clone_repo.index.write()
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Commits the files added
|
|
farhaanbukhsh |
60d445 |
tree = clone_repo.index.write_tree()
|
|
farhaanbukhsh |
60d445 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
60d445 |
'Alice Author', 'alice@authors.tld')
|
|
farhaanbukhsh |
60d445 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
60d445 |
'Cecil Committer', 'cecil@committers.tld')
|
|
farhaanbukhsh |
60d445 |
clone_repo.create_commit(
|
|
farhaanbukhsh |
60d445 |
'refs/heads/master', # the name of the reference to update
|
|
farhaanbukhsh |
60d445 |
author,
|
|
farhaanbukhsh |
60d445 |
committer,
|
|
farhaanbukhsh |
60d445 |
'Add sources file for testing',
|
|
farhaanbukhsh |
60d445 |
# binary string representing the tree object ID
|
|
farhaanbukhsh |
60d445 |
tree,
|
|
farhaanbukhsh |
60d445 |
# list of binary strings representing parents of the new commit
|
|
farhaanbukhsh |
60d445 |
[]
|
|
farhaanbukhsh |
60d445 |
)
|
|
farhaanbukhsh |
60d445 |
refname = 'refs/heads/master:refs/heads/master'
|
|
farhaanbukhsh |
60d445 |
ori_remote = clone_repo.remotes[0]
|
|
farhaanbukhsh |
60d445 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Tag our first commit
|
|
farhaanbukhsh |
60d445 |
first_commit = repo.revparse_single('HEAD')
|
|
farhaanbukhsh |
60d445 |
tagger = pygit2.Signature('Alice Doe', 'adoe@example.com', 12347, 0)
|
|
farhaanbukhsh |
60d445 |
repo.create_tag(
|
|
farhaanbukhsh |
60d445 |
"0.0.1", first_commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger,
|
|
farhaanbukhsh |
60d445 |
"Release 0.0.1")
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Create a token for foo for this project
|
|
farhaanbukhsh |
60d445 |
item = pagure.lib.model.Token(
|
|
farhaanbukhsh |
60d445 |
id='foobar_token',
|
|
farhaanbukhsh |
60d445 |
user_id=1,
|
|
farhaanbukhsh |
60d445 |
project_id=1,
|
|
farhaanbukhsh |
60d445 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
farhaanbukhsh |
60d445 |
days=30)
|
|
farhaanbukhsh |
60d445 |
)
|
|
farhaanbukhsh |
60d445 |
self.session.add(item)
|
|
farhaanbukhsh |
60d445 |
self.session.commit()
|
|
farhaanbukhsh |
60d445 |
item = pagure.lib.model.TokenAcl(
|
|
farhaanbukhsh |
60d445 |
token_id='foobar_token',
|
|
farhaanbukhsh |
60d445 |
acl_id=3,
|
|
farhaanbukhsh |
60d445 |
)
|
|
farhaanbukhsh |
60d445 |
self.session.add(item)
|
|
farhaanbukhsh |
60d445 |
self.session.commit()
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Check tags
|
|
farhaanbukhsh |
60d445 |
output = self.app.get('/api/0/test4/git/tags')
|
|
farhaanbukhsh |
60d445 |
self.assertEqual(output.status_code, 403)
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
user = tests.FakeUser(username='pingou')
|
|
farhaanbukhsh |
60d445 |
with tests.user_set(pagure.APP, user):
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
output = self.app.get('/api/0/test4/git/tags')
|
|
farhaanbukhsh |
60d445 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
60d445 |
data = json.loads(output.data)
|
|
farhaanbukhsh |
60d445 |
self.assertDictEqual(
|
|
farhaanbukhsh |
60d445 |
data,
|
|
farhaanbukhsh |
60d445 |
{'tags': ['0.0.1'], 'total_tags': 1}
|
|
farhaanbukhsh |
60d445 |
)
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
3604c1 |
|
|
farhaanbukhsh |
1df65f |
if __name__ == '__main__':
|
|
farhaanbukhsh |
1df65f |
SUITE = unittest.TestLoader().loadTestsFromTestCase(PagurePrivateRepotest)
|
|
farhaanbukhsh |
1df65f |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|