Blame tests/test_pagure_admin.py

Pierre-Yves Chibon d4c9da
# -*- coding: utf-8 -*-
Pierre-Yves Chibon d4c9da
Pierre-Yves Chibon d4c9da
"""
Pierre-Yves Chibon d4c9da
 (c) 2017 - 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
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
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(
Aurélien Bompard a29742
            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,
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
Pierre-Yves Chibon ede948
        get_helper.assert_called_with('gitolite3')
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
Pierre-Yves Chibon ede948
        get_helper.assert_called_with('gitolite3')
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
Pierre-Yves Chibon ede948
        get_helper.assert_called_with('gitolite3')
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
Pierre-Yves Chibon ede948
        get_helper.assert_called_with('gitolite3')
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
Pierre-Yves Chibon ede948
        get_helper.assert_called_with('gitolite3')
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,
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,
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,
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 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,
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 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,
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,
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,
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,
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,
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,
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,
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,
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,
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(
Aurélien Bompard a29742
            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(
Aurélien Bompard a29742
            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(
Aurélien Bompard a29742
            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(
Aurélien Bompard a29742
            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(
Aurélien Bompard a29742
            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(
Aurélien Bompard a29742
            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(
Aurélien Bompard a29742
            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(
Aurélien Bompard a29742
            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(
Aurélien Bompard a29742
            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 d4c9da
if __name__ == '__main__':
Pierre-Yves Chibon d4c9da
    unittest.main(verbosity=2)