Commit 35ffe0a Add test for running git blame file on a file at a tag

1 file Authored and Committed by pingou 3 months ago
Add test for running git blame file on a file at a tag

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>

    
 1 @@ -2468,6 +2468,39 @@
 2           self.assertIn(
 3               '<td class="cell2"><pre> barRow 0</pre></td>', output.data)
 4   
 5 +     def test_view_blame_file_on_tag(self):
 6 +         """ Test the view_blame_file endpoint. """
 7 + 
 8 +         regex = re.compile('>(\w+)</a></td>\n<td class="cell2">')
 9 +         tests.create_projects(self.session)
10 +         tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
11 +         # Add some content to the git repo
12 +         tests.add_content_git_repo(
13 +             os.path.join(self.path, 'repos', 'test.git'))
14 +         tests.add_readme_git_repo(
15 +             os.path.join(self.path, 'repos', 'test.git'))
16 + 
17 +         # add a tag to the git repo
18 +         repo = pygit2.Repository(
19 +             os.path.join(self.path, 'repos', 'test.git'))
20 +         commit = repo[repo.head.target]
21 +         tagger = pygit2.Signature('Alice Doe', 'adoe@example.com', 12347, 0)
22 +         repo.create_tag(
23 +             'v1.0', commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger,
24 +             "Release v1.0")
25 + 
26 +         # View for tag v1.0
27 +         output = self.app.get('/test/blame/sources?identifier=v1.0')
28 +         self.assertEqual(output.status_code, 200)
29 +         self.assertIn(b'<table class="code_table">', output.data)
30 +         self.assertIn(
31 +             b'<tr><td class="cell1"><a id="1" href="#1" '
32 +             b'data-line-number="1"></a></td>', output.data)
33 +         self.assertIn(
34 +             b'<td class="cell2"><pre> bar</pre></td>', output.data)
35 +         data = regex.findall(output.data)
36 +         self.assertEqual(len(data), 2)
37 + 
38       def test_view_commit(self):
39           """ Test the view_commit endpoint. """
40           output = self.app.get('/foo/c/bar')