diff --git a/tests/test_progit_flask_ui_repo.py b/tests/test_progit_flask_ui_repo.py index 1c0d372..6e8a53f 100644 --- a/tests/test_progit_flask_ui_repo.py +++ b/tests/test_progit_flask_ui_repo.py @@ -1577,6 +1577,130 @@ index 0000000..fb7093d self.assertIn('', output.data) self.assertTrue(output.data.count('tagid'), 1) + def test_edit_file(self): + """ Test the edit_file endpoint. """ + + output = self.app.get('/foo/edit/foo/f/sources') + self.assertEqual(output.status_code, 302) + + user = tests.FakeUser() + with tests.user_set(pagure.APP, user): + # No project registered in the DB + output = self.app.get('/foo/edit/foo/f/sources') + self.assertEqual(output.status_code, 404) + + tests.create_projects(self.session) + + # No a repo admin + output = self.app.get('/test/edit/foo/f/sources') + self.assertEqual(output.status_code, 403) + + user.username = 'pingou' + with tests.user_set(pagure.APP, user): + + # No associated git repo + output = self.app.get('/test/edit/foo/f/sources') + self.assertEqual(output.status_code, 404) + + tests.create_projects_git(tests.HERE, bare=True) + + output = self.app.get('/test/edit/foo/f/sources') + self.assertEqual(output.status_code, 404) + + # Add some content to the git repo + tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git')) + tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git')) + tests.add_binary_git_repo( + os.path.join(tests.HERE, 'test.git'), 'test.jpg') + tests.add_binary_git_repo( + os.path.join(tests.HERE, 'test.git'), 'test_binary') + + output = self.app.get('/test/edit/master/foofile') + self.assertEqual(output.status_code, 404) + + # Edit page + output = self.app.get('/test/edit/master/f/sources') + self.assertEqual(output.status_code, 200) + self.assertIn( + 'master/sources', + output.data) + self.assertIn( + '