|
Pierre-Yves Chibon |
65f7db |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
"""
|
|
Pierre-Yves Chibon |
65f7db |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
Authors:
|
|
Pierre-Yves Chibon |
65f7db |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
"""
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
65f7db |
import pkg_resources
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
import json
|
|
Pierre-Yves Chibon |
65f7db |
import unittest
|
|
Pierre-Yves Chibon |
65f7db |
import shutil
|
|
Pierre-Yves Chibon |
65f7db |
import sys
|
|
Pierre-Yves Chibon |
65f7db |
import tempfile
|
|
Pierre-Yves Chibon |
65f7db |
import os
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
import pygit2
|
|
Pierre-Yves Chibon |
65f7db |
from mock import patch
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
65f7db |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
import pagure.lib
|
|
Pierre-Yves Chibon |
65f7db |
import tests
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
class PagureFlaskNoMasterBranchtests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
65f7db |
""" Tests for flask application when the git repo has no master branch.
|
|
Pierre-Yves Chibon |
65f7db |
"""
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
def setUp(self):
|
|
Pierre-Yves Chibon |
65f7db |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
65f7db |
super(PagureFlaskNoMasterBranchtests, self).setUp()
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
65f7db |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
65f7db |
pagure.lib.SESSION = self.session
|
|
Pierre-Yves Chibon |
65f7db |
pagure.ui.app.SESSION = self.session
|
|
Pierre-Yves Chibon |
65f7db |
pagure.ui.filters.SESSION = self.session
|
|
Pierre-Yves Chibon |
65f7db |
pagure.ui.fork.SESSION = self.session
|
|
Pierre-Yves Chibon |
65f7db |
pagure.ui.repo.SESSION = self.session
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
pagure.APP.config['GIT_FOLDER'] = os.path.join(tests.HERE, 'repos')
|
|
Pierre-Yves Chibon |
65f7db |
pagure.APP.config['FORK_FOLDER'] = os.path.join(tests.HERE, 'forks')
|
|
Pierre-Yves Chibon |
65f7db |
pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
65f7db |
tests.HERE, 'tickets')
|
|
Pierre-Yves Chibon |
65f7db |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
65f7db |
tests.HERE, 'docs')
|
|
Pierre-Yves Chibon |
65f7db |
pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
65f7db |
tests.HERE, 'requests')
|
|
Pierre-Yves Chibon |
65f7db |
self.app = pagure.APP.test_client()
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
def set_up_git_repo(self):
|
|
Pierre-Yves Chibon |
65f7db |
""" Set up the git repo to play with. """
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
# Create a git repo to play with
|
|
Pierre-Yves Chibon |
65f7db |
gitrepo = os.path.join(tests.HERE, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
65f7db |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
newpath = tempfile.mkdtemp(prefix='pagure-other-test')
|
|
Pierre-Yves Chibon |
65f7db |
repopath = os.path.join(newpath, 'test')
|
|
Pierre-Yves Chibon |
65f7db |
clone_repo = pygit2.clone_repository(gitrepo, repopath)
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
# Create a file in that git repo
|
|
Pierre-Yves Chibon |
65f7db |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
Pierre-Yves Chibon |
65f7db |
stream.write('foo\n bar')
|
|
Pierre-Yves Chibon |
65f7db |
clone_repo.index.add('sources')
|
|
Pierre-Yves Chibon |
65f7db |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
# Commits the files added
|
|
Pierre-Yves Chibon |
65f7db |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
65f7db |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
65f7db |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
65f7db |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
65f7db |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
65f7db |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
65f7db |
'refs/heads/feature', # the name of the reference to update
|
|
Pierre-Yves Chibon |
65f7db |
author,
|
|
Pierre-Yves Chibon |
65f7db |
committer,
|
|
Pierre-Yves Chibon |
65f7db |
'Add sources file for testing',
|
|
Pierre-Yves Chibon |
65f7db |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
65f7db |
tree,
|
|
Pierre-Yves Chibon |
65f7db |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
65f7db |
[]
|
|
Pierre-Yves Chibon |
65f7db |
)
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
feature_branch = clone_repo.lookup_branch('feature')
|
|
Pierre-Yves Chibon |
65f7db |
first_commit = feature_branch.get_object().hex
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
# Second commit
|
|
Pierre-Yves Chibon |
65f7db |
with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
|
|
Pierre-Yves Chibon |
65f7db |
stream.write('*~')
|
|
Pierre-Yves Chibon |
65f7db |
clone_repo.index.add('.gitignore')
|
|
Pierre-Yves Chibon |
65f7db |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
65f7db |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
65f7db |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
65f7db |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
65f7db |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
65f7db |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
07f8d0 |
'refs/heads/feature',
|
|
Pierre-Yves Chibon |
65f7db |
author,
|
|
Pierre-Yves Chibon |
65f7db |
committer,
|
|
Pierre-Yves Chibon |
65f7db |
'Add .gitignore file for testing',
|
|
Pierre-Yves Chibon |
65f7db |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
65f7db |
tree,
|
|
Pierre-Yves Chibon |
65f7db |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
65f7db |
[first_commit]
|
|
Pierre-Yves Chibon |
65f7db |
)
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
refname = 'refs/heads/feature'
|
|
Pierre-Yves Chibon |
65f7db |
ori_remote = clone_repo.remotes[0]
|
|
Pierre-Yves Chibon |
65f7db |
ori_remote.push(refname)
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
65f7db |
def test_view_repo(self, send_email):
|
|
Pierre-Yves Chibon |
65f7db |
""" Test the view_repo endpoint when the git repo has no master
|
|
Pierre-Yves Chibon |
65f7db |
branch.
|
|
Pierre-Yves Chibon |
65f7db |
"""
|
|
Pierre-Yves Chibon |
65f7db |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
65f7db |
# Non-existant git repo
|
|
Pierre-Yves Chibon |
65f7db |
output = self.app.get('/test')
|
|
Pierre-Yves Chibon |
65f7db |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
self.set_up_git_repo()
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
# With git repo
|
|
Pierre-Yves Chibon |
65f7db |
output = self.app.get('/test')
|
|
Pierre-Yves Chibon |
65f7db |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
65f7db |
self.assertIn('Last 0 commits', output.data)
|
|
Pierre-Yves Chibon |
65f7db |
self.assertTrue(output.data.count('
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
a5ec94 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
a5ec94 |
def test_view_repo_branch(self, send_email):
|
|
Pierre-Yves Chibon |
a5ec94 |
""" Test the view_repo_branch endpoint when the git repo has no
|
|
Pierre-Yves Chibon |
a5ec94 |
master branch.
|
|
Pierre-Yves Chibon |
a5ec94 |
"""
|
|
Pierre-Yves Chibon |
a5ec94 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
a5ec94 |
|
|
Pierre-Yves Chibon |
a5ec94 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
a5ec94 |
# Non-existant git repo
|
|
Pierre-Yves Chibon |
a5ec94 |
output = self.app.get('/test/branch/master')
|
|
Pierre-Yves Chibon |
a5ec94 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
a5ec94 |
|
|
Pierre-Yves Chibon |
a5ec94 |
self.set_up_git_repo()
|
|
Pierre-Yves Chibon |
a5ec94 |
|
|
Pierre-Yves Chibon |
a5ec94 |
# With git repo
|
|
Pierre-Yves Chibon |
a5ec94 |
output = self.app.get('/test/branch/feature')
|
|
Pierre-Yves Chibon |
a5ec94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
07f8d0 |
self.assertIn('Last 2 commits', output.data)
|
|
Pierre-Yves Chibon |
a5ec94 |
self.assertTrue(output.data.count('
|
|
Pierre-Yves Chibon |
a5ec94 |
|
|
Pierre-Yves Chibon |
59857a |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
59857a |
def test_view_commits(self, send_email):
|
|
Pierre-Yves Chibon |
59857a |
""" Test the view_commits endpoint when the git repo has no
|
|
Pierre-Yves Chibon |
59857a |
master branch.
|
|
Pierre-Yves Chibon |
59857a |
"""
|
|
Pierre-Yves Chibon |
59857a |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
59857a |
|
|
Pierre-Yves Chibon |
59857a |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
59857a |
# Non-existant git repo
|
|
Pierre-Yves Chibon |
59857a |
output = self.app.get('/test/commits')
|
|
Pierre-Yves Chibon |
59857a |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
59857a |
|
|
Pierre-Yves Chibon |
59857a |
self.set_up_git_repo()
|
|
Pierre-Yves Chibon |
59857a |
|
|
Pierre-Yves Chibon |
59857a |
# With git repo
|
|
Pierre-Yves Chibon |
59857a |
output = self.app.get('/test/commits')
|
|
Pierre-Yves Chibon |
59857a |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
59857a |
self.assertIn(
|
|
Pierre-Yves Chibon |
59857a |
'Commits list\n ', output.data)
|
|
Pierre-Yves Chibon |
59857a |
self.assertTrue(output.data.count('
|
|
Pierre-Yves Chibon |
59857a |
|
|
Pierre-Yves Chibon |
59857a |
output = self.app.get('/test/commits/feature')
|
|
Pierre-Yves Chibon |
59857a |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
59857a |
self.assertIn('Commits list', output.data)
|
|
Pierre-Yves Chibon |
59857a |
self.assertIn('Add sources file for testing', output.data)
|
|
Pierre-Yves Chibon |
07f8d0 |
self.assertIn('Add .gitignore file for testing', output.data)
|
|
Pierre-Yves Chibon |
59857a |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
59857a |
'Commits list\n ', output.data)
|
|
Pierre-Yves Chibon |
59857a |
self.assertTrue(output.data.count('
|
|
Pierre-Yves Chibon |
59857a |
|
|
Pierre-Yves Chibon |
e5bc0d |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
e5bc0d |
def test_view_file(self, send_email):
|
|
Pierre-Yves Chibon |
e5bc0d |
""" Test the view_file endpoint when the git repo has no
|
|
Pierre-Yves Chibon |
e5bc0d |
master branch.
|
|
Pierre-Yves Chibon |
e5bc0d |
"""
|
|
Pierre-Yves Chibon |
e5bc0d |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
e5bc0d |
|
|
Pierre-Yves Chibon |
e5bc0d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
e5bc0d |
# Non-existant git repo
|
|
Pierre-Yves Chibon |
e5bc0d |
output = self.app.get('/test/blob/master/f/sources')
|
|
Pierre-Yves Chibon |
e5bc0d |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
e5bc0d |
|
|
Pierre-Yves Chibon |
e5bc0d |
self.set_up_git_repo()
|
|
Pierre-Yves Chibon |
e5bc0d |
|
|
Pierre-Yves Chibon |
e5bc0d |
# With git repo
|
|
Pierre-Yves Chibon |
e5bc0d |
output = self.app.get('/test/blob/master/f/sources')
|
|
Pierre-Yves Chibon |
e5bc0d |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
e5bc0d |
|
|
Pierre-Yves Chibon |
e5bc0d |
output = self.app.get('/test/blob/feature/f/sources')
|
|
Pierre-Yves Chibon |
e5bc0d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e5bc0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
e5bc0d |
'feature/sources',
|
|
Pierre-Yves Chibon |
e5bc0d |
output.data)
|
|
Pierre-Yves Chibon |
e5bc0d |
self.assertIn(
|
|
Pierre-Yves Chibon |
e5bc0d |
'foo ', output.data)
|
|
Pierre-Yves Chibon |
e5bc0d |
|
|
Pierre-Yves Chibon |
d908a9 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
d908a9 |
def test_view_raw_file(self, send_email):
|
|
Pierre-Yves Chibon |
d908a9 |
""" Test the view_raw_file endpoint when the git repo has no
|
|
Pierre-Yves Chibon |
d908a9 |
master branch.
|
|
Pierre-Yves Chibon |
d908a9 |
"""
|
|
Pierre-Yves Chibon |
d908a9 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
d908a9 |
|
|
Pierre-Yves Chibon |
d908a9 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
d908a9 |
# Non-existant git repo
|
|
Pierre-Yves Chibon |
d908a9 |
output = self.app.get('/test/raw/master')
|
|
Pierre-Yves Chibon |
d908a9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d908a9 |
output = self.app.get('/test/raw/master/f/sources')
|
|
Pierre-Yves Chibon |
d908a9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d908a9 |
|
|
Pierre-Yves Chibon |
d908a9 |
self.set_up_git_repo()
|
|
Pierre-Yves Chibon |
d908a9 |
|
|
Pierre-Yves Chibon |
d908a9 |
# With git repo
|
|
Pierre-Yves Chibon |
d908a9 |
output = self.app.get('/test/raw/master')
|
|
Pierre-Yves Chibon |
d908a9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d908a9 |
output = self.app.get('/test/raw/master/f/sources')
|
|
Pierre-Yves Chibon |
d908a9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d908a9 |
|
|
Pierre-Yves Chibon |
d908a9 |
output = self.app.get('/test/raw/feature')
|
|
Pierre-Yves Chibon |
d908a9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
07f8d0 |
self.assertIn('diff --git a/.gitignore b/.gitignore', output.data)
|
|
Pierre-Yves Chibon |
07f8d0 |
self.assertIn('+*~', output.data)
|
|
Pierre-Yves Chibon |
d908a9 |
|
|
Pierre-Yves Chibon |
d908a9 |
output = self.app.get('/test/raw/feature/f/sources')
|
|
Pierre-Yves Chibon |
d908a9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
d908a9 |
self.assertEqual('foo\n bar', output.data)
|
|
Pierre-Yves Chibon |
d908a9 |
|
|
Pierre-Yves Chibon |
45cfa4 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
45cfa4 |
def test_view_tree(self, send_email):
|
|
Pierre-Yves Chibon |
45cfa4 |
""" Test the view_tree endpoint when the git repo has no
|
|
Pierre-Yves Chibon |
45cfa4 |
master branch.
|
|
Pierre-Yves Chibon |
45cfa4 |
"""
|
|
Pierre-Yves Chibon |
45cfa4 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
45cfa4 |
|
|
Pierre-Yves Chibon |
45cfa4 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
45cfa4 |
# Non-existant git repo
|
|
Pierre-Yves Chibon |
45cfa4 |
output = self.app.get('/test/tree/')
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
45cfa4 |
output = self.app.get('/test/tree/master')
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
45cfa4 |
|
|
Pierre-Yves Chibon |
45cfa4 |
self.set_up_git_repo()
|
|
Pierre-Yves Chibon |
45cfa4 |
|
|
Pierre-Yves Chibon |
45cfa4 |
# With git repo
|
|
Pierre-Yves Chibon |
45cfa4 |
output = self.app.get('/test/tree/master')
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertIn('No content found in this repository', output.data)
|
|
Pierre-Yves Chibon |
45cfa4 |
output = self.app.get('/test/tree/master/sources')
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertIn('No content found in this repository', output.data)
|
|
Pierre-Yves Chibon |
45cfa4 |
|
|
Pierre-Yves Chibon |
45cfa4 |
output = self.app.get('/test/tree/feature')
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertIn('', output.data)
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertIn('9f4435', output.data)
|
|
Pierre-Yves Chibon |
45cfa4 |
|
|
Pierre-Yves Chibon |
45cfa4 |
output = self.app.get('/test/tree/feature/sources')
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
45cfa4 |
self.assertIn('No content found in this repository', output.data)
|
|
Pierre-Yves Chibon |
45cfa4 |
|
|
Pierre-Yves Chibon |
60fe0c |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
60fe0c |
def test_new_request_pull(self, send_email):
|
|
Pierre-Yves Chibon |
60fe0c |
""" Test the new_request_pull endpoint when the git repo has no
|
|
Pierre-Yves Chibon |
60fe0c |
master branch.
|
|
Pierre-Yves Chibon |
60fe0c |
"""
|
|
Pierre-Yves Chibon |
60fe0c |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
60fe0c |
|
|
Pierre-Yves Chibon |
60fe0c |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
60fe0c |
# Non-existant git repo
|
|
Pierre-Yves Chibon |
60fe0c |
output = self.app.get('/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
60fe0c |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
60fe0c |
|
|
Pierre-Yves Chibon |
60fe0c |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
60fe0c |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
60fe0c |
output = self.app.get('/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
60fe0c |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
60fe0c |
|
|
Pierre-Yves Chibon |
60fe0c |
self.set_up_git_repo()
|
|
Pierre-Yves Chibon |
60fe0c |
|
|
Pierre-Yves Chibon |
60fe0c |
output = self.app.get('/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
60fe0c |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
60fe0c |
|
|
Pierre-Yves Chibon |
60fe0c |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
60fe0c |
with tests.user_set(pagure.APP, user):
|
|
Pierre-Yves Chibon |
60fe0c |
output = self.app.get('/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
60fe0c |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
60fe0c |
self.assertIn(
|
|
Pierre-Yves Chibon |
60fe0c |
'Branch master could not be found in the target repo ',
|
|
Pierre-Yves Chibon |
60fe0c |
output.data)
|
|
Pierre-Yves Chibon |
60fe0c |
|
|
Pierre-Yves Chibon |
65f7db |
|
|
Pierre-Yves Chibon |
65f7db |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
65f7db |
SUITE = unittest.TestLoader().loadTestsFromTestCase(
|
|
Pierre-Yves Chibon |
65f7db |
PagureFlaskNoMasterBranchtests)
|
|
Pierre-Yves Chibon |
65f7db |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|