Blame tests/test_pagure_flask_ui_plugins_pagure_ci.py

farhaanbukhsh fbda94
# -*- coding: utf-8 -*-
farhaanbukhsh fbda94
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
farhaanbukhsh fbda94
import unittest
farhaanbukhsh fbda94
import sys
farhaanbukhsh fbda94
import os
farhaanbukhsh fbda94
Pierre-Yves Chibon 9c6dee
import mock
Pierre-Yves Chibon 9c6dee
Pierre-Yves Chibon 73d120
sys.path.insert(
Pierre-Yves Chibon 73d120
    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon 9c6dee
Pierre-Yves Chibon 9c6dee
import pagure.lib.tasks_services
farhaanbukhsh fbda94
import tests
farhaanbukhsh fbda94
farhaanbukhsh fbda94
Clement Verna 109c4b
class PagureFlaskPluginPagureCItests(tests.SimplePagureTest):
farhaanbukhsh fbda94
    """ Tests for flask plugins controller of pagure """
farhaanbukhsh fbda94
farhaanbukhsh fbda94
    def test_plugin_pagure_ci(self):
farhaanbukhsh fbda94
        """ Test the pagure ci plugin on/off endpoint. """
farhaanbukhsh fbda94
farhaanbukhsh fbda94
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"))
farhaanbukhsh fbda94
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="pingou")
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/test/settings/Pagure CI")
farhaanbukhsh fbda94
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
farhaanbukhsh fbda94
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - test - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Clement Verna 5434db
                '<label for="ci_url">URL to the project on the CI '</label>
Pierre-Yves Chibon 73d120
                "service",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Pierre-Yves Chibon 73d120
                '<label for="ci_job">Name of the job to trigger' "</label>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 5434db
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'name="active_commit" type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 926cdd
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'name="active_pr" type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
farhaanbukhsh fbda94
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 73d120
                'name="csrf_token" type="hidden" value="'
Pierre-Yves Chibon 73d120
            )[1].split('">')[0]
farhaanbukhsh fbda94
farhaanbukhsh fbda94
            data = {}
farhaanbukhsh fbda94
Pierre-Yves Chibon 73d120
            output = self.app.post("/test/settings/Pagure CI", data=data)
farhaanbukhsh fbda94
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
farhaanbukhsh fbda94
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - test - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Clement Verna 5434db
                '<label for="ci_url">URL to the project on the CI '</label>
Pierre-Yves Chibon 73d120
                "service",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Pierre-Yves Chibon 73d120
                '<label for="ci_job">Name of the job to trigger' "</label>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 5434db
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'name="active_commit" type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 926cdd
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'name="active_pr" type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
farhaanbukhsh fbda94
farhaanbukhsh fbda94
            # Activate hook
farhaanbukhsh fbda94
            data = {
Pierre-Yves Chibon 73d120
                "active_commit": "y",
Pierre-Yves Chibon 73d120
                "ci_url": "https://jenkins.fedoraproject.org",
Pierre-Yves Chibon 73d120
                "ci_type": "jenkins",
Pierre-Yves Chibon 73d120
                "ci_job": "test/job",
farhaanbukhsh fbda94
            }
Pierre-Yves Chibon 1e2f0d
            # CSRF Token missing
farhaanbukhsh fbda94
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/settings/Pagure CI", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - test - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Clement Verna 5434db
                '<label for="ci_url">URL to the project on the CI '</label>
Pierre-Yves Chibon 73d120
                "service",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Pierre-Yves Chibon 73d120
                '<label for="ci_job">Name of the job to trigger' "</label>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 5434db
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'name="active_commit" type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 926cdd
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'name="active_pr" type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
Pierre-Yves Chibon 73d120
            data["csrf_token"] = csrf_token
Pierre-Yves Chibon 1e2f0d
Pierre-Yves Chibon 1e2f0d
            # Activate hook
farhaanbukhsh fbda94
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/settings/Pagure CI", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
farhaanbukhsh fbda94
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
farhaanbukhsh fbda94
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9071b6
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("Hook Pagure CI activated", output_text)
farhaanbukhsh fbda94
Pierre-Yves Chibon 73d120
            output = self.app.get("/test/settings/Pagure CI")
farhaanbukhsh fbda94
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
farhaanbukhsh fbda94
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - test - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
farhaanbukhsh fbda94
            self.assertIn(
Clement Verna 5434db
                '<label for="ci_url">URL to the project on the CI '</label>
Pierre-Yves Chibon 73d120
                "service",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 5434db
            self.assertIn(
Pierre-Yves Chibon 73d120
                '<label for="ci_job">Name of the job to trigger' "</label>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 5434db
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'name="active_commit" type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7f3b76
            self.assertIn(
Pierre-Yves Chibon 73d120
                "
\nhttp://localhost.localdomain/api/0/ci/jenkins/test/",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
farhaanbukhsh fbda94
Pierre-Yves Chibon 1e2f0d
            # De-activate the hook
Pierre-Yves Chibon 73d120
            data = {"csrf_token": csrf_token}
farhaanbukhsh fbda94
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/settings/Pagure CI", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
farhaanbukhsh fbda94
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
farhaanbukhsh fbda94
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("Hook Pagure CI deactivated", output_text)
farhaanbukhsh fbda94
Pierre-Yves Chibon 73d120
            output = self.app.get("/test/settings/Pagure CI")
Pierre-Yves Chibon 1e2f0d
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
farhaanbukhsh fbda94
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - test - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Clement Verna 5434db
                '<label for="ci_url">URL to the project on the CI '</label>
Pierre-Yves Chibon 73d120
                "service",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Pierre-Yves Chibon 73d120
                '<label for="ci_job">Name of the job to trigger' "</label>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 5434db
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'name="active_commit" type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 1e2f0d
Pierre-Yves Chibon 1e2f0d
            # Missing the required ci_url
Pierre-Yves Chibon 73d120
            data = {"csrf_token": csrf_token, "active_commit": "y"}
farhaanbukhsh fbda94
farhaanbukhsh fbda94
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/settings/Pagure CI", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
farhaanbukhsh fbda94
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
farhaanbukhsh fbda94
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - test - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertNotIn("Hook Pagure CI activated", output_text)
Pierre-Yves Chibon 3e9b1d
Pierre-Yves Chibon 3e9b1d
            if self.get_wtforms_version() >= (2, 2):
Pierre-Yves Chibon 3e9b1d
                self.assertIn(
Pierre-Yves Chibon 7a5ac6
                    '
\n '
Pierre-Yves Chibon 7a5ac6
                    '
Pierre-Yves Chibon 7a5ac6
                    'required type="text" value="">\n    \n  \n      '
Pierre-Yves Chibon 7a5ac6
                    '
This field is required.
',
Pierre-Yves Chibon 73d120
                    output_text,
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 3e9b1d
                self.assertIn(
Pierre-Yves Chibon 7a5ac6
                    '
\n '
Pierre-Yves Chibon 7a5ac6
                    '
Pierre-Yves Chibon 7a5ac6
                    'required type="text" value="">\n    \n  \n      '
Pierre-Yves Chibon 7a5ac6
                    '
This field is required.
',
Pierre-Yves Chibon 73d120
                    output_text,
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 3e9b1d
            else:
Pierre-Yves Chibon 3e9b1d
                self.assertIn(
Ryan Lerch 014c1c
                    '
\n '
Ryan Lerch 014c1c
                    '
Ryan Lerch 014c1c
                    'type="text" value="">\n    \n  \n      '
Ryan Lerch 014c1c
                    '
This field is required.
',
Pierre-Yves Chibon 73d120
                    output_text,
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 3e9b1d
                self.assertIn(
Ryan Lerch 014c1c
                    '
\n '
Ryan Lerch 014c1c
                    '
Ryan Lerch 014c1c
                    'type="text" value="">\n    \n  \n      '
Ryan Lerch 014c1c
                    '
This field is required.
',
Pierre-Yves Chibon 73d120
                    output_text,
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 1e2f0d
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'name="active_commit" type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
farhaanbukhsh fbda94
Pierre-Yves Chibon 7f3b76
    def test_plugin_pagure_ci_namespaced(self):
Pierre-Yves Chibon 7f3b76
        """ Test the pagure ci plugin on/off endpoint. """
Pierre-Yves Chibon 7f3b76
Pierre-Yves Chibon 7f3b76
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"))
Pierre-Yves Chibon 7f3b76
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="pingou")
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/somenamespace/test3/settings/Pagure CI")
Pierre-Yves Chibon 7f3b76
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7f3b76
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - somenamespace/test3 - "</title>
Pierre-Yves Chibon 73d120
                "Pagure",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7f3b76
            self.assertIn(
Clement Verna 5434db
                '<label for="ci_url">URL to the project on the CI '</label>
Pierre-Yves Chibon 73d120
                "service",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7f3b76
            self.assertIn(
Pierre-Yves Chibon 73d120
                '<label for="ci_job">Name of the job to trigger' "</label>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 5434db
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7f3b76
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 73d120
                'name="csrf_token" type="hidden" value="'
Pierre-Yves Chibon 73d120
            )[1].split('">')[0]
Pierre-Yves Chibon 7f3b76
Pierre-Yves Chibon 7f3b76
            # Activate hook
Pierre-Yves Chibon 7f3b76
            data = {
Pierre-Yves Chibon 73d120
                "active_pr": "y",
Pierre-Yves Chibon 73d120
                "ci_url": "https://jenkins.fedoraproject.org",
Pierre-Yves Chibon 73d120
                "ci_job": "test/job",
Pierre-Yves Chibon 73d120
                "ci_type": "jenkins",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 7f3b76
            }
Pierre-Yves Chibon 7f3b76
Pierre-Yves Chibon 7f3b76
            # Activate hook
Pierre-Yves Chibon 7f3b76
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/somenamespace/test3/settings/Pagure CI",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7f3b76
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7f3b76
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7f3b76
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings - somenamespace/test3 - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Aurélien Bompard 626417
            self.assertIn(
Pierre-Yves Chibon 9071b6
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("Hook Pagure CI activated", output_text)
Pierre-Yves Chibon 7f3b76
Pierre-Yves Chibon 73d120
            output = self.app.get("/somenamespace/test3/settings/Pagure CI")
Pierre-Yves Chibon 7f3b76
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7f3b76
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - somenamespace/test3 - "</title>
Pierre-Yves Chibon 73d120
                "Pagure",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7f3b76
            self.assertIn(
Clement Verna 5434db
                '<label for="ci_url">URL to the project on the CI '</label>
Pierre-Yves Chibon 73d120
                "service",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Clement Verna 5434db
            self.assertIn(
Pierre-Yves Chibon 73d120
                '<label for="ci_job">Name of the job to trigger' "</label>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Aurélien Bompard 626417
            self.assertIn(
Ryan Lerch 014c1c
                '
Pierre-Yves Chibon 73d120
                'type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7f3b76
            self.assertIn(
Pierre-Yves Chibon 73d120
                "
\nhttp://localhost.localdomain/api/0/ci/jenkins/somenamespace/test3/",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7f3b76
Pierre-Yves Chibon 73d120
    @mock.patch("pagure.lib.tasks_services.trigger_jenkins_build")
Pierre-Yves Chibon 9c6dee
    def test_plugin_pagure_ci_namespaced_auth(self, trigger_jenk):
Pierre-Yves Chibon 9c6dee
        """ Test the pagure ci plugin on/off endpoint. """
Pierre-Yves Chibon 9c6dee
Pierre-Yves Chibon 9c6dee
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"))
Pierre-Yves Chibon 9c6dee
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="pingou")
Pierre-Yves Chibon 9c6dee
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/somenamespace/test3/settings/Pagure CI")
Pierre-Yves Chibon 9c6dee
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 9c6dee
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - somenamespace/test3 - "</title>
Pierre-Yves Chibon 73d120
                "Pagure",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 9c6dee
                '<label for="ci_url">URL to the project on the CI '</label>
Pierre-Yves Chibon 73d120
                "service",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 73d120
                '<label for="ci_job">Name of the job to trigger' "</label>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 9c6dee
                '
Pierre-Yves Chibon 73d120
                'type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
Pierre-Yves Chibon 9c6dee
            csrf_token = output_text.split(
Pierre-Yves Chibon 73d120
                'name="csrf_token" type="hidden" value="'
Pierre-Yves Chibon 73d120
            )[1].split('">')[0]
Pierre-Yves Chibon 9c6dee
Pierre-Yves Chibon 9c6dee
            # Activate hook
Pierre-Yves Chibon 9c6dee
            data = {
Pierre-Yves Chibon 73d120
                "active_pr": "y",
Pierre-Yves Chibon 73d120
                "ci_url": "https://jenkins.fedoraproject.org",
Pierre-Yves Chibon 73d120
                "ci_job": "test/job",
Pierre-Yves Chibon 73d120
                "ci_type": "jenkins",
Pierre-Yves Chibon 73d120
                "ci_username": "jenkins_username",
Pierre-Yves Chibon 73d120
                "ci_password": "jenkins_password",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 9c6dee
            }
Pierre-Yves Chibon 9c6dee
Pierre-Yves Chibon 9c6dee
            # Activate hook
Pierre-Yves Chibon 9c6dee
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/somenamespace/test3/settings/Pagure CI",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 9c6dee
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 9c6dee
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings - somenamespace/test3 - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 9c6dee
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("Hook Pagure CI activated", output_text)
Pierre-Yves Chibon 9c6dee
Pierre-Yves Chibon 73d120
            output = self.app.get("/somenamespace/test3/settings/Pagure CI")
Pierre-Yves Chibon 9c6dee
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 9c6dee
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Settings Pagure CI - somenamespace/test3 - "</title>
Pierre-Yves Chibon 73d120
                "Pagure",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 9c6dee
                '<label for="ci_url">URL to the project on the CI '</label>
Pierre-Yves Chibon 73d120
                "service",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 73d120
                '<label for="ci_job">Name of the job to trigger' "</label>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 9c6dee
                '
Pierre-Yves Chibon 73d120
                'type="checkbox" value="y">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
            self.assertIn(
Pierre-Yves Chibon 73d120
                "
\nhttp://localhost.localdomain/api/0/ci/jenkins/somenamespace/test3/",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 9c6dee
Pierre-Yves Chibon 9c6dee
        output = pagure.lib.tasks_services.trigger_ci_build(
Pierre-Yves Chibon 73d120
            project_name="somenamespace/test3",
Pierre-Yves Chibon 73d120
            cause="PR#ID",
Pierre-Yves Chibon 73d120
            branch="feature",
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            ci_type="jenkins",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 9c6dee
        self.assertIsNone(output)
Pierre-Yves Chibon 9c6dee
        trigger_jenk.assert_called_once_with(
Pierre-Yves Chibon 73d120
            branch="feature",
Pierre-Yves Chibon 73d120
            cause="PR#ID",
Pierre-Yves Chibon 73d120
            ci_password="jenkins_password",
Pierre-Yves Chibon 73d120
            ci_username="jenkins_username",
Pierre-Yves Chibon 73d120
            job="test/job",
Pierre-Yves Chibon 73d120
            project_path="somenamespace/test3.git",
Pierre-Yves Chibon 73d120
            token=mock.ANY,
Pierre-Yves Chibon 73d120
            url="https://jenkins.fedoraproject.org",
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 9c6dee
        )
Pierre-Yves Chibon 9c6dee
farhaanbukhsh fbda94
Pierre-Yves Chibon 73d120
if __name__ == "__main__":
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)