Ejemplo n.º 1
0
    def test_do_list_admin_token(self, conf, rinp):
        """ Test the do_list_admin_token function of pagure-admin. """
        # Create an admin token to use
        conf.return_value = True
        rinp.return_value = '1,2,3'

        args = munch.Munch({'user': '******'})
        pagure.cli.admin.do_create_admin_token(args)

        # Retrieve all tokens
        list_args = munch.Munch({
            'user': None,
            'token': None,
            'active': False,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertNotEqual(output, 'No user "pingou" found\n')
        self.assertEqual(len(output.split('\n')), 2)
        self.assertIn(' -- pingou -- ', output)

        # Retrieve pfrields's tokens
        list_args = munch.Munch({
            'user': '******',
            'token': None,
            'active': False,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertEqual(output, 'No admin tokens found\n')
Ejemplo n.º 2
0
    def test_do_expire_admin_token(self, conf, rinp):
        """ Test the do_expire_admin_token function of pagure-admin. """
        if 'BUILD_ID' in os.environ:
            raise unittest.case.SkipTest('Skipping on jenkins/el7')

        # Create an admin token to use
        conf.return_value = True
        rinp.return_value = '1,2,3'

        args = munch.Munch({'user': '******'})
        pagure.cli.admin.do_create_admin_token(args)

        # Retrieve the token
        list_args = munch.Munch({
            'user': None,
            'token': None,
            'active': False,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertNotEqual(output, 'No user "pingou" found\n')
        self.assertEqual(len(output.split('\n')), 2)
        self.assertIn(' -- pingou -- ', output)

        token = output.split(' ', 1)[0]

        # Before
        list_args = munch.Munch({
            'user': None,
            'token': None,
            'active': True,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertNotEqual(output, 'No admin tokens found\n')
        self.assertEqual(len(output.split('\n')), 2)
        self.assertIn(' -- pingou -- ', output)

        # Expire the token
        args = munch.Munch({'token': token})
        pagure.cli.admin.do_expire_admin_token(args)

        # After
        list_args = munch.Munch({
            'user': None,
            'token': None,
            'active': True,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertEqual(output, 'No admin tokens found\n')
Ejemplo n.º 3
0
    def test_get_watch_get_project_namespaced_not_watching(self):
        """ Test the get-watch function of pagure-admin on a namespaced project.
        """

        args = munch.Munch({
            'project': 'somenamespace/test',
            'user': '******',
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_get_watch_status(args)
        output = output.getvalue()
        with tests.capture_output() as _discarded:
            pagure.cli.admin.do_get_watch_status(args)
        self.assertEqual(
            'On somenamespace/test user: foo is watching the following '
            'items: None\n', output)
Ejemplo n.º 4
0
    def test_do_update_admin_token_invalid_date2(self, conf, rinp):
        """ Test the do_update_admin_token function of pagure-admin with
        an invalid date. """
        if 'BUILD_ID' in os.environ:
            raise unittest.case.SkipTest('Skipping on jenkins/el7')

        # Create an admin token to use
        conf.return_value = True
        rinp.return_value = '1,2,3'

        args = munch.Munch({'user': '******'})
        pagure.cli.admin.do_create_admin_token(args)

        # Retrieve the token
        list_args = munch.Munch({
            'user': None,
            'token': None,
            'active': False,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertNotEqual(output, 'No user "pingou" found\n')
        self.assertEqual(len(output.split('\n')), 2)
        self.assertIn(' -- pingou -- ', output)

        token = output.split(' ', 1)[0]
        current_expiration = output.split(' ', 1)[1]

        # Set the expiration date to the token
        args = munch.Munch({'token': token, 'date': '2017-18-01'})
        self.assertRaises(pagure.exceptions.PagureException,
                          pagure.cli.admin.do_update_admin_token, args)
Ejemplo n.º 5
0
    def test_read_only_namespace_changed(self):
        """ Test the read-only function of pagure-admin to set the status of
        a namespaced project.
        """

        # Before
        args = munch.Munch({
            'project': 'somenamespace/test',
            'user': None,
            'ro': None,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_read_only(args)
        output = output.getvalue()
        self.assertEqual(
            'The current read-only flag of the project somenamespace/test '\
            'is set to True\n', output)

        args = munch.Munch({
            'project': 'somenamespace/test',
            'user': None,
            'ro': 'false',
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_read_only(args)
        output = output.getvalue()
        self.assertEqual(
            'The read-only flag of the project somenamespace/test has been '
            'set to False\n', output)

        # After
        args = munch.Munch({
            'project': 'somenamespace/test',
            'user': None,
            'ro': None,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_read_only(args)
        output = output.getvalue()
        self.assertEqual(
            'The current read-only flag of the project somenamespace/test '\
            'is set to False\n', output)
Ejemplo n.º 6
0
    def test_all(self):
        paths = [mutagen.__path__[0], tests.__path__[0]]

        errors = []
        for path in paths:
            style = pycodestyle.StyleGuide(ignore=self.IGNORE)
            with capture_output() as (o, e):
                style.input_dir(path)
            errors.extend(o.getvalue().splitlines())

        if errors:
            raise Exception("\n".join(errors))
Ejemplo n.º 7
0
 def test_get_watch_get_project(self):
     """ Test the get-watch function of pagure-admin on a regular project.
     """
     args = munch.Munch({
         'project': 'test',
         'user': '******',
     })
     with tests.capture_output() as output:
         pagure.cli.admin.do_get_watch_status(args)
     output = output.getvalue()
     self.assertEqual(
         'On test user: pingou is watching the following items: '
         'issues, pull-requests\n', output)
Ejemplo n.º 8
0
    def test_get_watch_update_project_no_effect(self):
        """ Test the update-watch function of pagure-admin with a regular
        project - nothing changed.
        """

        args = munch.Munch({
            'project': 'test',
            'user': '******',
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_get_watch_status(args)
        output = output.getvalue()
        self.assertEqual(
            'On test user: pingou is watching the following items: '
            'issues, pull-requests\n', output)

        args = munch.Munch({
            'project': 'test',
            'user': '******',
            'status': '1'
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_update_watch_status(args)
        output = output.getvalue()
        self.assertEqual(
            'Updating watch status of pingou to 1 (watch issues and PRs) '
            'on test\n', output)

        args = munch.Munch({
            'project': 'test',
            'user': '******',
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_get_watch_status(args)
        output = output.getvalue()
        self.assertEqual(
            'On test user: pingou is watching the following items: '
            'issues, pull-requests\n', output)
Ejemplo n.º 9
0
 def test_do_list_admin_token_empty(self):
     """ Test the do_list_admin_token function of pagure-admin when there
     are not tokens in the db.
     """
     list_args = munch.Munch({
         'user': None,
         'token': None,
         'active': False,
         'expired': False,
     })
     with tests.capture_output() as output:
         pagure.cli.admin.do_list_admin_token(list_args)
     output = output.getvalue()
     self.assertEqual(output, 'No admin tokens found\n')
Ejemplo n.º 10
0
    def test_do_info_admin_token(self, conf, rinp):
        """ Test the do_info_admin_token function of pagure-admin. """
        # Create an admin token to use
        conf.return_value = True
        rinp.return_value = '1,3,4'

        args = munch.Munch({'user': '******'})
        pagure.cli.admin.do_create_admin_token(args)

        # Retrieve the token
        list_args = munch.Munch({
            'user': None,
            'token': None,
            'active': False,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertNotEqual(output, 'No user "pingou" found\n')
        self.assertEqual(len(output.split('\n')), 2)
        self.assertIn(' -- pingou -- ', output)

        token = output.split(' ', 1)[0]

        args = munch.Munch({'token': token})
        with tests.capture_output() as output:
            pagure.cli.admin.do_info_admin_token(args)
        output = output.getvalue()
        self.assertIn(' -- pingou -- ', output.split('\n', 1)[0])
        self.assertEqual(
            output.split('\n', 1)[1], '''ACLs:
  - issue_create
  - pull_request_comment
  - pull_request_flag
''')
Ejemplo n.º 11
0
    def test_read_only(self):
        """ Test the read-only function of pagure-admin to get status of
        a non-namespaced project.
        """

        args = munch.Munch({
            'project': 'test',
            'user': None,
            'ro': None,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_read_only(args)
        output = output.getvalue()
        self.assertEqual(
            'The current read-only flag of the project test is set to True\n',
            output)
Ejemplo n.º 12
0
    def test_do_update_admin_token(self, conf, rinp):
        """ Test the do_update_admin_token function of pagure-admin. """
        if 'BUILD_ID' in os.environ:
            raise unittest.case.SkipTest('Skipping on jenkins/el7')

        # Create an admin token to use
        conf.return_value = True
        rinp.return_value = '1,2,3'

        args = munch.Munch({'user': '******'})
        pagure.cli.admin.do_create_admin_token(args)

        # Retrieve the token
        list_args = munch.Munch({
            'user': None,
            'token': None,
            'active': False,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertNotEqual(output, 'No user "pingou" found\n')
        self.assertEqual(len(output.split('\n')), 2)
        self.assertIn(' -- pingou -- ', output)

        token = output.split(' ', 1)[0]
        current_expiration = output.strip().split(' -- ', 2)[-1]

        # Before
        list_args = munch.Munch({
            'user': None,
            'token': None,
            'active': True,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertNotEqual(output, 'No admin tokens found\n')
        self.assertEqual(len(output.split('\n')), 2)
        self.assertIn(' -- pingou -- ', output)

        deadline = datetime.datetime.utcnow().date() \
            + datetime.timedelta(days=3)

        # Set the expiration date to the token
        args = munch.Munch({
            'token': token,
            'date': deadline.strftime('%Y-%m-%d')
        })
        pagure.cli.admin.do_update_admin_token(args)

        # After
        list_args = munch.Munch({
            'user': None,
            'token': None,
            'active': True,
            'expired': False,
        })
        with tests.capture_output() as output:
            pagure.cli.admin.do_list_admin_token(list_args)
        output = output.getvalue()
        self.assertEqual(output.split(' ', 1)[0], token)
        self.assertNotEqual(output.strip().split(' -- ', 2)[-1],
                            current_expiration)