|
Julen Landa Alustiza |
51e0f0 |
# -*- coding: utf-8 -*-
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
"""
|
|
Julen Landa Alustiza |
51e0f0 |
Authors:
|
|
Julen Landa Alustiza |
51e0f0 |
Julen Landa Alustiza <julen@landa.eus></julen@landa.eus>
|
|
Julen Landa Alustiza |
51e0f0 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
"""
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
from __future__ import unicode_literals, absolute_import
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
import re
|
|
Julen Landa Alustiza |
51e0f0 |
import sys
|
|
Julen Landa Alustiza |
51e0f0 |
import os
|
|
Julen Landa Alustiza |
51e0f0 |
import pygit2
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
sys.path.insert(
|
|
Julen Landa Alustiza |
51e0f0 |
0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
import tests
|
|
Julen Landa Alustiza |
51e0f0 |
import pagure.lib.model
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
class PagureFlaskRepoViewBlameFileSimpletests(tests.Modeltests):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Tests for view_blame_file endpoint of the flask pagure app """
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_no_project(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/foo/blame/sources")
|
|
Julen Landa Alustiza |
51e0f0 |
# No project registered in the DB
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 404)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
"<title>Page not found :'( - Pagure</title>", output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("Page not found (404)", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("Project not found ", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_no_git_repo(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
tests.create_projects(self.session)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/sources")
|
|
Julen Landa Alustiza |
51e0f0 |
# No git repo associated
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 404)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_no_git_content(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
tests.create_projects(self.session)
|
|
Julen Landa Alustiza |
51e0f0 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/sources")
|
|
Julen Landa Alustiza |
51e0f0 |
# project and associated repo, but no file
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 404)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
"<title>Page not found :'( - Pagure</title>", output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("Page not found (404)", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("Empty repo cannot have a file ", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
class PagureFlaskRepoViewBlameFiletests(tests.Modeltests):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Tests for view_blame_file endpoint of the flask pagure app """
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def setUp(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Set up the environment, ran before every tests. """
|
|
Julen Landa Alustiza |
51e0f0 |
super(PagureFlaskRepoViewBlameFiletests, self).setUp()
|
|
Julen Landa Alustiza |
51e0f0 |
self.regex = re.compile(r'>(\w+)\n')
|
|
Julen Landa Alustiza |
51e0f0 |
tests.create_projects(self.session)
|
|
Julen Landa Alustiza |
51e0f0 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
# Add some content to the git repo
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_content_to_git(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "test.git"),
|
|
Julen Landa Alustiza |
51e0f0 |
message="initial commit",
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_content_to_git(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "test.git"), message="foo"
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_content_to_git(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "test.git"),
|
|
Julen Landa Alustiza |
51e0f0 |
branch="feature",
|
|
Julen Landa Alustiza |
51e0f0 |
content="bar",
|
|
Julen Landa Alustiza |
51e0f0 |
message="bar",
|
|
Julen Landa Alustiza |
51e0f0 |
author=("Aritz Author", "aritz@authors.tld"),
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_default_branch_master(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/sources")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 200)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertTrue(
|
|
Julen Landa Alustiza |
51e0f0 |
'
|
|
Julen Landa Alustiza |
51e0f0 |
'data-line-number="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
or '
|
|
Julen Landa Alustiza |
51e0f0 |
'href="#1" id="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
'foo ', output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('Alice Author', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
data = self.regex.findall(output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(len(data), 2)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_default_branch_non_master(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
|
|
Julen Landa Alustiza |
51e0f0 |
reference = repo.lookup_reference("refs/heads/feature").resolve()
|
|
Julen Landa Alustiza |
51e0f0 |
repo.set_head(reference.name)
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/sources")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 200)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertTrue(
|
|
Julen Landa Alustiza |
51e0f0 |
'
|
|
Julen Landa Alustiza |
51e0f0 |
'data-line-number="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
or '
|
|
Julen Landa Alustiza |
51e0f0 |
'href="#1" id="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
'bar ', output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('Aritz Author', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
data = self.regex.findall(output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(len(data), 3)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_on_commit(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
repo_obj = pygit2.Repository(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "test.git")
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
commit = repo_obj[repo_obj.head.target]
|
|
Julen Landa Alustiza |
51e0f0 |
parent = commit.parents[0].oid.hex
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get(
|
|
Julen Landa Alustiza |
51e0f0 |
"/test/blame/sources?identifier={}".format(parent)
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 200)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertTrue(
|
|
Julen Landa Alustiza |
51e0f0 |
'
|
|
Julen Landa Alustiza |
51e0f0 |
'data-line-number="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
or '
|
|
Julen Landa Alustiza |
51e0f0 |
'href="#1" id="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
'foo ', output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('Alice Author', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
data = self.regex.findall(output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(len(data), 1)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_on_branch(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/sources?identifier=feature")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 200)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertTrue(
|
|
Julen Landa Alustiza |
51e0f0 |
'
|
|
Julen Landa Alustiza |
51e0f0 |
'data-line-number="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
or '
|
|
Julen Landa Alustiza |
51e0f0 |
'href="#1" id="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
'bar ', output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('Aritz Author', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
data = self.regex.findall(output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(len(data), 3)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_on_tag(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
# set a tag on the head's parent commit
|
|
Julen Landa Alustiza |
51e0f0 |
repo_obj = pygit2.Repository(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "test.git")
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
commit = repo_obj[repo_obj.head.target]
|
|
Julen Landa Alustiza |
51e0f0 |
parent = commit.parents[0].oid.hex
|
|
Julen Landa Alustiza |
51e0f0 |
tagger = pygit2.Signature("Alice Doe", "adoe@example.com", 12347, 0)
|
|
Julen Landa Alustiza |
51e0f0 |
repo_obj.create_tag(
|
|
Julen Landa Alustiza |
51e0f0 |
"v1.0", parent, pygit2.GIT_OBJ_COMMIT, tagger, "Release v1.0"
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/sources?identifier=v1.0")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 200)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertTrue(
|
|
Julen Landa Alustiza |
51e0f0 |
'
|
|
Julen Landa Alustiza |
51e0f0 |
'data-line-number="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
or '
|
|
Julen Landa Alustiza |
51e0f0 |
'href="#1" id="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
'foo ', output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('Alice Author', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
data = self.regex.findall(output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(len(data), 1)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_binary(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
# Add binary content
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_binary_git_repo(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "test.git"), "test.jpg"
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/test.jpg")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 400)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("<title>400 Bad Request</title>", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("Binary files cannot be blamed ", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_non_ascii_name(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_commit_git_repo(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "test.git"),
|
|
Julen Landa Alustiza |
51e0f0 |
ncommits=1,
|
|
Julen Landa Alustiza |
51e0f0 |
filename="Ĺ ource",
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/Ĺ ource")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 200)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(
|
|
Julen Landa Alustiza |
51e0f0 |
output.headers["Content-Type"].lower(), "text/html; charset=utf-8"
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(" Ĺ ource", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertTrue(
|
|
Julen Landa Alustiza |
51e0f0 |
'
|
|
Julen Landa Alustiza |
51e0f0 |
'data-line-number="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
or '
|
|
Julen Landa Alustiza |
51e0f0 |
'href="#1" id="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
'Row 0 ', output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_fork_of_a_fork(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
item = pagure.lib.model.Project(
|
|
Julen Landa Alustiza |
51e0f0 |
user_id=1, # pingou
|
|
Julen Landa Alustiza |
51e0f0 |
name="test3",
|
|
Julen Landa Alustiza |
51e0f0 |
description="test project #3",
|
|
Julen Landa Alustiza |
51e0f0 |
is_fork=True,
|
|
Julen Landa Alustiza |
51e0f0 |
parent_id=1,
|
|
Julen Landa Alustiza |
51e0f0 |
hook_token="aaabbbppp",
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.session.add(item)
|
|
Julen Landa Alustiza |
51e0f0 |
self.session.commit()
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_content_git_repo(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "forks", "pingou", "test3.git")
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_readme_git_repo(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "forks", "pingou", "test3.git")
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_commit_git_repo(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),
|
|
Julen Landa Alustiza |
51e0f0 |
ncommits=10,
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_content_to_git(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),
|
|
Julen Landa Alustiza |
51e0f0 |
content="â¨âđ°ââ¨",
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/fork/pingou/test3/blame/sources")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 200)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn('', output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertTrue(
|
|
Julen Landa Alustiza |
51e0f0 |
'
|
|
Julen Landa Alustiza |
51e0f0 |
'data-line-number="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
or '
|
|
Julen Landa Alustiza |
51e0f0 |
'href="#1" id="1">' in output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
' barRow 0 ',
|
|
Julen Landa Alustiza |
51e0f0 |
output_text,
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_no_file(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/foofile")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 404)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
"<title>Page not found :'( - Pagure</title>", output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("Page not found (404)", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("File not found ", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_folder(self):
|
|
Julen Landa Alustiza |
51e0f0 |
""" Test the view_blame_file endpoint """
|
|
Julen Landa Alustiza |
51e0f0 |
tests.add_commit_git_repo(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "test.git/folder1"),
|
|
Julen Landa Alustiza |
51e0f0 |
ncommits=1,
|
|
Julen Landa Alustiza |
51e0f0 |
filename="sources",
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/folder1")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 404)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
"<title>Page not found :'( - Pagure</title>", output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("Page not found (404)", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("File not found ", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
def test_view_blame_file_unborn_head_no_identifier(self):
|
|
Julen Landa Alustiza |
51e0f0 |
repo_obj = pygit2.Repository(
|
|
Julen Landa Alustiza |
51e0f0 |
os.path.join(self.path, "repos", "test.git")
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
repo_obj.set_head("refs/heads/unexistent")
|
|
Julen Landa Alustiza |
51e0f0 |
|
|
Julen Landa Alustiza |
51e0f0 |
output = self.app.get("/test/blame/sources")
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertEqual(output.status_code, 404)
|
|
Julen Landa Alustiza |
51e0f0 |
output_text = output.get_data(as_text=True)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
"<title>Page not found :'( - Pagure</title>", output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn("Page not found (404)", output_text)
|
|
Julen Landa Alustiza |
51e0f0 |
self.assertIn(
|
|
Julen Landa Alustiza |
51e0f0 |
"Identifier is mandatory on unborn HEAD repos ", output_text
|
|
Julen Landa Alustiza |
51e0f0 |
)
|