|
Pierre-Yves Chibon |
fd7da8 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
"""
|
|
Pierre-Yves Chibon |
fd7da8 |
(c) 2017 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
Authors:
|
|
Pierre-Yves Chibon |
fd7da8 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
"""
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
fd7da8 |
import unittest
|
|
Pierre-Yves Chibon |
fd7da8 |
import shutil
|
|
Pierre-Yves Chibon |
fd7da8 |
import sys
|
|
Pierre-Yves Chibon |
fd7da8 |
import tempfile
|
|
Pierre-Yves Chibon |
fd7da8 |
import os
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
from mock import patch, MagicMock
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
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 |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
import pagure
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
fd7da8 |
import tests
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Clement Verna |
109c4b |
class PagureFlaskGiveRepotests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
fd7da8 |
""" Tests for give a project on pagure """
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
def setUp(self):
|
|
Pierre-Yves Chibon |
fd7da8 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
fd7da8 |
super(PagureFlaskGiveRepotests, self).setUp()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["VIRUS_SCAN_ATTACHMENTS"] = False
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["UPLOAD_FOLDER_URL"] = "/releases/"
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["UPLOAD_FOLDER_PATH"] = os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "releases"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
73d120 |
self._check_user(user="pingou")
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
73d120 |
def _check_user(self, user="pingou"):
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, project_name="test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertEqual(project.user.user, user)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
def test_give_project_no_project(self):
|
|
Pierre-Yves Chibon |
fd7da8 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
# No such project
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/test42/give")
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
def test_give_project_no_csrf(self):
|
|
Pierre-Yves Chibon |
fd7da8 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "pingou"
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
# Missing CSRF
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foo"}
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Overview - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
def test_give_project_invalid_user(self):
|
|
Pierre-Yves Chibon |
fd7da8 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "pingou"
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
fd7da8 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
# Invalid user
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foobar", "csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0575a5 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"No such user foobar found ",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
6f43f3 |
def test_give_project_no_user(self):
|
|
Pierre-Yves Chibon |
6f43f3 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
6f43f3 |
|
|
Pierre-Yves Chibon |
6f43f3 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "pingou"
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
6f43f3 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
6f43f3 |
|
|
Pierre-Yves Chibon |
6f43f3 |
self._check_user()
|
|
Pierre-Yves Chibon |
6f43f3 |
|
|
Pierre-Yves Chibon |
6f43f3 |
# No user
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
6f43f3 |
|
|
Pierre-Yves Chibon |
6f43f3 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
6f43f3 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"No user specified ", output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
6f43f3 |
|
|
Pierre-Yves Chibon |
6f43f3 |
self._check_user()
|
|
Pierre-Yves Chibon |
6f43f3 |
|
|
Pierre-Yves Chibon |
fd7da8 |
def test_give_project_not_owner(self):
|
|
Pierre-Yves Chibon |
fd7da8 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "foo"
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
fd7da8 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
# User isn't the admin
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foo", "csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"You are not allowed to change the settings for this "
|
|
Pierre-Yves Chibon |
73d120 |
"project",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
def test_give_project_not_admin(self):
|
|
Pierre-Yves Chibon |
fd7da8 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "foo"
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
fd7da8 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
# User isn't the admin
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foo", "csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"You are not allowed to change the settings for this "
|
|
Pierre-Yves Chibon |
73d120 |
"project",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Lubomír Sedlář |
a25e58 |
def test_give_project_not_owner_but_is_admin(self):
|
|
Pierre-Yves Chibon |
fd7da8 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, project_name="test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.add_user_to_project(
|
|
Pierre-Yves Chibon |
fd7da8 |
self.session,
|
|
Pierre-Yves Chibon |
fd7da8 |
project=project,
|
|
Pierre-Yves Chibon |
73d120 |
new_user="foo",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
73d120 |
access="admin",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg, "User added")
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "foo"
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
fd7da8 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
# User isn't the owner
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foo", "csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"You are not allowed to give this project ",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
|
|
Pierre-Yves Chibon |
fd7da8 |
def test_give_project_not_owner_but_admin(self):
|
|
Pierre-Yves Chibon |
1544e0 |
""" Test the give_project endpoint.
|
|
Pierre-Yves Chibon |
1544e0 |
|
|
Pierre-Yves Chibon |
1544e0 |
Test giving a project when the person giving the project is a pagure
|
|
Pierre-Yves Chibon |
1544e0 |
admin (instance wide admin) but not a project admin.
|
|
Pierre-Yves Chibon |
1544e0 |
"""
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "foo"
|
|
Pierre-Yves Chibon |
fd7da8 |
user.cla_done = True
|
|
Pierre-Yves Chibon |
73d120 |
user.groups = ["foo"]
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
fd7da8 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
# User isn't the owner but is an instance admin
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foo", "csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"The project has been " "transferred to foo",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
73d120 |
self._check_user("foo")
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
|
|
Pierre-Yves Chibon |
fd7da8 |
def test_give_project(self):
|
|
Pierre-Yves Chibon |
fd7da8 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "pingou"
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
mprahl |
10dcea |
csrf_token = self.get_csrf()
|
|
mprahl |
10dcea |
|
|
mprahl |
10dcea |
self._check_user()
|
|
mprahl |
10dcea |
|
|
mprahl |
10dcea |
# All good
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foo", "csrf_token": csrf_token}
|
|
mprahl |
10dcea |
|
|
mprahl |
10dcea |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
mprahl |
10dcea |
self.assertEqual(output.status_code, 200)
|
|
mprahl |
10dcea |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"The project has been " "transferred to foo",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
mprahl |
10dcea |
|
|
Pierre-Yves Chibon |
73d120 |
self._check_user("foo")
|
|
mprahl |
10dcea |
# Make sure that the user giving the project is still an admin
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, project_name="test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
mprahl |
10dcea |
self.assertEqual(len(project.users), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(project.users[0].user, "pingou")
|
|
mprahl |
10dcea |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
|
|
mprahl |
10dcea |
def test_give_project_already_user(self):
|
|
mprahl |
10dcea |
""" Test the give_project endpoint when the new main_admin is already
|
|
mprahl |
10dcea |
a committer on the project. """
|
|
mprahl |
10dcea |
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query._get_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
pagure.lib.query.add_user_to_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session,
|
|
Pierre-Yves Chibon |
73d120 |
project,
|
|
Pierre-Yves Chibon |
73d120 |
new_user="foo",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
73d120 |
access="commit",
|
|
mprahl |
10dcea |
)
|
|
mprahl |
10dcea |
self.session.commit()
|
|
mprahl |
10dcea |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "pingou"
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
fd7da8 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
self._check_user()
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
# All good
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foo", "csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
fd7da8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fd7da8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"The project has been " "transferred to foo",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
73d120 |
self._check_user("foo")
|
|
mprahl |
8f40ee |
# Make sure that the user giving the project is still an admin
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, project_name="test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
mprahl |
8f40ee |
self.assertEqual(len(project.users), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(project.users[0].user, "pingou")
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config", {"REQUIRED_GROUPS": {"*": ["packager"]}}
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
|
|
Pierre-Yves Chibon |
411690 |
def test_give_project_not_in_required_group(self):
|
|
Pierre-Yves Chibon |
411690 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "pingou"
|
|
Pierre-Yves Chibon |
411690 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
411690 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
self._check_user()
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
# User not a packager
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foo", "csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
411690 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
411690 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
" This user must be in one of the following groups to "
|
|
Pierre-Yves Chibon |
73d120 |
"be allowed to be added to this project: packager",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
self._check_user(user="pingou")
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config", {"REQUIRED_GROUPS": {"*": ["packager"]}}
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
|
|
Pierre-Yves Chibon |
411690 |
def test_give_project_in_required_group(self):
|
|
Pierre-Yves Chibon |
411690 |
""" Test the give_project endpoint. """
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
# Create the packager group
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.add_group(
|
|
Pierre-Yves Chibon |
411690 |
self.session,
|
|
Pierre-Yves Chibon |
73d120 |
group_name="packager",
|
|
Pierre-Yves Chibon |
73d120 |
display_name="packager group",
|
|
Pierre-Yves Chibon |
411690 |
description=None,
|
|
Pierre-Yves Chibon |
73d120 |
group_type="user",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
411690 |
is_admin=False,
|
|
Pierre-Yves Chibon |
411690 |
blacklist=[],
|
|
Pierre-Yves Chibon |
411690 |
)
|
|
Pierre-Yves Chibon |
411690 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg, "User `pingou` added to the group `packager`.")
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
# Add foo to the packager group
|
|
Pierre-Yves Chibon |
73d120 |
group = pagure.lib.query.search_groups(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, group_name="packager"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.add_user_to_group(
|
|
Pierre-Yves Chibon |
411690 |
self.session,
|
|
Pierre-Yves Chibon |
73d120 |
username="foo",
|
|
Pierre-Yves Chibon |
411690 |
group=group,
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
411690 |
is_admin=False,
|
|
Pierre-Yves Chibon |
411690 |
)
|
|
Pierre-Yves Chibon |
411690 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg, "User `foo` added to the group `packager`.")
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
# pingou transferts test to foo
|
|
Pierre-Yves Chibon |
411690 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "pingou"
|
|
Pierre-Yves Chibon |
411690 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
411690 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
self._check_user()
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
# User not a packager
|
|
Pierre-Yves Chibon |
73d120 |
data = {"user": "foo", "csrf_token": csrf_token}
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
411690 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/give", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
411690 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
411690 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
" The project has been transferred to foo",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
73d120 |
self._check_user("foo")
|
|
Pierre-Yves Chibon |
411690 |
# Make sure that the user giving the project is still an admin
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, project_name="test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
411690 |
self.assertEqual(len(project.users), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(project.users[0].user, "pingou")
|
|
Pierre-Yves Chibon |
411690 |
|
|
Pierre-Yves Chibon |
fd7da8 |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
fd7da8 |
unittest.main(verbosity=2)
|