# -*- 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() tests.reload_pagure(CONFIG) 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['EMAIL_SEND'] = False 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 tearDown(self): """ Tear down the environnment, after every tests. """ super(PagureFlaskRepoOldUrltests, self).tearDown() tests.reload_pagure(CONFIG) pagure.APP.config['EMAIL_SEND'] = False pagure.LOG.handlers = [] 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( '