Blame tests/test_pagure_flask_ui_plugins_irc.py

Pierre-Yves Chibon 382fd3
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
"""
Pierre-Yves Chibon 9071b6
 (c) 2015-2018 - Copyright Red Hat Inc
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
 Authors:
Pierre-Yves Chibon 382fd3
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
"""
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
Pierre-Yves Chibon 382fd3
import unittest
Pierre-Yves Chibon 382fd3
import sys
Pierre-Yves Chibon 382fd3
import os
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 382fd3
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
import tests
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
Clement Verna 109c4b
class PagureFlaskPluginIRCtests(tests.SimplePagureTest):
Pierre-Yves Chibon fe5017
    """ Tests for pagure_hook plugin of pagure """
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
    def test_plugin_mail(self):
Pierre-Yves Chibon 59394d
        """ Test the irc plugin on/off endpoint. """
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'))
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
        user = tests.FakeUser(username='pingou')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 382fd3
            output = self.app.get('/test/settings/IRC')
Pierre-Yves Chibon 382fd3
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings IRC - test - Pagure</title>', output_text)
Aurélien Bompard 626417
            self.assertIn(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 382fd3
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 382fd3
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
            data = {}
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
            output = self.app.post('/test/settings/IRC', data=data)
Pierre-Yves Chibon 382fd3
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings IRC - test - Pagure</title>', output_text)
Aurélien Bompard 626417
            self.assertIn(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 899d15
            self.assertFalse(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
Pierre-Yves Chibon 899d15
Pierre-Yves Chibon 382fd3
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
            # With the git repo
Pierre-Yves Chibon 1e4803
            output = self.app.post(
Pierre-Yves Chibon 1e4803
                '/test/settings/IRC', data=data, follow_redirects=True)
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 4beb7c
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 9071b6
                'Project Settings\n', output_text)
Aurélien Bompard 626417
            self.assertIn(
Ryan Lerch 90916a
                'Hook IRC deactivated', output_text)
Pierre-Yves Chibon 1e4803
Pierre-Yves Chibon 1e4803
            output = self.app.get('/test/settings/IRC')
Pierre-Yves Chibon 382fd3
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings IRC - test - Pagure</title>', output_text)
Aurélien Bompard 626417
            self.assertIn(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 899d15
            self.assertFalse(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
Pierre-Yves Chibon 899d15
Pierre-Yves Chibon 382fd3
            # Activate hook
Pierre-Yves Chibon 382fd3
            data = {
Pierre-Yves Chibon 382fd3
                'csrf_token': csrf_token,
Pierre-Yves Chibon 382fd3
                'active': 'y',
Pierre-Yves Chibon 382fd3
                'server': 'irc.freenode.net',
Pierre-Yves Chibon 382fd3
                'port': 6667,
Pierre-Yves Chibon 382fd3
                'room': '#fedora-apps',
Pierre-Yves Chibon 382fd3
            }
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 1e4803
            output = self.app.post(
Pierre-Yves Chibon 1e4803
                '/test/settings/IRC', data=data, follow_redirects=True)
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 4beb7c
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 9071b6
                'Project Settings\n', output_text)
Aurélien Bompard 626417
            self.assertIn(
Ryan Lerch 90916a
                'Hook IRC activated', output_text)
Pierre-Yves Chibon 1e4803
Pierre-Yves Chibon 1e4803
            output = self.app.get('/test/settings/IRC')
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings IRC - test - Pagure</title>', output_text)
Aurélien Bompard 626417
            self.assertIn(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 899d15
            # TODO: Fix this
Pierre-Yves Chibon 899d15
            #self.assertTrue(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                #self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
Pierre-Yves Chibon 899d15
Pierre-Yves Chibon 382fd3
            # De-Activate hook
Pierre-Yves Chibon 382fd3
            data = {'csrf_token': csrf_token}
Pierre-Yves Chibon 1e4803
            output = self.app.post('/test/settings/IRC', data=data, follow_redirects=True)
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 4beb7c
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 9071b6
                'Project Settings\n', output_text)
Aurélien Bompard 626417
            self.assertIn(
Ryan Lerch 90916a
                'Hook IRC deactivated', output_text)
Pierre-Yves Chibon 1e4803
Pierre-Yves Chibon 1e4803
            output = self.app.get('/test/settings/IRC')
Pierre-Yves Chibon 1e4803
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '<title>Settings IRC - test - Pagure</title>', output_text)
Aurélien Bompard 626417
            self.assertIn(
Ryan Lerch 014c1c
                '
Aurélien Bompard 626417
                'type="checkbox" value="y">', output_text)
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 899d15
            self.assertFalse(os.path.exists(os.path.join(
Patrick Uiterwijk 170974
                self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
Pierre-Yves Chibon 899d15
Pierre-Yves Chibon 382fd3
Pierre-Yves Chibon 382fd3
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)