Blame tests/test_pagure_flask_ui_plugins_rtd_hook.py

Pierre-Yves Chibon 7a8384
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
"""
Pierre-Yves Chibon 9071b6
 (c) 2016-2018 - Copyright Red Hat Inc
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
 Authors:
Pierre-Yves Chibon 7a8384
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
"""
Pierre-Yves Chibon 7a8384
Aurélien Bompard dcf6f6
from __future__ import unicode_literals
Aurélien Bompard dcf6f6
Pierre-Yves Chibon 7a8384
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 7a8384
import unittest
Pierre-Yves Chibon 7a8384
import shutil
Pierre-Yves Chibon 7a8384
import sys
Pierre-Yves Chibon 7a8384
import os
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 7a8384
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
import pagure.lib
Pierre-Yves Chibon 7a8384
import tests
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
Clement Verna 109c4b
class PagureFlaskPluginRtdHooktests(tests.SimplePagureTest):
Pierre-Yves Chibon 7a8384
    """ Tests for rtd_hook plugin of pagure """
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
    def test_plugin_pagure_request(self):
Pierre-Yves Chibon 7a8384
        """ Test the pagure_request plugin on/off endpoint. """
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'))
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
        user = tests.FakeUser(username='pingou')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 7a8384
            output = self.app.get('/test/settings/Read the Doc')
Pierre-Yves Chibon 7a8384
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Read the Doc - test - Pagure</title>',
Pierre-Yves Chibon 9071b6
                output_text)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Clement Verna 2c8224
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 7a8384
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 7a8384
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            data = {}
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            output = self.app.post('/test/settings/Read the Doc', data=data)
Pierre-Yves Chibon 7a8384
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Read the Doc - test - Pagure</title>',
Pierre-Yves Chibon 9071b6
                output_text)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Clement Verna 2c8224
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 3f60e3
            # Create the requests repo
Jeremy Cline 20109f
            tests.create_projects_git(os.path.join(self.path, 'requests'))
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            output = self.app.post(
Pierre-Yves Chibon 7a8384
                '/test/settings/Read the Doc', data=data,
Pierre-Yves Chibon 7a8384
                follow_redirects=True)
Pierre-Yves Chibon 7a8384
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 9071b6
                'Project Settings\n', output_text)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Ryan Lerch 90916a
                'Hook Read the Doc deactivated',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            output = self.app.get('/test/settings/Read the Doc')
Pierre-Yves Chibon 7a8384
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Read the Doc - test - Pagure</title>',
Pierre-Yves Chibon 9071b6
                output_text)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Clement Verna 2c8224
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            self.assertFalse(os.path.exists(os.path.join(
Jeremy Cline 20109f
                self.path, 'requests', 'test.git', 'hooks',
Pierre-Yves Chibon 7a8384
                'post-receive.pagure')))
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            # Activate hook
Pierre-Yves Chibon 7a8384
            data = {
Pierre-Yves Chibon 7a8384
                'csrf_token': csrf_token,
Pierre-Yves Chibon 7a8384
                'active': 'y',
Pierre-Yves Chibon 7a8384
                'project_name': 'foo',
Pierre-Yves Chibon 7a8384
            }
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            output = self.app.post(
Pierre-Yves Chibon 7a8384
                '/test/settings/Read the Doc', data=data,
Pierre-Yves Chibon 7a8384
                follow_redirects=True)
Pierre-Yves Chibon 7a8384
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 9071b6
                'Project Settings\n', output_text)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Ryan Lerch 90916a
                'Hook Read the Doc activated',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            output = self.app.get('/test/settings/Read the Doc')
Pierre-Yves Chibon 7a8384
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Read the Doc - test - Pagure</title>',
Pierre-Yves Chibon 9071b6
                output_text)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Clement Verna 2c8224
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            self.assertTrue(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks',
Pierre-Yves Chibon 7a8384
                'post-receive.rtd')))
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            # De-Activate hook
Pierre-Yves Chibon 7a8384
            data = {'csrf_token': csrf_token}
Pierre-Yves Chibon 7a8384
            output = self.app.post(
Pierre-Yves Chibon 7a8384
                '/test/settings/Read the Doc', data=data,
Pierre-Yves Chibon 7a8384
                follow_redirects=True)
Pierre-Yves Chibon 7a8384
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 9071b6
                'Project Settings\n', output_text)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Ryan Lerch 90916a
                'Hook Read the Doc deactivated',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            output = self.app.get('/test/settings/Read the Doc')
Pierre-Yves Chibon 7a8384
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings Read the Doc - test - Pagure</title>',
Pierre-Yves Chibon 9071b6
                output_text)
Pierre-Yves Chibon 7a8384
            self.assertIn(
Clement Verna 2c8224
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            self.assertFalse(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks',
Pierre-Yves Chibon 7a8384
                'post-receive.rtd')))
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            # Try re-activate hook w/o the git repo
Pierre-Yves Chibon 7a8384
            data = {
Pierre-Yves Chibon 7a8384
                'csrf_token': csrf_token,
Pierre-Yves Chibon 7a8384
                'active': 'y',
Pierre-Yves Chibon 7a8384
                'project_name': 'foo',
Pierre-Yves Chibon 7a8384
            }
Patrick Uiterwijk 170974
            shutil.rmtree(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
            output = self.app.post('/test/settings/Read the Doc', data=data)
Pierre-Yves Chibon 7a8384
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
Pierre-Yves Chibon 7a8384
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)