|
Pierre-Yves Chibon |
180887 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
"""
|
|
Pierre-Yves Chibon |
9071b6 |
(c) 2015-2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
Authors:
|
|
Pierre-Yves Chibon |
180887 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
"""
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
180887 |
import unittest
|
|
Pierre-Yves Chibon |
180887 |
import sys
|
|
Pierre-Yves Chibon |
180887 |
import os
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
from mock import patch
|
|
Pierre-Yves Chibon |
180887 |
|
|
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 |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
import tests
|
|
Pierre-Yves Chibon |
930073 |
import pagure.config
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
|
|
Clement Verna |
109c4b |
class PagureFlaskPluginPagureHooktests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Tests for pagure_hook plugin of pagure """
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
def setUp(self):
|
|
Pierre-Yves Chibon |
180887 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
fe5017 |
super(PagureFlaskPluginPagureHooktests, self).setUp()
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"))
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos", "docs"))
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
e6f2ec |
def tearDown(self):
|
|
Pierre-Yves Chibon |
e6f2ec |
""" Tear Down the environment after the tests. """
|
|
Pierre-Yves Chibon |
e6f2ec |
super(PagureFlaskPluginPagureHooktests, self).tearDown()
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["DOCS_FOLDER"] = None
|
|
Pierre-Yves Chibon |
e6f2ec |
|
|
Pierre-Yves Chibon |
8c7787 |
def test_plugin_mail_page(self):
|
|
Pierre-Yves Chibon |
8c7787 |
""" Test the default page of the pagure hook plugin. """
|
|
Pierre-Yves Chibon |
180887 |
|
|
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")
|
|
Pierre-Yves Chibon |
180887 |
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 |
73d120 |
"<title>Settings Pagure - test - Pagure</title>", 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 |
180887 |
|
|
Pierre-Yves Chibon |
8c7787 |
def test_plugin_mail_no_data(self):
|
|
Pierre-Yves Chibon |
8c7787 |
""" Test the pagure hook plugin endpoint when no data is sent. """
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
data = {}
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/test/settings/Pagure", data=data)
|
|
Pierre-Yves Chibon |
180887 |
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 |
73d120 |
"<title>Settings Pagure - test - Pagure</title>", 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 |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "docs", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
8c7787 |
def test_plugin_mail_no_data_csrf(self):
|
|
Pierre-Yves Chibon |
8c7787 |
""" Test the pagure hook plugin endpoint when no data is sent but
|
|
Pierre-Yves Chibon |
8c7787 |
the csrf token.
|
|
Pierre-Yves Chibon |
8c7787 |
"""
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
8c7787 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos", "docs"))
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "repos", "requests")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
180887 |
# With the git repo
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/settings/Pagure", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
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 |
73d120 |
"Project Settings\n",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Hook Pagure deactivated", output_text)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/settings/Pagure")
|
|
Pierre-Yves Chibon |
180887 |
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 |
73d120 |
"<title>Settings Pagure - test - Pagure</title>", 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 |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path,
|
|
Pierre-Yves Chibon |
73d120 |
"repos",
|
|
Pierre-Yves Chibon |
73d120 |
"test.git",
|
|
Pierre-Yves Chibon |
73d120 |
"hooks",
|
|
Pierre-Yves Chibon |
73d120 |
"post-receive.pagure",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "docs", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
8c7787 |
def test_plugin_mail_activate_hook(self):
|
|
Pierre-Yves Chibon |
8c7787 |
""" Test the pagure hook plugin endpoint when activating the hook.
|
|
Pierre-Yves Chibon |
8c7787 |
"""
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["DOCS_FOLDER"] = os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "docs"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
8c7787 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
d7106c |
|
|
Pierre-Yves Chibon |
180887 |
# Activate hook
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token, "active": "y"}
|
|
Pierre-Yves Chibon |
180887 |
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/settings/Pagure", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
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 |
73d120 |
"Project Settings\n",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Hook Pagure activated", output_text)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/settings/Pagure")
|
|
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 |
73d120 |
"<title>Settings Pagure - test - Pagure</title>", 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 |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path,
|
|
Pierre-Yves Chibon |
73d120 |
"repos",
|
|
Pierre-Yves Chibon |
73d120 |
"docs",
|
|
Pierre-Yves Chibon |
73d120 |
"test.git",
|
|
Pierre-Yves Chibon |
73d120 |
"hooks",
|
|
Pierre-Yves Chibon |
73d120 |
"post-receive",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
8c7787 |
def test_plugin_mail_deactivate_hook(self):
|
|
Pierre-Yves Chibon |
8c7787 |
""" Test the pagure hook plugin endpoint when activating the hook.
|
|
Pierre-Yves Chibon |
8c7787 |
"""
|
|
Pierre-Yves Chibon |
8c7787 |
self.test_plugin_mail_activate_hook()
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
8c7787 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
d7106c |
|
|
Pierre-Yves Chibon |
180887 |
# De-Activate hook
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
1e4803 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/settings/Pagure", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
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 |
73d120 |
"Project Settings\n",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Hook Pagure deactivated", output_text)
|
|
Pierre-Yves Chibon |
1e4803 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/settings/Pagure")
|
|
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 |
73d120 |
"<title>Settings Pagure - test - Pagure</title>", 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 |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path,
|
|
Pierre-Yves Chibon |
73d120 |
"repos",
|
|
Pierre-Yves Chibon |
73d120 |
"test.git",
|
|
Pierre-Yves Chibon |
73d120 |
"hooks",
|
|
Pierre-Yves Chibon |
73d120 |
"post-receive.pagure",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path,
|
|
Pierre-Yves Chibon |
73d120 |
"repos",
|
|
Pierre-Yves Chibon |
73d120 |
"docs",
|
|
Pierre-Yves Chibon |
73d120 |
"test.git",
|
|
Pierre-Yves Chibon |
73d120 |
"hooks",
|
|
Pierre-Yves Chibon |
73d120 |
"post-receive",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict("pagure.config.config", {"DOCS_FOLDER": None})
|
|
Pierre-Yves Chibon |
8c7787 |
def test_plugin_mail_activate_hook_no_doc(self):
|
|
Pierre-Yves Chibon |
8c7787 |
""" Test the pagure hook plugin endpoint when activating the hook
|
|
Pierre-Yves Chibon |
8c7787 |
on a pagure instance that de-activated the doc repos.
|
|
Pierre-Yves Chibon |
8c7787 |
"""
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
8c7787 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
8c7787 |
# Activate hook
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token, "active": "y"}
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
8c7787 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/settings/Pagure", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Hook Pagure activated", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "docs", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict("pagure.config.config", {"DOCS_FOLDER": None})
|
|
Pierre-Yves Chibon |
8c7787 |
def test_plugin_mail_deactivate_hook_no_doc(self):
|
|
Pierre-Yves Chibon |
8c7787 |
""" Test the pagure hook plugin endpoint when activating then
|
|
Pierre-Yves Chibon |
8c7787 |
deactivating the hook on a pagure instance that de-activated the
|
|
Pierre-Yves Chibon |
8c7787 |
doc repos.
|
|
Pierre-Yves Chibon |
8c7787 |
"""
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="pingou")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
8c7787 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
8c7787 |
# Activate hook
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token, "active": "y"}
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
8c7787 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/settings/Pagure", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
8c7787 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
8c7787 |
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 activated", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "docs", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
8c7787 |
# Deactivate hook
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
8c7787 |
|
|
Pierre-Yves Chibon |
8c7787 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/settings/Pagure", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Hook Pagure deactivated", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path,
|
|
Pierre-Yves Chibon |
73d120 |
"repos",
|
|
Pierre-Yves Chibon |
73d120 |
"test.git",
|
|
Pierre-Yves Chibon |
73d120 |
"hooks",
|
|
Pierre-Yves Chibon |
73d120 |
"post-receive.pagure",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.exists(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "docs", "test.git", "hooks", "post-receive"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|