|
Pierre-Yves Chibon |
d4c9da |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
"""
|
|
Pierre-Yves Chibon |
ffbe63 |
(c) 2017-2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
Authors:
|
|
Pierre-Yves Chibon |
d4c9da |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
"""
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Aurélien Bompard |
dcf6f6 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
d4c9da |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
d4c9da |
import pkg_resources # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
87a6d0 |
import datetime # noqa
|
|
Pierre-Yves Chibon |
600fa7 |
import os # noqa
|
|
Pierre-Yves Chibon |
600fa7 |
import platform # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
import shutil # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
import subprocess # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
import sys # noqa
|
|
Pierre-Yves Chibon |
600fa7 |
import unittest # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
import munch # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
from mock import patch, MagicMock # noqa
|
|
Fabian Arrotin |
0096c9 |
from six import StringIO # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
d4c9da |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
b130e5 |
import pagure.config # noqa
|
|
Aurélien Bompard |
a29742 |
import pagure.exceptions # noqa: E402
|
|
Pierre-Yves Chibon |
d4c9da |
import pagure.cli.admin # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
import pagure.lib.model # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
import tests # noqa
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
class PagureAdminAdminTokenEmptytests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
d4c9da |
""" Tests for pagure-admin admin-token when there is nothing in the DB
|
|
Pierre-Yves Chibon |
d4c9da |
"""
|
|
Aurélien Bompard |
e78d79 |
|
|
Aurélien Bompard |
e78d79 |
populate_db = False
|
|
Aurélien Bompard |
e78d79 |
|
|
Pierre-Yves Chibon |
d4c9da |
def setUp(self):
|
|
Pierre-Yves Chibon |
d4c9da |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
d4c9da |
super(PagureAdminAdminTokenEmptytests, self).setUp()
|
|
Aurélien Bompard |
e78d79 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
def test_do_create_admin_token_no_user(self):
|
|
Pierre-Yves Chibon |
d4c9da |
""" Test the do_create_admin_token function of pagure-admin without
|
|
Pierre-Yves Chibon |
d4c9da |
user.
|
|
Pierre-Yves Chibon |
d4c9da |
"""
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({'user': "pingou"})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_create_admin_token(args)
|
|
Aurélien Bompard |
a29742 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'No user "pingou" found'
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
def test_do_list_admin_token_empty(self):
|
|
Pierre-Yves Chibon |
d4c9da |
""" Test the do_list_admin_token function of pagure-admin when there
|
|
Pierre-Yves Chibon |
d4c9da |
are not tokens in the db.
|
|
Pierre-Yves Chibon |
d4c9da |
"""
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Aurélien Bompard |
a29742 |
self.assertEqual(output, 'No admin tokens found\n')
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
ede948 |
class PagureAdminAdminRefreshGitolitetests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
ede948 |
""" Tests for pagure-admin refresh-gitolite """
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Aurélien Bompard |
e78d79 |
populate_db = False
|
|
Aurélien Bompard |
e78d79 |
|
|
Pierre-Yves Chibon |
ede948 |
def setUp(self):
|
|
Pierre-Yves Chibon |
ede948 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
ede948 |
super(PagureAdminAdminRefreshGitolitetests, self).setUp()
|
|
Aurélien Bompard |
e78d79 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
# Create the user pingou
|
|
Pierre-Yves Chibon |
ede948 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
ede948 |
user='pingou',
|
|
Pierre-Yves Chibon |
ede948 |
fullname='PY C',
|
|
Pierre-Yves Chibon |
ede948 |
password='foo',
|
|
Pierre-Yves Chibon |
ede948 |
default_email='bar@pingou.com',
|
|
Pierre-Yves Chibon |
ede948 |
)
|
|
Pierre-Yves Chibon |
ede948 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
ede948 |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
ede948 |
user_id=1,
|
|
Pierre-Yves Chibon |
ede948 |
email='bar@pingou.com')
|
|
Pierre-Yves Chibon |
ede948 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
ede948 |
self.session.commit()
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
# Create a couple of projects
|
|
Pierre-Yves Chibon |
ede948 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
# Add a group
|
|
Pierre-Yves Chibon |
ede948 |
msg = pagure.lib.add_group(
|
|
Pierre-Yves Chibon |
ede948 |
self.session,
|
|
Pierre-Yves Chibon |
ede948 |
group_name='foo',
|
|
Pierre-Yves Chibon |
ede948 |
display_name='foo group',
|
|
Pierre-Yves Chibon |
ede948 |
description=None,
|
|
Pierre-Yves Chibon |
ede948 |
group_type='bar',
|
|
Pierre-Yves Chibon |
ede948 |
user='pingou',
|
|
Pierre-Yves Chibon |
ede948 |
is_admin=False,
|
|
Pierre-Yves Chibon |
ede948 |
blacklist=[],
|
|
Pierre-Yves Chibon |
ede948 |
)
|
|
Pierre-Yves Chibon |
ede948 |
self.session.commit()
|
|
Pierre-Yves Chibon |
ede948 |
self.assertEqual(msg, 'User `pingou` added to the group `foo`.')
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
# Make the imported pagure use the correct db session
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.lib.git_auth.get_git_auth_helper')
|
|
Pierre-Yves Chibon |
ede948 |
def test_do_refresh_gitolite_no_args(self, get_helper, conf):
|
|
Pierre-Yves Chibon |
ede948 |
""" Test the do_generate_acl function with no special args. """
|
|
Pierre-Yves Chibon |
ede948 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
ede948 |
helper = MagicMock()
|
|
Pierre-Yves Chibon |
ede948 |
get_helper.return_value = helper
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
args = munch.Munch(
|
|
Pierre-Yves Chibon |
ede948 |
{'group': None, 'project': None, 'all_': False, 'user': None})
|
|
Pierre-Yves Chibon |
ede948 |
pagure.cli.admin.do_generate_acl(args)
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Patrick Uiterwijk |
ad0b72 |
get_helper.assert_called_with()
|
|
Pierre-Yves Chibon |
ede948 |
args = helper.generate_acls.call_args
|
|
Pierre-Yves Chibon |
ede948 |
self.assertIsNone(args[1].get('group'))
|
|
Pierre-Yves Chibon |
ede948 |
self.assertIsNone(args[1].get('project'))
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.lib.git_auth.get_git_auth_helper')
|
|
Pierre-Yves Chibon |
ede948 |
def test_do_refresh_gitolite_all_project(self, get_helper, conf):
|
|
Pierre-Yves Chibon |
ede948 |
""" Test the do_generate_acl function for all projects. """
|
|
Pierre-Yves Chibon |
ede948 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
ede948 |
helper = MagicMock()
|
|
Pierre-Yves Chibon |
ede948 |
get_helper.return_value = helper
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
args = munch.Munch(
|
|
Pierre-Yves Chibon |
ede948 |
{'group': None, 'project': None, 'all_': True, 'user': None})
|
|
Pierre-Yves Chibon |
ede948 |
pagure.cli.admin.do_generate_acl(args)
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Patrick Uiterwijk |
ad0b72 |
get_helper.assert_called_with()
|
|
Pierre-Yves Chibon |
ede948 |
args = helper.generate_acls.call_args
|
|
Pierre-Yves Chibon |
ede948 |
self.assertIsNone(args[1].get('group'))
|
|
Pierre-Yves Chibon |
ede948 |
self.assertEqual(args[1].get('project'), -1)
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.lib.git_auth.get_git_auth_helper')
|
|
Pierre-Yves Chibon |
ede948 |
def test_do_refresh_gitolite_one_project(self, get_helper, conf):
|
|
Pierre-Yves Chibon |
ede948 |
""" Test the do_generate_acl function for a certain project. """
|
|
Pierre-Yves Chibon |
ede948 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
ede948 |
helper = MagicMock()
|
|
Pierre-Yves Chibon |
ede948 |
get_helper.return_value = helper
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
args = munch.Munch(
|
|
Pierre-Yves Chibon |
ede948 |
{'group': None, 'project': 'test', 'all_': False, 'user': None})
|
|
Pierre-Yves Chibon |
ede948 |
pagure.cli.admin.do_generate_acl(args)
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Patrick Uiterwijk |
ad0b72 |
get_helper.assert_called_with()
|
|
Pierre-Yves Chibon |
ede948 |
args = helper.generate_acls.call_args
|
|
Pierre-Yves Chibon |
ede948 |
self.assertIsNone(args[1].get('group'))
|
|
Pierre-Yves Chibon |
ede948 |
self.assertEqual(args[1].get('project').fullname, 'test')
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.lib.git_auth.get_git_auth_helper')
|
|
Pierre-Yves Chibon |
ede948 |
def test_do_refresh_gitolite_one_project_and_all(self, get_helper, conf):
|
|
Pierre-Yves Chibon |
ede948 |
""" Test the do_generate_acl function for a certain project and all.
|
|
Pierre-Yves Chibon |
ede948 |
"""
|
|
Pierre-Yves Chibon |
ede948 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
ede948 |
helper = MagicMock()
|
|
Pierre-Yves Chibon |
ede948 |
get_helper.return_value = helper
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
args = munch.Munch(
|
|
Pierre-Yves Chibon |
ede948 |
{'group': None, 'project': 'test', 'all_': True, 'user': None})
|
|
Pierre-Yves Chibon |
ede948 |
pagure.cli.admin.do_generate_acl(args)
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Patrick Uiterwijk |
ad0b72 |
get_helper.assert_called_with()
|
|
Pierre-Yves Chibon |
ede948 |
args = helper.generate_acls.call_args
|
|
Pierre-Yves Chibon |
ede948 |
self.assertIsNone(args[1].get('group'))
|
|
Pierre-Yves Chibon |
ede948 |
self.assertEqual(args[1].get('project'), -1)
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
ede948 |
@patch('pagure.lib.git_auth.get_git_auth_helper')
|
|
Pierre-Yves Chibon |
ede948 |
def test_do_refresh_gitolite_one_group(self, get_helper, conf):
|
|
Pierre-Yves Chibon |
ede948 |
""" Test the do_generate_acl function for a certain group. """
|
|
Pierre-Yves Chibon |
ede948 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
ede948 |
helper = MagicMock()
|
|
Pierre-Yves Chibon |
ede948 |
get_helper.return_value = helper
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
args = munch.Munch(
|
|
Pierre-Yves Chibon |
ede948 |
{'group': 'foo', 'project': None, 'all_': False, 'user': None})
|
|
Pierre-Yves Chibon |
ede948 |
pagure.cli.admin.do_generate_acl(args)
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Patrick Uiterwijk |
ad0b72 |
get_helper.assert_called_with()
|
|
Pierre-Yves Chibon |
ede948 |
args = helper.generate_acls.call_args
|
|
Pierre-Yves Chibon |
ede948 |
self.assertEqual(args[1].get('group').group_name, 'foo')
|
|
Pierre-Yves Chibon |
ede948 |
self.assertIsNone(args[1].get('project'))
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
ede948 |
|
|
Pierre-Yves Chibon |
d4c9da |
class PagureAdminAdminTokentests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
d4c9da |
""" Tests for pagure-admin admin-token """
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Aurélien Bompard |
e78d79 |
populate_db = False
|
|
Aurélien Bompard |
e78d79 |
|
|
Pierre-Yves Chibon |
d4c9da |
def setUp(self):
|
|
Pierre-Yves Chibon |
d4c9da |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
d4c9da |
super(PagureAdminAdminTokentests, self).setUp()
|
|
Aurélien Bompard |
e78d79 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
# Create the user pingou
|
|
Pierre-Yves Chibon |
d4c9da |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
d4c9da |
user='pingou',
|
|
Pierre-Yves Chibon |
d4c9da |
fullname='PY C',
|
|
Pierre-Yves Chibon |
d4c9da |
password='foo',
|
|
Pierre-Yves Chibon |
d4c9da |
default_email='bar@pingou.com',
|
|
Pierre-Yves Chibon |
d4c9da |
)
|
|
Pierre-Yves Chibon |
d4c9da |
self.session.add(item)
|
|
Pierre-Yves Chibon |
d4c9da |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
d4c9da |
user_id=1,
|
|
Pierre-Yves Chibon |
d4c9da |
email='bar@pingou.com')
|
|
Pierre-Yves Chibon |
d4c9da |
self.session.add(item)
|
|
Pierre-Yves Chibon |
d4c9da |
self.session.commit()
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
# Make the imported pagure use the correct db session
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
@patch('pagure.cli.admin._get_input')
|
|
Pierre-Yves Chibon |
d4c9da |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
d4c9da |
def test_do_create_admin_token(self, conf, rinp):
|
|
Pierre-Yves Chibon |
d4c9da |
""" Test the do_create_admin_token function of pagure-admin. """
|
|
Pierre-Yves Chibon |
d4c9da |
conf.return_value = True
|
|
Pierre-Yves Chibon |
d4c9da |
rinp.return_value = '1,2,3'
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
args = munch.Munch({'user': 'pingou'})
|
|
Pierre-Yves Chibon |
d4c9da |
pagure.cli.admin.do_create_admin_token(args)
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
# Check the outcome
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
@patch('pagure.cli.admin._get_input')
|
|
Pierre-Yves Chibon |
d4c9da |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
9a36a4 |
def test_do_list_admin_token(self, conf, rinp):
|
|
Pierre-Yves Chibon |
9a36a4 |
""" Test the do_list_admin_token function of pagure-admin. """
|
|
Pierre-Yves Chibon |
9a36a4 |
# Create an admin token to use
|
|
Pierre-Yves Chibon |
9a36a4 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
9a36a4 |
rinp.return_value = '1,2,3'
|
|
Pierre-Yves Chibon |
9a36a4 |
|
|
Pierre-Yves Chibon |
9a36a4 |
args = munch.Munch({'user': 'pingou'})
|
|
Pierre-Yves Chibon |
9a36a4 |
pagure.cli.admin.do_create_admin_token(args)
|
|
Pierre-Yves Chibon |
9a36a4 |
|
|
Pierre-Yves Chibon |
9a36a4 |
# Retrieve all tokens
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
9a36a4 |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
9a36a4 |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
9a36a4 |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
9a36a4 |
|
|
Pierre-Yves Chibon |
9a36a4 |
# Retrieve pfrields's tokens
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': 'pfrields',
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
9a36a4 |
self.assertEqual(output, 'No admin tokens found\n')
|
|
Pierre-Yves Chibon |
9a36a4 |
|
|
Pierre-Yves Chibon |
f3c6b4 |
def test_do_list_admin_token_non_admin_acls(self):
|
|
Pierre-Yves Chibon |
f3c6b4 |
""" Test the do_list_admin_token function of pagure-admin for a token
|
|
Pierre-Yves Chibon |
f3c6b4 |
without any admin ACL. """
|
|
Pierre-Yves Chibon |
f3c6b4 |
pagure.lib.add_token_to_user(
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.session,
|
|
Pierre-Yves Chibon |
f3c6b4 |
project=None,
|
|
Pierre-Yves Chibon |
f3c6b4 |
acls=['issue_assign', 'pull_request_subscribe'],
|
|
Pierre-Yves Chibon |
f3c6b4 |
username='pingou')
|
|
Pierre-Yves Chibon |
f3c6b4 |
|
|
Pierre-Yves Chibon |
f3c6b4 |
# Retrieve all admin tokens
|
|
Pierre-Yves Chibon |
f3c6b4 |
list_args = munch.Munch({
|
|
Pierre-Yves Chibon |
f3c6b4 |
'user': None,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'token': None,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'active': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
})
|
|
Pierre-Yves Chibon |
f3c6b4 |
with tests.capture_output() as output:
|
|
Pierre-Yves Chibon |
f3c6b4 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Pierre-Yves Chibon |
f3c6b4 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.assertEqual(output, 'No admin tokens found\n')
|
|
Pierre-Yves Chibon |
f3c6b4 |
|
|
Pierre-Yves Chibon |
f3c6b4 |
# Retrieve all tokens
|
|
Pierre-Yves Chibon |
f3c6b4 |
list_args = munch.Munch({
|
|
Pierre-Yves Chibon |
f3c6b4 |
'user': None,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'token': None,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'active': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': True,
|
|
Pierre-Yves Chibon |
f3c6b4 |
})
|
|
Pierre-Yves Chibon |
f3c6b4 |
with tests.capture_output() as output:
|
|
Pierre-Yves Chibon |
f3c6b4 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Pierre-Yves Chibon |
f3c6b4 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
f3c6b4 |
|
|
Pierre-Yves Chibon |
9a36a4 |
@patch('pagure.cli.admin._get_input')
|
|
Pierre-Yves Chibon |
9a36a4 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
d4c9da |
def test_do_info_admin_token(self, conf, rinp):
|
|
Pierre-Yves Chibon |
d4c9da |
""" Test the do_info_admin_token function of pagure-admin. """
|
|
Pierre-Yves Chibon |
d4c9da |
# Create an admin token to use
|
|
Pierre-Yves Chibon |
d4c9da |
conf.return_value = True
|
|
Pierre-Yves Chibon |
e22186 |
rinp.return_value = '1,3,4'
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
args = munch.Munch({'user': 'pingou'})
|
|
Pierre-Yves Chibon |
d4c9da |
pagure.cli.admin.do_create_admin_token(args)
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
# Retrieve the token
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
token = output.split(' ', 1)[0]
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({'token': token})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_info_admin_token(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertIn(' -- pingou -- ', output.split('\n', 1)[0])
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertEqual(
|
|
Pierre-Yves Chibon |
d4c9da |
output.split('\n', 1)[1], '''ACLs:
|
|
Pierre-Yves Chibon |
d4c9da |
- issue_create
|
|
Pierre-Yves Chibon |
d4c9da |
- pull_request_comment
|
|
Pierre-Yves Chibon |
d4c9da |
- pull_request_flag
|
|
Pierre-Yves Chibon |
d4c9da |
''')
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
f3c6b4 |
def test_do_info_admin_token_non_admin_acl(self):
|
|
Pierre-Yves Chibon |
f3c6b4 |
""" Test the do_info_admin_token function of pagure-admin for a
|
|
Pierre-Yves Chibon |
f3c6b4 |
token not having any admin ACL. """
|
|
Pierre-Yves Chibon |
f3c6b4 |
pagure.lib.add_token_to_user(
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.session,
|
|
Pierre-Yves Chibon |
f3c6b4 |
project=None,
|
|
Pierre-Yves Chibon |
f3c6b4 |
acls=['issue_assign', 'pull_request_subscribe'],
|
|
Pierre-Yves Chibon |
f3c6b4 |
username='pingou')
|
|
Pierre-Yves Chibon |
f3c6b4 |
|
|
Pierre-Yves Chibon |
f3c6b4 |
# Retrieve the token
|
|
Pierre-Yves Chibon |
f3c6b4 |
list_args = munch.Munch({
|
|
Pierre-Yves Chibon |
f3c6b4 |
'user': None,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'token': None,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'active': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': True,
|
|
Pierre-Yves Chibon |
f3c6b4 |
})
|
|
Pierre-Yves Chibon |
f3c6b4 |
with tests.capture_output() as output:
|
|
Pierre-Yves Chibon |
f3c6b4 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Pierre-Yves Chibon |
f3c6b4 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
f3c6b4 |
|
|
Pierre-Yves Chibon |
f3c6b4 |
token = output.split(' ', 1)[0]
|
|
Pierre-Yves Chibon |
f3c6b4 |
|
|
Pierre-Yves Chibon |
f3c6b4 |
args = munch.Munch({'token': token})
|
|
Pierre-Yves Chibon |
f3c6b4 |
with tests.capture_output() as output:
|
|
Pierre-Yves Chibon |
f3c6b4 |
pagure.cli.admin.do_info_admin_token(args)
|
|
Pierre-Yves Chibon |
f3c6b4 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.assertIn(' -- pingou -- ', output.split('\n', 1)[0])
|
|
Pierre-Yves Chibon |
f3c6b4 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
f3c6b4 |
output.split('\n', 1)[1], '''ACLs:
|
|
Pierre-Yves Chibon |
f3c6b4 |
- issue_assign
|
|
Pierre-Yves Chibon |
f3c6b4 |
- pull_request_subscribe
|
|
Pierre-Yves Chibon |
f3c6b4 |
''')
|
|
Pierre-Yves Chibon |
f3c6b4 |
|
|
Pierre-Yves Chibon |
d4c9da |
@patch('pagure.cli.admin._get_input')
|
|
Pierre-Yves Chibon |
d4c9da |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
d4c9da |
def test_do_expire_admin_token(self, conf, rinp):
|
|
Pierre-Yves Chibon |
d4c9da |
""" Test the do_expire_admin_token function of pagure-admin. """
|
|
Pierre-Yves Chibon |
d8759f |
if 'BUILD_ID' in os.environ:
|
|
Pierre-Yves Chibon |
d8759f |
raise unittest.case.SkipTest('Skipping on jenkins/el7')
|
|
Pierre-Yves Chibon |
d8759f |
|
|
Pierre-Yves Chibon |
d4c9da |
# Create an admin token to use
|
|
Pierre-Yves Chibon |
d4c9da |
conf.return_value = True
|
|
Pierre-Yves Chibon |
d4c9da |
rinp.return_value = '1,2,3'
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
args = munch.Munch({'user': 'pingou'})
|
|
Pierre-Yves Chibon |
d4c9da |
pagure.cli.admin.do_create_admin_token(args)
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
# Retrieve the token
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
token = output.split(' ', 1)[0]
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
# Before
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': True,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertNotEqual(output, 'No admin tokens found\n')
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
# Expire the token
|
|
Pierre-Yves Chibon |
d4c9da |
args = munch.Munch({'token': token})
|
|
Pierre-Yves Chibon |
d4c9da |
pagure.cli.admin.do_expire_admin_token(args)
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
d4c9da |
# After
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': True,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
d4c9da |
self.assertEqual(output, 'No admin tokens found\n')
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
87a6d0 |
@patch('pagure.cli.admin._get_input')
|
|
Pierre-Yves Chibon |
87a6d0 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
87a6d0 |
def test_do_update_admin_token_invalid_date(self, conf, rinp):
|
|
Pierre-Yves Chibon |
87a6d0 |
""" Test the do_update_admin_token function of pagure-admin with
|
|
Pierre-Yves Chibon |
87a6d0 |
an invalid date. """
|
|
Pierre-Yves Chibon |
87a6d0 |
if 'BUILD_ID' in os.environ:
|
|
Pierre-Yves Chibon |
87a6d0 |
raise unittest.case.SkipTest('Skipping on jenkins/el7')
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Create an admin token to use
|
|
Pierre-Yves Chibon |
87a6d0 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
87a6d0 |
rinp.return_value = '1,2,3'
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
args = munch.Munch({'user': 'pingou'})
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.cli.admin.do_create_admin_token(args)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Retrieve the token
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
token = output.split(' ', 1)[0]
|
|
Pierre-Yves Chibon |
87a6d0 |
current_expiration = output.split(' ', 1)[1]
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Set the expiration date to the token
|
|
Pierre-Yves Chibon |
87a6d0 |
args = munch.Munch({'token': token, 'date': 'aa-bb-cc'})
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertRaises(
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.exceptions.PagureException,
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.cli.admin.do_update_admin_token,
|
|
Pierre-Yves Chibon |
87a6d0 |
args
|
|
Pierre-Yves Chibon |
87a6d0 |
)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
@patch('pagure.cli.admin._get_input')
|
|
Pierre-Yves Chibon |
87a6d0 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
87a6d0 |
def test_do_update_admin_token_invalid_date2(self, conf, rinp):
|
|
Pierre-Yves Chibon |
87a6d0 |
""" Test the do_update_admin_token function of pagure-admin with
|
|
Pierre-Yves Chibon |
87a6d0 |
an invalid date. """
|
|
Pierre-Yves Chibon |
87a6d0 |
if 'BUILD_ID' in os.environ:
|
|
Pierre-Yves Chibon |
87a6d0 |
raise unittest.case.SkipTest('Skipping on jenkins/el7')
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Create an admin token to use
|
|
Pierre-Yves Chibon |
87a6d0 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
87a6d0 |
rinp.return_value = '1,2,3'
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
args = munch.Munch({'user': 'pingou'})
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.cli.admin.do_create_admin_token(args)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Retrieve the token
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
token = output.split(' ', 1)[0]
|
|
Pierre-Yves Chibon |
87a6d0 |
current_expiration = output.split(' ', 1)[1]
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Set the expiration date to the token
|
|
Pierre-Yves Chibon |
87a6d0 |
args = munch.Munch({'token': token, 'date': '2017-18-01'})
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertRaises(
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.exceptions.PagureException,
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.cli.admin.do_update_admin_token,
|
|
Pierre-Yves Chibon |
87a6d0 |
args
|
|
Pierre-Yves Chibon |
87a6d0 |
)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
@patch('pagure.cli.admin._get_input')
|
|
Pierre-Yves Chibon |
87a6d0 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
87a6d0 |
def test_do_update_admin_token_invalid_date3(self, conf, rinp):
|
|
Pierre-Yves Chibon |
87a6d0 |
""" Test the do_update_admin_token function of pagure-admin with
|
|
Pierre-Yves Chibon |
87a6d0 |
an invalid date (is today). """
|
|
Pierre-Yves Chibon |
87a6d0 |
if 'BUILD_ID' in os.environ:
|
|
Pierre-Yves Chibon |
87a6d0 |
raise unittest.case.SkipTest('Skipping on jenkins/el7')
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Create an admin token to use
|
|
Pierre-Yves Chibon |
87a6d0 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
87a6d0 |
rinp.return_value = '1,2,3'
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
args = munch.Munch({'user': 'pingou'})
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.cli.admin.do_create_admin_token(args)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Retrieve the token
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
token = output.split(' ', 1)[0]
|
|
Pierre-Yves Chibon |
87a6d0 |
current_expiration = output.split(' ', 1)[1]
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Set the expiration date to the token
|
|
Pierre-Yves Chibon |
87a6d0 |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
87a6d0 |
'token': token, 'date': datetime.datetime.utcnow().date()
|
|
Pierre-Yves Chibon |
87a6d0 |
})
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertRaises(
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.exceptions.PagureException,
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.cli.admin.do_update_admin_token,
|
|
Pierre-Yves Chibon |
87a6d0 |
args
|
|
Pierre-Yves Chibon |
87a6d0 |
)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
@patch('pagure.cli.admin._get_input')
|
|
Pierre-Yves Chibon |
87a6d0 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
87a6d0 |
def test_do_update_admin_token(self, conf, rinp):
|
|
Pierre-Yves Chibon |
87a6d0 |
""" Test the do_update_admin_token function of pagure-admin. """
|
|
Pierre-Yves Chibon |
87a6d0 |
if 'BUILD_ID' in os.environ:
|
|
Pierre-Yves Chibon |
87a6d0 |
raise unittest.case.SkipTest('Skipping on jenkins/el7')
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Create an admin token to use
|
|
Pierre-Yves Chibon |
87a6d0 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
87a6d0 |
rinp.return_value = '1,2,3'
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
args = munch.Munch({'user': 'pingou'})
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.cli.admin.do_create_admin_token(args)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Retrieve the token
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': False,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertNotEqual(output, 'No user "pingou" found\n')
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
token = output.split(' ', 1)[0]
|
|
Pierre-Yves Chibon |
87a6d0 |
current_expiration = output.strip().split(' -- ', 2)[-1]
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Before
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': True,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertNotEqual(output, 'No admin tokens found\n')
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertEqual(len(output.split('\n')), 2)
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertIn(' -- pingou -- ', output)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
deadline = datetime.datetime.utcnow().date() \
|
|
Pierre-Yves Chibon |
87a6d0 |
+ datetime.timedelta(days=3)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# Set the expiration date to the token
|
|
Pierre-Yves Chibon |
87a6d0 |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
87a6d0 |
'token': token,
|
|
Pierre-Yves Chibon |
87a6d0 |
'date': deadline.strftime('%Y-%m-%d')
|
|
Pierre-Yves Chibon |
87a6d0 |
})
|
|
Pierre-Yves Chibon |
87a6d0 |
pagure.cli.admin.do_update_admin_token(args)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
87a6d0 |
# After
|
|
Aurélien Bompard |
a29742 |
list_args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'token': None,
|
|
Aurélien Bompard |
a29742 |
'active': True,
|
|
Aurélien Bompard |
a29742 |
'expired': False,
|
|
Pierre-Yves Chibon |
f3c6b4 |
'all': False,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_list_admin_token(list_args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertEqual(output.split(' ', 1)[0], token)
|
|
Pierre-Yves Chibon |
87a6d0 |
self.assertNotEqual(
|
|
Pierre-Yves Chibon |
87a6d0 |
output.strip().split(' -- ', 2)[-1],
|
|
Pierre-Yves Chibon |
87a6d0 |
current_expiration)
|
|
Pierre-Yves Chibon |
87a6d0 |
|
|
Pierre-Yves Chibon |
d4c9da |
|
|
Pierre-Yves Chibon |
25e586 |
class PagureAdminGetWatchTests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
25e586 |
""" Tests for pagure-admin get-watch """
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Aurélien Bompard |
e78d79 |
populate_db = False
|
|
Aurélien Bompard |
e78d79 |
|
|
Pierre-Yves Chibon |
25e586 |
def setUp(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
25e586 |
super(PagureAdminGetWatchTests, self).setUp()
|
|
Aurélien Bompard |
e78d79 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
# Create the user pingou
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
25e586 |
user='pingou',
|
|
Pierre-Yves Chibon |
25e586 |
fullname='PY C',
|
|
Pierre-Yves Chibon |
25e586 |
password='foo',
|
|
Pierre-Yves Chibon |
25e586 |
default_email='bar@pingou.com',
|
|
Pierre-Yves Chibon |
25e586 |
)
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
25e586 |
user_id=1,
|
|
Pierre-Yves Chibon |
25e586 |
email='bar@pingou.com')
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
# Create the user foo
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
25e586 |
user='foo',
|
|
Pierre-Yves Chibon |
25e586 |
fullname='foo B.',
|
|
Pierre-Yves Chibon |
25e586 |
password='foob',
|
|
Pierre-Yves Chibon |
25e586 |
default_email='foo@pingou.com',
|
|
Pierre-Yves Chibon |
25e586 |
)
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
# Create two projects for the user pingou
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
25e586 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
25e586 |
name='test',
|
|
Pierre-Yves Chibon |
25e586 |
description='namespaced test project',
|
|
Pierre-Yves Chibon |
25e586 |
hook_token='aaabbbeee',
|
|
Pierre-Yves Chibon |
25e586 |
namespace='somenamespace',
|
|
Pierre-Yves Chibon |
25e586 |
)
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
25e586 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
25e586 |
name='test',
|
|
Pierre-Yves Chibon |
25e586 |
description='Test project',
|
|
Pierre-Yves Chibon |
25e586 |
hook_token='aaabbbccc',
|
|
Pierre-Yves Chibon |
25e586 |
namespace=None,
|
|
Pierre-Yves Chibon |
25e586 |
)
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
self.session.commit()
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
# Make the imported pagure use the correct db session
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_get_project_unknown_project(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the get-watch function of pagure-admin with an unknown
|
|
Pierre-Yves Chibon |
25e586 |
project.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'foobar',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'No project found with: foobar'
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_get_project_invalid_project(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the get-watch function of pagure-admin with an invalid
|
|
Pierre-Yves Chibon |
25e586 |
project.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'fo/o/bar',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'Invalid project name, has more than one "/": fo/o/bar',
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_get_project_invalid_user(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the get-watch function of pagure-admin on a invalid user.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': 'beebop',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'No user "beebop" found'
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_get_project(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the get-watch function of pagure-admin on a regular project.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
25e586 |
'On test user: pingou is watching the following items: '
|
|
Pierre-Yves Chibon |
25e586 |
'issues, pull-requests\n', output)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_get_project_not_watching(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the get-watch function of pagure-admin on a regular project.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': 'foo',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
25e586 |
'On test user: foo is watching the following items: None\n',
|
|
Pierre-Yves Chibon |
25e586 |
output)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_get_project_namespaced(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the get-watch function of pagure-admin on a namespaced project.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'somenamespace/test',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
25e586 |
'On somenamespace/test user: pingou is watching the following '
|
|
Pierre-Yves Chibon |
25e586 |
'items: issues, pull-requests\n', output)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_get_project_namespaced_not_watching(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the get-watch function of pagure-admin on a namespaced project.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'somenamespace/test',
|
|
Aurélien Bompard |
a29742 |
'user': 'foo',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as _discarded:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
25e586 |
'On somenamespace/test user: foo is watching the following '
|
|
Pierre-Yves Chibon |
25e586 |
'items: None\n', output)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
class PagureAdminUpdateWatchTests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
25e586 |
""" Tests for pagure-admin update-watch """
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Aurélien Bompard |
e78d79 |
populate_db = False
|
|
Aurélien Bompard |
e78d79 |
|
|
Pierre-Yves Chibon |
25e586 |
def setUp(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
25e586 |
super(PagureAdminUpdateWatchTests, self).setUp()
|
|
Aurélien Bompard |
e78d79 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
# Create the user pingou
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
25e586 |
user='pingou',
|
|
Pierre-Yves Chibon |
25e586 |
fullname='PY C',
|
|
Pierre-Yves Chibon |
25e586 |
password='foo',
|
|
Pierre-Yves Chibon |
25e586 |
default_email='bar@pingou.com',
|
|
Pierre-Yves Chibon |
25e586 |
)
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
25e586 |
user_id=1,
|
|
Pierre-Yves Chibon |
25e586 |
email='bar@pingou.com')
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
# Create the user foo
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
25e586 |
user='foo',
|
|
Pierre-Yves Chibon |
25e586 |
fullname='foo B.',
|
|
Pierre-Yves Chibon |
25e586 |
password='foob',
|
|
Pierre-Yves Chibon |
25e586 |
default_email='foo@pingou.com',
|
|
Pierre-Yves Chibon |
25e586 |
)
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
# Create two projects for the user pingou
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
25e586 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
25e586 |
name='test',
|
|
Pierre-Yves Chibon |
25e586 |
description='namespaced test project',
|
|
Pierre-Yves Chibon |
25e586 |
hook_token='aaabbbeee',
|
|
Pierre-Yves Chibon |
25e586 |
namespace='somenamespace',
|
|
Pierre-Yves Chibon |
25e586 |
)
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
25e586 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
25e586 |
name='test',
|
|
Pierre-Yves Chibon |
25e586 |
description='Test project',
|
|
Pierre-Yves Chibon |
25e586 |
hook_token='aaabbbccc',
|
|
Pierre-Yves Chibon |
25e586 |
namespace=None,
|
|
Pierre-Yves Chibon |
25e586 |
)
|
|
Pierre-Yves Chibon |
25e586 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
self.session.commit()
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
# Make the imported pagure use the correct db session
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_update_project_unknown_project(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the update-watch function of pagure-admin on an unknown
|
|
Pierre-Yves Chibon |
25e586 |
project.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'foob',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
'status': '1'
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_update_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'No project found with: foob'
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_update_project_invalid_project(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the update-watch function of pagure-admin on an invalid
|
|
Pierre-Yves Chibon |
25e586 |
project.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'fo/o/b',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
'status': '1'
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_update_watch_status(args)
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'Invalid project name, has more than one "/": fo/o/b',
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_update_project_invalid_user(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the update-watch function of pagure-admin on an invalid user.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': 'foob',
|
|
Aurélien Bompard |
a29742 |
'status': '1'
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_update_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'No user "foob" found'
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_update_project_invalid_status(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the update-watch function of pagure-admin with an invalid
|
|
Pierre-Yves Chibon |
25e586 |
status.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
'status': '10'
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_update_watch_status(args)
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'Invalid status provided: 10 not in -1, 0, 1, 2, 3'
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
def test_get_watch_update_project_no_effect(self):
|
|
Pierre-Yves Chibon |
25e586 |
""" Test the update-watch function of pagure-admin with a regular
|
|
Pierre-Yves Chibon |
25e586 |
project - nothing changed.
|
|
Pierre-Yves Chibon |
25e586 |
"""
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
25e586 |
'On test user: pingou is watching the following items: '
|
|
Pierre-Yves Chibon |
25e586 |
'issues, pull-requests\n', output)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
'status': '1'
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_update_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
25e586 |
'Updating watch status of pingou to 1 (watch issues and PRs) '
|
|
Pierre-Yves Chibon |
25e586 |
'on test\n', output)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': 'pingou',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_get_watch_status(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
25e586 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
25e586 |
'On test user: pingou is watching the following items: '
|
|
Pierre-Yves Chibon |
25e586 |
'issues, pull-requests\n', output)
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
25e586 |
|
|
Pierre-Yves Chibon |
3a016c |
class PagureAdminReadOnlyTests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
3a016c |
""" Tests for pagure-admin read-only """
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Aurélien Bompard |
e78d79 |
populate_db = False
|
|
Aurélien Bompard |
e78d79 |
|
|
Pierre-Yves Chibon |
3a016c |
def setUp(self):
|
|
Pierre-Yves Chibon |
3a016c |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
3a016c |
super(PagureAdminReadOnlyTests, self).setUp()
|
|
Aurélien Bompard |
e78d79 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
# Create the user pingou
|
|
Pierre-Yves Chibon |
3a016c |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
3a016c |
user='pingou',
|
|
Pierre-Yves Chibon |
3a016c |
fullname='PY C',
|
|
Pierre-Yves Chibon |
3a016c |
password='foo',
|
|
Pierre-Yves Chibon |
3a016c |
default_email='bar@pingou.com',
|
|
Pierre-Yves Chibon |
3a016c |
)
|
|
Pierre-Yves Chibon |
3a016c |
self.session.add(item)
|
|
Pierre-Yves Chibon |
3a016c |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
3a016c |
user_id=1,
|
|
Pierre-Yves Chibon |
3a016c |
email='bar@pingou.com')
|
|
Pierre-Yves Chibon |
3a016c |
self.session.add(item)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
# Create two projects for the user pingou
|
|
Pierre-Yves Chibon |
3a016c |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
3a016c |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
3a016c |
name='test',
|
|
Pierre-Yves Chibon |
3a016c |
description='namespaced test project',
|
|
Pierre-Yves Chibon |
3a016c |
hook_token='aaabbbeee',
|
|
Pierre-Yves Chibon |
3a016c |
namespace='somenamespace',
|
|
Pierre-Yves Chibon |
3a016c |
)
|
|
Pierre-Yves Chibon |
3a016c |
self.session.add(item)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
3a016c |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
3a016c |
name='test',
|
|
Pierre-Yves Chibon |
3a016c |
description='Test project',
|
|
Pierre-Yves Chibon |
3a016c |
hook_token='aaabbbccc',
|
|
Pierre-Yves Chibon |
3a016c |
namespace=None,
|
|
Pierre-Yves Chibon |
3a016c |
)
|
|
Pierre-Yves Chibon |
3a016c |
self.session.add(item)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
self.session.commit()
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
# Make the imported pagure use the correct db session
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
def test_read_only_unknown_project(self):
|
|
Pierre-Yves Chibon |
3a016c |
""" Test the read-only function of pagure-admin on an unknown
|
|
Pierre-Yves Chibon |
3a016c |
project.
|
|
Pierre-Yves Chibon |
3a016c |
"""
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'foob',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': None,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Aurélien Bompard |
a29742 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'No project found with: foob'
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
def test_read_only_invalid_project(self):
|
|
Pierre-Yves Chibon |
3a016c |
""" Test the read-only function of pagure-admin on an invalid
|
|
Pierre-Yves Chibon |
3a016c |
project.
|
|
Pierre-Yves Chibon |
3a016c |
"""
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'fo/o/b',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': None,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Pierre-Yves Chibon |
3a016c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Aurélien Bompard |
a29742 |
'Invalid project name, has more than one "/": fo/o/b'
|
|
Aurélien Bompard |
a29742 |
)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
def test_read_only(self):
|
|
Pierre-Yves Chibon |
3a016c |
""" Test the read-only function of pagure-admin to get status of
|
|
Pierre-Yves Chibon |
3a016c |
a non-namespaced project.
|
|
Pierre-Yves Chibon |
3a016c |
"""
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': None,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
3a016c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
3a016c |
'The current read-only flag of the project test is set to True\n',
|
|
Pierre-Yves Chibon |
3a016c |
output)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
def test_read_only_namespace(self):
|
|
Pierre-Yves Chibon |
3a016c |
""" Test the read-only function of pagure-admin to get status of
|
|
Pierre-Yves Chibon |
3a016c |
a namespaced project.
|
|
Pierre-Yves Chibon |
3a016c |
"""
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'somenamespace/test',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': None,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
3a016c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
3a016c |
'The current read-only flag of the project somenamespace/test '\
|
|
Pierre-Yves Chibon |
3a016c |
'is set to True\n', output)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
def test_read_only_namespace_changed(self):
|
|
Pierre-Yves Chibon |
3a016c |
""" Test the read-only function of pagure-admin to set the status of
|
|
Pierre-Yves Chibon |
3a016c |
a namespaced project.
|
|
Pierre-Yves Chibon |
3a016c |
"""
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
# Before
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'somenamespace/test',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': None,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
3a016c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
3a016c |
'The current read-only flag of the project somenamespace/test '\
|
|
Pierre-Yves Chibon |
3a016c |
'is set to True\n', output)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'somenamespace/test',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': 'false',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
3a016c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
3a016c |
'The read-only flag of the project somenamespace/test has been '
|
|
Pierre-Yves Chibon |
3a016c |
'set to False\n', output)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
# After
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'somenamespace/test',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': None,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
3a016c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
3a016c |
'The current read-only flag of the project somenamespace/test '\
|
|
Pierre-Yves Chibon |
3a016c |
'is set to False\n', output)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
def test_read_only_no_change(self):
|
|
Pierre-Yves Chibon |
3a016c |
""" Test the read-only function of pagure-admin to set the status of
|
|
Pierre-Yves Chibon |
3a016c |
a namespaced project.
|
|
Pierre-Yves Chibon |
3a016c |
"""
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
# Before
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': None,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
3a016c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
3a016c |
'The current read-only flag of the project test '\
|
|
Pierre-Yves Chibon |
3a016c |
'is set to True\n', output)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': 'true',
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
3a016c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
3a016c |
'The read-only flag of the project test has been '
|
|
Pierre-Yves Chibon |
3a016c |
'set to True\n', output)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
# After
|
|
Aurélien Bompard |
a29742 |
args = munch.Munch({
|
|
Aurélien Bompard |
a29742 |
'project': 'test',
|
|
Aurélien Bompard |
a29742 |
'user': None,
|
|
Aurélien Bompard |
a29742 |
'ro': None,
|
|
Aurélien Bompard |
a29742 |
})
|
|
Aurélien Bompard |
a29742 |
with tests.capture_output() as output:
|
|
Aurélien Bompard |
a29742 |
pagure.cli.admin.do_read_only(args)
|
|
Aurélien Bompard |
a29742 |
output = output.getvalue()
|
|
Pierre-Yves Chibon |
3a016c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
3a016c |
'The current read-only flag of the project test '\
|
|
Pierre-Yves Chibon |
3a016c |
'is set to True\n', output)
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
3a016c |
|
|
Pierre-Yves Chibon |
ffbe63 |
class PagureNewGroupTests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
ffbe63 |
""" Tests for pagure-admin new-group """
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
populate_db = False
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
def setUp(self):
|
|
Pierre-Yves Chibon |
ffbe63 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
ffbe63 |
super(PagureNewGroupTests, self).setUp()
|
|
Pierre-Yves Chibon |
ffbe63 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
# Create the user pingou
|
|
Pierre-Yves Chibon |
ffbe63 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
ffbe63 |
user='pingou',
|
|
Pierre-Yves Chibon |
ffbe63 |
fullname='PY C',
|
|
Pierre-Yves Chibon |
ffbe63 |
password='foo',
|
|
Pierre-Yves Chibon |
ffbe63 |
default_email='bar@pingou.com',
|
|
Pierre-Yves Chibon |
ffbe63 |
)
|
|
Pierre-Yves Chibon |
ffbe63 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
ffbe63 |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
ffbe63 |
user_id=1,
|
|
Pierre-Yves Chibon |
ffbe63 |
email='bar@pingou.com')
|
|
Pierre-Yves Chibon |
ffbe63 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
self.session.commit()
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
# Make the imported pagure use the correct db session
|
|
Pierre-Yves Chibon |
ffbe63 |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
groups = pagure.lib.search_groups(self.session)
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(len(groups), 0)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
def test_missing_display_name(self):
|
|
Pierre-Yves Chibon |
ffbe63 |
""" Test the new-group function of pagure-admin when the display name
|
|
Pierre-Yves Chibon |
ffbe63 |
is missing from the args.
|
|
Pierre-Yves Chibon |
ffbe63 |
"""
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
ffbe63 |
'group_name': 'foob',
|
|
Pierre-Yves Chibon |
ffbe63 |
'display': None,
|
|
Pierre-Yves Chibon |
ffbe63 |
'description': None,
|
|
Pierre-Yves Chibon |
ffbe63 |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
ffbe63 |
})
|
|
Pierre-Yves Chibon |
ffbe63 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Pierre-Yves Chibon |
ffbe63 |
pagure.cli.admin.do_new_group(args)
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Pierre-Yves Chibon |
ffbe63 |
'A display name must be provided for the group'
|
|
Pierre-Yves Chibon |
ffbe63 |
)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
groups = pagure.lib.search_groups(self.session)
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(len(groups), 0)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
def test_missing_username(self):
|
|
Pierre-Yves Chibon |
ffbe63 |
""" Test the new-group function of pagure-admin when the username
|
|
Pierre-Yves Chibon |
ffbe63 |
is missing from the args.
|
|
Pierre-Yves Chibon |
ffbe63 |
"""
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
ffbe63 |
'group_name': 'foob',
|
|
Pierre-Yves Chibon |
ffbe63 |
'display': 'foo group',
|
|
Pierre-Yves Chibon |
ffbe63 |
'description': None,
|
|
Pierre-Yves Chibon |
ffbe63 |
'username': None,
|
|
Pierre-Yves Chibon |
ffbe63 |
})
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Pierre-Yves Chibon |
ffbe63 |
pagure.cli.admin.do_new_group(args)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Pierre-Yves Chibon |
ffbe63 |
'An username must be provided to associate with the group'
|
|
Pierre-Yves Chibon |
ffbe63 |
)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
groups = pagure.lib.search_groups(self.session)
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(len(groups), 0)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
def test_new_group(self):
|
|
Pierre-Yves Chibon |
ffbe63 |
""" Test the new-group function of pagure-admin when all arguments
|
|
Pierre-Yves Chibon |
ffbe63 |
are provided.
|
|
Pierre-Yves Chibon |
ffbe63 |
"""
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
ffbe63 |
'group_name': 'foob',
|
|
Pierre-Yves Chibon |
ffbe63 |
'display': 'foo group',
|
|
Pierre-Yves Chibon |
ffbe63 |
'description': None,
|
|
Pierre-Yves Chibon |
ffbe63 |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
ffbe63 |
})
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
pagure.cli.admin.do_new_group(args)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
groups = pagure.lib.search_groups(self.session)
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(len(groups), 1)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
@patch.dict('pagure.config.config', {'ENABLE_GROUP_MNGT': False})
|
|
Pierre-Yves Chibon |
ffbe63 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
ffbe63 |
def test_new_group_grp_mngt_off_no(self, conf):
|
|
Pierre-Yves Chibon |
ffbe63 |
""" Test the new-group function of pagure-admin when all arguments
|
|
Pierre-Yves Chibon |
ffbe63 |
are provided and ENABLE_GROUP_MNGT if off in the config and the user
|
|
Pierre-Yves Chibon |
ffbe63 |
replies no to the question.
|
|
Pierre-Yves Chibon |
ffbe63 |
"""
|
|
Pierre-Yves Chibon |
ffbe63 |
conf.return_value = False
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
ffbe63 |
'group_name': 'foob',
|
|
Pierre-Yves Chibon |
ffbe63 |
'display': 'foo group',
|
|
Pierre-Yves Chibon |
ffbe63 |
'description': None,
|
|
Pierre-Yves Chibon |
ffbe63 |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
ffbe63 |
})
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
pagure.cli.admin.do_new_group(args)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
groups = pagure.lib.search_groups(self.session)
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(len(groups), 0)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
@patch.dict('pagure.config.config', {'ENABLE_GROUP_MNGT': False})
|
|
Pierre-Yves Chibon |
ffbe63 |
@patch('pagure.cli.admin._ask_confirmation')
|
|
Pierre-Yves Chibon |
ffbe63 |
def test_new_group_grp_mngt_off_yes(self, conf):
|
|
Pierre-Yves Chibon |
ffbe63 |
""" Test the new-group function of pagure-admin when all arguments
|
|
Pierre-Yves Chibon |
ffbe63 |
are provided and ENABLE_GROUP_MNGT if off in the config and the user
|
|
Pierre-Yves Chibon |
ffbe63 |
replies yes to the question.
|
|
Pierre-Yves Chibon |
ffbe63 |
"""
|
|
Pierre-Yves Chibon |
ffbe63 |
conf.return_value = True
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
ffbe63 |
'group_name': 'foob',
|
|
Pierre-Yves Chibon |
ffbe63 |
'display': 'foo group',
|
|
Pierre-Yves Chibon |
ffbe63 |
'description': None,
|
|
Pierre-Yves Chibon |
ffbe63 |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
ffbe63 |
})
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
pagure.cli.admin.do_new_group(args)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
groups = pagure.lib.search_groups(self.session)
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(len(groups), 1)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
@patch.dict('pagure.config.config', {'BLACKLISTED_GROUPS': ['foob']})
|
|
Pierre-Yves Chibon |
ffbe63 |
def test_new_group_grp_mngt_off_yes(self):
|
|
Pierre-Yves Chibon |
ffbe63 |
""" Test the new-group function of pagure-admin when all arguments
|
|
Pierre-Yves Chibon |
ffbe63 |
are provided but the group is black listed.
|
|
Pierre-Yves Chibon |
ffbe63 |
"""
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
ffbe63 |
'group_name': 'foob',
|
|
Pierre-Yves Chibon |
ffbe63 |
'display': 'foo group',
|
|
Pierre-Yves Chibon |
ffbe63 |
'description': None,
|
|
Pierre-Yves Chibon |
ffbe63 |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
ffbe63 |
})
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Pierre-Yves Chibon |
ffbe63 |
pagure.cli.admin.do_new_group(args)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ffbe63 |
cm.exception.args[0],
|
|
Pierre-Yves Chibon |
ffbe63 |
'This group name has been blacklisted, please choose another one'
|
|
Pierre-Yves Chibon |
ffbe63 |
)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
ffbe63 |
groups = pagure.lib.search_groups(self.session)
|
|
Pierre-Yves Chibon |
ffbe63 |
self.assertEqual(len(groups), 0)
|
|
Pierre-Yves Chibon |
ffbe63 |
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Fabian Arrotin |
0096c9 |
class PagureListGroupEmptyTests(tests.Modeltests):
|
|
Fabian Arrotin |
0096c9 |
""" Tests for pagure-admin list-groups """
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
populate_db = False
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
def setUp(self):
|
|
Fabian Arrotin |
0096c9 |
""" Set up the environnment, ran before every tests. """
|
|
Fabian Arrotin |
0096c9 |
super(PagureListGroupEmptyTests, self).setUp()
|
|
Fabian Arrotin |
0096c9 |
pagure.cli.admin.session = self.session
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
# Create the user pingou
|
|
Fabian Arrotin |
0096c9 |
item = pagure.lib.model.User(
|
|
Fabian Arrotin |
0096c9 |
user='pingou',
|
|
Fabian Arrotin |
0096c9 |
fullname='PY C',
|
|
Fabian Arrotin |
0096c9 |
password='foo',
|
|
Fabian Arrotin |
0096c9 |
default_email='bar@pingou.com',
|
|
Fabian Arrotin |
0096c9 |
)
|
|
Fabian Arrotin |
0096c9 |
self.session.add(item)
|
|
Fabian Arrotin |
0096c9 |
item = pagure.lib.model.UserEmail(
|
|
Fabian Arrotin |
0096c9 |
user_id=1,
|
|
Fabian Arrotin |
0096c9 |
email='bar@pingou.com')
|
|
Fabian Arrotin |
0096c9 |
self.session.add(item)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
self.session.commit()
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
# Make the imported pagure use the correct db session
|
|
Fabian Arrotin |
0096c9 |
pagure.cli.admin.session = self.session
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
groups = pagure.lib.search_groups(self.session)
|
|
Fabian Arrotin |
0096c9 |
self.assertEqual(len(groups), 0)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
@patch('sys.stdout', new_callable=StringIO)
|
|
Fabian Arrotin |
0096c9 |
def test_no_groups(self, mock_stdout):
|
|
Fabian Arrotin |
0096c9 |
""" Test the list-groups function of pagure-admin when there are no
|
|
Fabian Arrotin |
0096c9 |
groups in the database
|
|
Fabian Arrotin |
0096c9 |
"""
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
args = munch.Munch()
|
|
Fabian Arrotin |
0096c9 |
pagure.cli.admin.do_list_groups(args)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
self.assertEqual(
|
|
Fabian Arrotin |
0096c9 |
mock_stdout.getvalue(),
|
|
Fabian Arrotin |
0096c9 |
'No groups found in this pagure instance.\n'
|
|
Fabian Arrotin |
0096c9 |
)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
groups = pagure.lib.search_groups(self.session)
|
|
Fabian Arrotin |
0096c9 |
self.assertEqual(len(groups), 0)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
class PagureListGroupTests(tests.Modeltests):
|
|
Fabian Arrotin |
0096c9 |
""" Tests for pagure-admin list-groups """
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
populate_db = False
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
def setUp(self):
|
|
Fabian Arrotin |
0096c9 |
""" Set up the environnment, ran before every tests. """
|
|
Fabian Arrotin |
0096c9 |
super(PagureListGroupTests, self).setUp()
|
|
Fabian Arrotin |
0096c9 |
pagure.cli.admin.session = self.session
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
# Create the user pingou
|
|
Fabian Arrotin |
0096c9 |
item = pagure.lib.model.User(
|
|
Fabian Arrotin |
0096c9 |
user='pingou',
|
|
Fabian Arrotin |
0096c9 |
fullname='PY C',
|
|
Fabian Arrotin |
0096c9 |
password='foo',
|
|
Fabian Arrotin |
0096c9 |
default_email='bar@pingou.com',
|
|
Fabian Arrotin |
0096c9 |
)
|
|
Fabian Arrotin |
0096c9 |
self.session.add(item)
|
|
Fabian Arrotin |
0096c9 |
item = pagure.lib.model.UserEmail(
|
|
Fabian Arrotin |
0096c9 |
user_id=1,
|
|
Fabian Arrotin |
0096c9 |
email='bar@pingou.com')
|
|
Fabian Arrotin |
0096c9 |
self.session.add(item)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
# Create a group
|
|
Fabian Arrotin |
0096c9 |
pagure.lib.add_group(
|
|
Fabian Arrotin |
0096c9 |
self.session,
|
|
Fabian Arrotin |
0096c9 |
group_name='JL',
|
|
Fabian Arrotin |
0096c9 |
display_name='Justice League',
|
|
Fabian Arrotin |
0096c9 |
description='Nope, it\'s not JLA anymore',
|
|
Fabian Arrotin |
0096c9 |
group_type='user',
|
|
Fabian Arrotin |
0096c9 |
user='pingou',
|
|
Fabian Arrotin |
0096c9 |
is_admin=False,
|
|
Fabian Arrotin |
0096c9 |
blacklist=[]
|
|
Fabian Arrotin |
0096c9 |
)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
self.session.commit()
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
# Make the imported pagure use the correct db session
|
|
Fabian Arrotin |
0096c9 |
pagure.cli.admin.session = self.session
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
groups = pagure.lib.search_groups(self.session)
|
|
Fabian Arrotin |
0096c9 |
self.assertEqual(len(groups), 1)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
@patch('sys.stdout', new_callable=StringIO)
|
|
Fabian Arrotin |
0096c9 |
def test_list_groups(self, mock_stdout):
|
|
Fabian Arrotin |
0096c9 |
""" Test the list-groups function of pagure-admin when there is one
|
|
Fabian Arrotin |
0096c9 |
group in the database
|
|
Fabian Arrotin |
0096c9 |
"""
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
args = munch.Munch()
|
|
Fabian Arrotin |
0096c9 |
pagure.cli.admin.do_list_groups(args)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
self.assertEqual(
|
|
Fabian Arrotin |
0096c9 |
mock_stdout.getvalue(),
|
|
Fabian Arrotin |
0096c9 |
'List of groups on this Pagure instance:\n'
|
|
Fabian Arrotin |
0096c9 |
'Group: 1 - name JL\n'
|
|
Fabian Arrotin |
0096c9 |
)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
groups = pagure.lib.search_groups(self.session)
|
|
Fabian Arrotin |
0096c9 |
self.assertEqual(len(groups), 1)
|
|
Fabian Arrotin |
0096c9 |
|
|
Fabian Arrotin |
0096c9 |
|
|
Pierre-Yves Chibon |
bee78a |
class PagureBlockUserTests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
bee78a |
""" Tests for pagure-admin block-user """
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
populate_db = False
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
def setUp(self):
|
|
Pierre-Yves Chibon |
bee78a |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
bee78a |
super(PagureBlockUserTests, self).setUp()
|
|
Pierre-Yves Chibon |
bee78a |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
# Create the user pingou
|
|
Pierre-Yves Chibon |
bee78a |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
bee78a |
user='pingou',
|
|
Pierre-Yves Chibon |
bee78a |
fullname='PY C',
|
|
Pierre-Yves Chibon |
bee78a |
password='foo',
|
|
Pierre-Yves Chibon |
bee78a |
default_email='bar@pingou.com',
|
|
Pierre-Yves Chibon |
bee78a |
)
|
|
Pierre-Yves Chibon |
bee78a |
self.session.add(item)
|
|
Pierre-Yves Chibon |
bee78a |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
bee78a |
user_id=1,
|
|
Pierre-Yves Chibon |
bee78a |
email='bar@pingou.com')
|
|
Pierre-Yves Chibon |
bee78a |
self.session.add(item)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
self.session.commit()
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
# Make the imported pagure use the correct db session
|
|
Pierre-Yves Chibon |
bee78a |
pagure.cli.admin.session = self.session
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
bee78a |
self.assertIsNone(user.refuse_sessions_before)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
def test_missing_date(self):
|
|
Pierre-Yves Chibon |
bee78a |
""" Test the block-user function of pagure-admin when the no date is
|
|
Pierre-Yves Chibon |
bee78a |
provided.
|
|
Pierre-Yves Chibon |
bee78a |
"""
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
bee78a |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
bee78a |
'date': None,
|
|
Pierre-Yves Chibon |
bee78a |
})
|
|
Pierre-Yves Chibon |
bee78a |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Pierre-Yves Chibon |
bee78a |
pagure.cli.admin.do_block_user(args)
|
|
Pierre-Yves Chibon |
bee78a |
self.assertEqual(
|
|
Pierre-Yves Chibon |
bee78a |
cm.exception.args[0],
|
|
Pierre-Yves Chibon |
bee78a |
'Invalid date submitted: None, not of the format YYYY-MM-DD'
|
|
Pierre-Yves Chibon |
bee78a |
)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
bee78a |
self.assertIsNone(user.refuse_sessions_before)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
def test_missing_username(self):
|
|
Pierre-Yves Chibon |
bee78a |
""" Test the block-user function of pagure-admin when the username
|
|
Pierre-Yves Chibon |
bee78a |
is missing from the args.
|
|
Pierre-Yves Chibon |
bee78a |
"""
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
bee78a |
'date': '2018-06-11',
|
|
Pierre-Yves Chibon |
bee78a |
'username': None,
|
|
Pierre-Yves Chibon |
bee78a |
})
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Pierre-Yves Chibon |
bee78a |
pagure.cli.admin.do_block_user(args)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
self.assertEqual(
|
|
Pierre-Yves Chibon |
bee78a |
cm.exception.args[0],
|
|
Pierre-Yves Chibon |
bee78a |
'An username must be specified'
|
|
Pierre-Yves Chibon |
bee78a |
)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
bee78a |
self.assertIsNone(user.refuse_sessions_before)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
def test_invalid_username(self):
|
|
Pierre-Yves Chibon |
bee78a |
""" Test the block-user function of pagure-admin when the username
|
|
Pierre-Yves Chibon |
bee78a |
provided does correspond to any user in the DB.
|
|
Pierre-Yves Chibon |
bee78a |
"""
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
bee78a |
'date': '2018-06-11',
|
|
Pierre-Yves Chibon |
bee78a |
'username': 'invalid'
|
|
Pierre-Yves Chibon |
bee78a |
})
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Pierre-Yves Chibon |
bee78a |
pagure.cli.admin.do_block_user(args)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
self.assertEqual(
|
|
Pierre-Yves Chibon |
bee78a |
cm.exception.args[0],
|
|
Pierre-Yves Chibon |
bee78a |
'No user "invalid" found'
|
|
Pierre-Yves Chibon |
bee78a |
)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
bee78a |
self.assertIsNone(user.refuse_sessions_before)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
def test_invalide_date(self):
|
|
Pierre-Yves Chibon |
bee78a |
""" Test the block-user function of pagure-admin when the provided
|
|
Pierre-Yves Chibon |
bee78a |
date is incorrect.
|
|
Pierre-Yves Chibon |
bee78a |
"""
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
bee78a |
'date': '2018-14-05',
|
|
Pierre-Yves Chibon |
bee78a |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
bee78a |
})
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
with self.assertRaises(pagure.exceptions.PagureException) as cm:
|
|
Pierre-Yves Chibon |
bee78a |
pagure.cli.admin.do_block_user(args)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
self.assertEqual(
|
|
Pierre-Yves Chibon |
bee78a |
cm.exception.args[0],
|
|
Pierre-Yves Chibon |
bee78a |
'Invalid date submitted: 2018-14-05, not of the format YYYY-MM-DD'
|
|
Pierre-Yves Chibon |
bee78a |
)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
bee78a |
self.assertIsNone(user.refuse_sessions_before)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Ryan Lerch |
b24025 |
@patch('pagure.cli.admin._ask_confirmation', MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
bee78a |
def test_block_user(self):
|
|
Pierre-Yves Chibon |
bee78a |
""" Test the block-user function of pagure-admin when all arguments
|
|
Pierre-Yves Chibon |
bee78a |
are provided correctly.
|
|
Pierre-Yves Chibon |
bee78a |
"""
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
args = munch.Munch({
|
|
Pierre-Yves Chibon |
bee78a |
'date': '2050-12-31',
|
|
Pierre-Yves Chibon |
bee78a |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
bee78a |
})
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
pagure.cli.admin.do_block_user(args)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
4c9301 |
self.assertIsNotNone(user.refuse_sessions_before)
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
bee78a |
|
|
Pierre-Yves Chibon |
d4c9da |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
d4c9da |
unittest.main(verbosity=2)
|