From 1d1633d9f7abd664c681914c1c7250b1838acd72 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 14 2016 10:18:24 +0000 Subject: Move the tests for the old url scheme for commits to a new file This allows using a dedicated configuration file allowing the old style URL schema which cannot be changed once the application is loaded. --- diff --git a/tests/test_config b/tests/test_config new file mode 100644 index 0000000..cac6d7d --- /dev/null +++ b/tests/test_config @@ -0,0 +1 @@ +OLD_VIEW_COMMIT_ENABLED = True diff --git a/tests/test_pagure_flask_ui_old_commit.py b/tests/test_pagure_flask_ui_old_commit.py new file mode 100644 index 0000000..33b7116 --- /dev/null +++ b/tests/test_pagure_flask_ui_old_commit.py @@ -0,0 +1,200 @@ +# -*- coding: utf-8 -*- + +""" + (c) 2016 - Copyright Red Hat Inc + + Authors: + Pierre-Yves Chibon + +""" + +__requires__ = ['SQLAlchemy >= 0.8'] +import pkg_resources + +import datetime +import json +import unittest +import shutil +import sys +import tempfile +import os + +import pygit2 +from mock import patch + +sys.path.insert(0, os.path.join(os.path.dirname( + os.path.abspath(__file__)), '..')) + +HERE = os.path.join(os.path.dirname(os.path.abspath(__file__))) +CONFIG = os.path.join(HERE, 'test_config') + +os.environ['PAGURE_CONFIG'] = CONFIG + +import pagure.lib +import tests +from pagure.lib.repo import PagureRepo + + +class PagureFlaskRepoOldUrltests(tests.Modeltests): + """ Tests for flask app controller of pagure """ + + def setUp(self): + """ Set up the environnment, ran before every tests. """ + super(PagureFlaskRepoOldUrltests, self).setUp() + + pagure.APP.config['TESTING'] = True + pagure.SESSION = self.session + pagure.ui.SESSION = self.session + pagure.ui.app.SESSION = self.session + pagure.ui.filters.SESSION = self.session + pagure.ui.repo.SESSION = self.session + + pagure.APP.config['OLD_VIEW_COMMIT_ENABLED'] = True + pagure.APP.config['GIT_FOLDER'] = tests.HERE + pagure.APP.config['FORK_FOLDER'] = os.path.join( + tests.HERE, 'forks') + pagure.APP.config['REQUESTS_FOLDER'] = os.path.join( + tests.HERE, 'requests') + pagure.APP.config['TICKETS_FOLDER'] = os.path.join( + tests.HERE, 'tickets') + pagure.APP.config['DOCS_FOLDER'] = os.path.join( + tests.HERE, 'docs') + pagure.APP.config['UPLOAD_FOLDER_PATH'] = os.path.join( + tests.HERE, 'releases') + self.app = pagure.APP.test_client() + + def test_view_commit_old(self): + """ Test the view_commit_old endpoint. """ + + tests.create_projects(self.session) + tests.create_projects_git(tests.HERE, bare=True) + + # Add a README to the git repo - First commit + tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git')) + repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git')) + commit = repo.revparse_single('HEAD') + + # View first commit + output = self.app.get('/test/%s' % commit.oid.hex) + self.assertEqual(output.status_code, 302) + + output = self.app.get( + '/test/%s' % commit.oid.hex, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertTrue( + '