|
Pierre-Yves Chibon |
1d1633 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
"""
|
|
Pierre-Yves Chibon |
9071b6 |
(c) 2016-2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
Authors:
|
|
Pierre-Yves Chibon |
1d1633 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
"""
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
1d1633 |
import unittest
|
|
Pierre-Yves Chibon |
1d1633 |
import sys
|
|
Pierre-Yves Chibon |
1d1633 |
import os
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
import pygit2
|
|
Pierre-Yves Chibon |
1d1633 |
from mock import patch
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
73d120 |
sys.path.insert(
|
|
Pierre-Yves Chibon |
73d120 |
0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
930073 |
import tests
|
|
Pierre-Yves Chibon |
930073 |
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Clement Verna |
109c4b |
class PagureFlaskRepoOldUrltests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
1d1633 |
""" Tests for flask app controller of pagure """
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
def setUp(self):
|
|
Pierre-Yves Chibon |
1d1633 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
1d1633 |
super(PagureFlaskRepoOldUrltests, self).setUp()
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["EMAIL_SEND"] = False
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["UPLOAD_FOLDER_PATH"] = os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "releases"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict("pagure.config.config", {"OLD_VIEW_COMMIT_ENABLED": True})
|
|
Lubomír Sedlář |
a25e58 |
def test_view_commit_old_with_bogus_url(self):
|
|
Pierre-Yves Chibon |
d49b8c |
""" Test the view_commit_old endpoint. """
|
|
Pierre-Yves Chibon |
64afef |
|
|
Pierre-Yves Chibon |
d49b8c |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
d49b8c |
|
|
Pierre-Yves Chibon |
d49b8c |
# Add a README to the git repo - First commit
|
|
Pierre-Yves Chibon |
73d120 |
tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
|
|
Pierre-Yves Chibon |
73d120 |
pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
|
|
Pierre-Yves Chibon |
d49b8c |
|
|
Pierre-Yves Chibon |
d49b8c |
# View first commit
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/apple-touch-icon-152x152-precomposed.png")
|
|
Pierre-Yves Chibon |
d49b8c |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
1a0280 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict("pagure.config.config", {"OLD_VIEW_COMMIT_ENABLED": True})
|
|
Pierre-Yves Chibon |
1d1633 |
def test_view_commit_old(self):
|
|
Pierre-Yves Chibon |
1d1633 |
""" Test the view_commit_old endpoint. """
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# Add a README to the git repo - First commit
|
|
Pierre-Yves Chibon |
73d120 |
tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
|
|
Pierre-Yves Chibon |
73d120 |
repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
|
|
Pierre-Yves Chibon |
73d120 |
commit = repo.revparse_single("HEAD")
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# View first commit
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/%s" % commit.oid.hex)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/%s" % commit.oid.hex, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
'href="#commit-overview-collapse"' in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
"Merged by Alice Author" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
"Committed by Cecil Committer" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Mark Reynolds |
48bfcb |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
'title="View file as of %s"' % commit.oid.hex[0:6]
|
|
Pierre-Yves Chibon |
73d120 |
in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# View first commit - with the old URL scheme
|
|
Pierre-Yves Chibon |
1d1633 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/%s" % commit.oid.hex, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
'href="#commit-overview-collapse"' in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
"Merged by Alice Author" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
"Committed by Cecil Committer" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# Add some content to the git repo
|
|
Pierre-Yves Chibon |
73d120 |
tests.add_content_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test.git")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
|
|
Pierre-Yves Chibon |
73d120 |
commit = repo.revparse_single("HEAD")
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# View another commit
|
|
Pierre-Yves Chibon |
1d1633 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/%s" % commit.oid.hex, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
'href="#commit-overview-collapse"' in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
"Authored by Alice Author" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
"Committed by Cecil Committer" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# Add a fork of a fork
|
|
Pierre-Yves Chibon |
1d1633 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
1d1633 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
name="test3",
|
|
Pierre-Yves Chibon |
73d120 |
description="test project #3",
|
|
farhaanbukhsh |
907098 |
is_fork=True,
|
|
Pierre-Yves Chibon |
1d1633 |
parent_id=1,
|
|
Pierre-Yves Chibon |
73d120 |
hook_token="aaabbbkkk",
|
|
Pierre-Yves Chibon |
1d1633 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
1d1633 |
self.session.commit()
|
|
Pierre-Yves Chibon |
1d1633 |
forkedgit = os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "forks", "pingou", "test3.git"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
tests.add_content_git_repo(forkedgit)
|
|
Pierre-Yves Chibon |
1d1633 |
tests.add_readme_git_repo(forkedgit)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
repo = pygit2.Repository(forkedgit)
|
|
Pierre-Yves Chibon |
73d120 |
commit = repo.revparse_single("HEAD")
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# Commit does not exist in anothe repo :)
|
|
Pierre-Yves Chibon |
1d1633 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/%s" % commit.oid.hex, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# View commit of fork
|
|
Pierre-Yves Chibon |
1d1633 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/fork/pingou/test3/%s" % commit.oid.hex, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
'href="#commit-overview-collapse"' in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
" Authored by Alice Author\n" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
" Committed by Cecil Committer\n" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Ryan Lerch |
e2f045 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
'title="View file as of %s"' % commit.oid.hex[0:6]
|
|
Pierre-Yves Chibon |
73d120 |
in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# View commit of fork - With the old URL scheme
|
|
Pierre-Yves Chibon |
1d1633 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/fork/pingou/test3/%s" % commit.oid.hex, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
'href="#commit-overview-collapse"' in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
"Authored by Alice Author" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
"Committed by Cecil Committer" in output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
# Try the old URL scheme with a short hash
|
|
Pierre-Yves Chibon |
1d1633 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/fork/pingou/test3/%s" % commit.oid.hex[:10],
|
|
Pierre-Yves Chibon |
73d120 |
follow_redirects=True,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"Project not found ", output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
1d1633 |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|