|
Pierre-Yves Chibon |
12829b |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
"""
|
|
Pierre-Yves Chibon |
12829b |
(c) 2017 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
Authors:
|
|
Pierre-Yves Chibon |
12829b |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
"""
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
12829b |
import unittest
|
|
Pierre-Yves Chibon |
12829b |
import sys
|
|
Pierre-Yves Chibon |
12829b |
import os
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
import pygit2
|
|
Pierre-Yves Chibon |
12829b |
|
|
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 |
12829b |
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.model # noqa
|
|
Pierre-Yves Chibon |
12829b |
import tests # noqa
|
|
Pierre-Yves Chibon |
12829b |
from pagure.lib.repo import PagureRepo # noqa
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
class LocalBasetests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
12829b |
""" Tests for view_file endpoint of the flask pagure app """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def setUp(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
12829b |
super(LocalBasetests, self).setUp()
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["VIRUS_SCAN_ATTACHMENTS"] = False
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["UPLOAD_FOLDER_URL"] = "/releases/"
|
|
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 |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
class PagureFlaskRepoViewFileSimpletests(LocalBasetests):
|
|
Pierre-Yves Chibon |
12829b |
""" Tests for view_file endpoint of the flask pagure app """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_no_project(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file when the project is unknown. """
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/foo/blob/foo/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
# No project registered in the DB
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_no_git(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file when the project has no git repo. """
|
|
Pierre-Yves Chibon |
12829b |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/foo/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
# No git repo associated
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_no_git_content(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file when the file doesn't exist. """
|
|
Pierre-Yves Chibon |
12829b |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/foo/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
class PagureFlaskRepoViewFiletests(LocalBasetests):
|
|
Pierre-Yves Chibon |
12829b |
""" Tests for view_file endpoint of the flask pagure app """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def setUp(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
12829b |
super(PagureFlaskRepoViewFiletests, self).setUp()
|
|
Pierre-Yves Chibon |
12829b |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# Add some content to the git repo
|
|
Pierre-Yves Chibon |
12829b |
tests.add_content_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test.git")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
|
|
Pierre-Yves Chibon |
12829b |
tests.add_binary_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test.git"), "test.jpg"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
tests.add_binary_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test.git"), "test_binary"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_invalid_file(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file when the file doesn't exist. """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/foofile")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/sources/f/testfoo.jpg")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/folder1/testfoo.jpg")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_basic_text(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file with a basic text file. """
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
967e77 |
self.assertIn(
|
|
Ryan Lerch |
9fe1c6 |
''
|
|
Ryan Lerch |
9fe1c6 |
'foo\n bar ',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
2d9829 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_empty_file(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file with an empty file. """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# Empty files should also be displayed
|
|
Pierre-Yves Chibon |
12829b |
tests.add_content_to_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test.git"),
|
|
Pierre-Yves Chibon |
12829b |
filename="emptyfile.md",
|
|
Pierre-Yves Chibon |
73d120 |
content="",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/emptyfile.md")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
12829b |
'
|
|
Pierre-Yves Chibon |
12829b |
'href="/test/raw/master/f/emptyfile.md" '
|
|
Pierre-Yves Chibon |
73d120 |
'title="View as raw">Raw',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
'\n' " \n ", output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_binary_file(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file with a binary file. """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# View what's supposed to be an image
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/test.jpg")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Binary files cannot be rendered. ", output_text)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
12829b |
'view the raw version',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_by_commit(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file in a specific commit. """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# View by commit id
|
|
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 |
12829b |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/%s/f/test.jpg" % commit.oid.hex)
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Binary files cannot be rendered. ", output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('/f/test.jpg">view the raw version', output_text)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_by_name(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file via a image name. """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# View by image name -- somehow we support this
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/sources/f/test.jpg")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Binary files cannot be rendered. ", output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('/f/test.jpg">view the raw version', output_text)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_binary_file2(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file with a binary file (2). """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# View binary file
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/sources/f/test_binary")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Aurélien Bompard |
626417 |
self.assertIn('/f/test_binary">view the raw version', output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue("Binary files cannot be rendered. " in output_text)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_for_folder(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file with a folder. """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# View folder
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/folder1")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
'', output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("<title>Tree - test - Pagure</title>", output_text)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
'', output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_nested_file(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file with a nested file. """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# Verify the nav links correctly when viewing a nested folder/file.
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/folder1/folder2/file")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
77bdcd |
'
|
|
Pierre-Yves Chibon |
77bdcd |
'href="/test/blob/master/f/folder1/folder2">\n '
|
|
Pierre-Yves Chibon |
77bdcd |
' folder2'
|
|
Pierre-Yves Chibon |
73d120 |
"\n ",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_non_ascii_file(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file with a non-ascii file name. """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# View file with a non-ascii name
|
|
Pierre-Yves Chibon |
12829b |
tests.add_commit_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test.git"),
|
|
Pierre-Yves Chibon |
73d120 |
ncommits=1,
|
|
Pierre-Yves Chibon |
73d120 |
filename="Šource",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/Šource")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
output.headers["Content-Type"].lower(), "text/html; charset=utf-8"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn(" Šource", output_text)
|
|
Pierre-Yves Chibon |
967e77 |
self.assertIn(
|
|
Ryan Lerch |
9fe1c6 |
''
|
|
Ryan Lerch |
9fe1c6 |
'Row 0\n ',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
12829b |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_fork_and_edit_logged_out(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file fork and edit button presence when logged
|
|
Pierre-Yves Chibon |
12829b |
out.
|
|
Pierre-Yves Chibon |
12829b |
"""
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# not logged in, no edit button but fork & edit is there
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
12829b |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
12829b |
'
|
|
Pierre-Yves Chibon |
12829b |
'href="/test/edit/master/f/sources" title="Edit file">'
|
|
Pierre-Yves Chibon |
73d120 |
"Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
36de81 |
'<button class="btn btn-sm btn-secondary fork_project_btn">'</button>
|
|
Julen Landa Alustiza |
0cafab |
"\n Fork and Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
025aab |
def test_view_file_fork_and_edit_logged_in(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file fork and edit button presence when logged
|
|
Pierre-Yves Chibon |
12829b |
in.
|
|
Pierre-Yves Chibon |
12829b |
"""
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# logged in, both buttons are there
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
12829b |
'
|
|
Pierre-Yves Chibon |
12829b |
'href="/test/edit/master/f/sources" title="Edit file">'
|
|
Pierre-Yves Chibon |
73d120 |
"Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
36de81 |
'<button class="btn btn-sm btn-secondary fork_project_btn">'</button>
|
|
Julen Landa Alustiza |
0cafab |
"\n Fork and Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
025aab |
class PagureFlaskRepoViewFileForktests(LocalBasetests):
|
|
Pierre-Yves Chibon |
12829b |
""" Tests for view_file endpoint of the flask pagure app for a fork """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def setUp(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
12829b |
super(PagureFlaskRepoViewFileForktests, self).setUp()
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
025aab |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
025aab |
|
|
Pierre-Yves Chibon |
025aab |
# Add some content to the git repo
|
|
Pierre-Yves Chibon |
025aab |
tests.add_content_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test.git")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
|
|
Pierre-Yves Chibon |
025aab |
tests.add_binary_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test.git"), "test.jpg"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
025aab |
tests.add_binary_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "test.git"), "test_binary"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
025aab |
|
|
Pierre-Yves Chibon |
12829b |
# Add a fork of a fork
|
|
Pierre-Yves Chibon |
12829b |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
12829b |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
name="test",
|
|
Pierre-Yves Chibon |
73d120 |
description="test project #3",
|
|
Pierre-Yves Chibon |
12829b |
is_fork=True,
|
|
Pierre-Yves Chibon |
12829b |
parent_id=1,
|
|
Pierre-Yves Chibon |
73d120 |
hook_token="aaabbbppp",
|
|
Pierre-Yves Chibon |
12829b |
)
|
|
Pierre-Yves Chibon |
12829b |
self.session.add(item)
|
|
Pierre-Yves Chibon |
12829b |
self.session.commit()
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
tests.add_content_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "forks", "pingou", "test.git")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
tests.add_readme_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "forks", "pingou", "test.git")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
tests.add_commit_git_repo(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "forks", "pingou", "test.git"),
|
|
Pierre-Yves Chibon |
73d120 |
ncommits=10,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_nested_file_in_fork(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file with a nested file in fork. """
|
|
Pierre-Yves Chibon |
12829b |
# Verify the nav links correctly when viewing a file/folder in a fork.
|
|
Pierre-Yves Chibon |
12829b |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/fork/pingou/test/blob/master/f/folder1/folder2/file"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
77bdcd |
'
|
|
Pierre-Yves Chibon |
77bdcd |
'href="/fork/pingou/test/blob/master/f/folder1/folder2">'
|
|
Pierre-Yves Chibon |
77bdcd |
'\n folder2'
|
|
Pierre-Yves Chibon |
73d120 |
"\n ",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_in_branch_in_fork(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file in a specific branch of a fork. """
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/fork/pingou/test/blob/master/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Ryan Lerch |
9fe1c6 |
''
|
|
Pierre-Yves Chibon |
73d120 |
"foo\n barRow 0\n"
|
|
Pierre-Yves Chibon |
73d120 |
"Row 1\nRow 2\nRow 3\nRow 4\nRow 5\nRow 6\nRow 7\nRow 8\n"
|
|
Pierre-Yves Chibon |
73d120 |
"Row 9\n",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
2d9829 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_fork_and_edit_on_fork_logged_out(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file on a text file on a fork when logged out. """
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# not logged in, no edit button but fork & edit is there
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/fork/pingou/test/blob/master/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
12829b |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
12829b |
'
|
|
Pierre-Yves Chibon |
12829b |
'href="/test/edit/master/f/sources" title="Edit file">'
|
|
Pierre-Yves Chibon |
73d120 |
"Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
36de81 |
'<button class="btn btn-sm btn-secondary fork_project_btn">'</button>
|
|
Julen Landa Alustiza |
0cafab |
"\n Fork and Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_fork_and_edit_on_your_fork(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file on a text file on your fork when logged in.
|
|
Pierre-Yves Chibon |
12829b |
"""
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# logged in, but it's your own fork, so just edit button is there
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/fork/pingou/test/blob/master/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
12829b |
'
|
|
Pierre-Yves Chibon |
025aab |
'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">'
|
|
Pierre-Yves Chibon |
73d120 |
"Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
36de81 |
'<button class="btn btn-sm btn-secondary fork_project_btn">'</button>
|
|
Julen Landa Alustiza |
0cafab |
"\n Fork and Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
def test_view_file_fork_and_edit_on_a_fork(self):
|
|
Pierre-Yves Chibon |
12829b |
""" Test the view_file on a text file on somone else's fork when
|
|
Pierre-Yves Chibon |
12829b |
logged in.
|
|
Pierre-Yves Chibon |
12829b |
"""
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
12829b |
# logged in, but it's not your fork, so only fork and edit button
|
|
Pierre-Yves Chibon |
12829b |
# is there
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/fork/pingou/test/blob/master/f/sources")
|
|
Pierre-Yves Chibon |
12829b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
12829b |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
12829b |
'
|
|
Pierre-Yves Chibon |
025aab |
'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">'
|
|
Pierre-Yves Chibon |
73d120 |
"Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
self.assertIn(
|
|
Pierre-Yves Chibon |
36de81 |
'<button class="btn btn-sm btn-secondary fork_project_btn">'</button>
|
|
Julen Landa Alustiza |
0cafab |
"\n Fork and Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
025aab |
def test_view_file_fork_and_edit_on_project(self):
|
|
Pierre-Yves Chibon |
025aab |
""" Test the view_file on a text file on somone else's fork when
|
|
Pierre-Yves Chibon |
025aab |
logged in.
|
|
Pierre-Yves Chibon |
025aab |
"""
|
|
Pierre-Yves Chibon |
025aab |
|
|
Pierre-Yves Chibon |
025aab |
# logged in and seeing the project you forked
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/blob/master/f/sources")
|
|
Pierre-Yves Chibon |
025aab |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
025aab |
self.assertIn(
|
|
Pierre-Yves Chibon |
025aab |
'
|
|
Pierre-Yves Chibon |
025aab |
'href="/test/edit/master/f/sources" title="Edit file">'
|
|
Pierre-Yves Chibon |
73d120 |
"Edit",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
025aab |
self.assertIn(
|
|
Pierre-Yves Chibon |
36de81 |
'<button class="btn btn-sm btn-secondary fork_project_btn">'</button>
|
|
Julen Landa Alustiza |
0cafab |
"\n Edit in your fork",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
025aab |
|
|
Pierre-Yves Chibon |
12829b |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
12829b |
unittest.main(verbosity=2)
|