From 9a36a4fae0e528cc583d8695d86cd9f9965a1414 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 28 2017 12:58:47 +0000 Subject: Fix retrieve the tokens of a specified user --- diff --git a/pagure/cli/admin.py b/pagure/cli/admin.py index f3dfe5c..50e0097 100644 --- a/pagure/cli/admin.py +++ b/pagure/cli/admin.py @@ -227,7 +227,11 @@ def do_list_admin_token(args): acls = APP.config['ADMIN_API_ACLS'] tokens = pagure.lib.search_token( - SESSION, acls, active=args.active, expired=args.expired) + SESSION, acls, + user=args.user, + active=args.active, + expired=args.expired) + for token in tokens: print('%s -- %s -- %s' % ( token.id, token.user.user, token.expiration)) diff --git a/tests/test_pagure_admin.py b/tests/test_pagure_admin.py index c21ea13..f3d09a1 100644 --- a/tests/test_pagure_admin.py +++ b/tests/test_pagure_admin.py @@ -299,6 +299,31 @@ class PagureAdminAdminTokentests(tests.Modeltests): @patch('pagure.cli.admin._get_input') @patch('pagure.cli.admin._ask_confirmation') + 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': 'pingou'}) + pagure.cli.admin.do_create_admin_token(args) + + # Retrieve all tokens + cmd = ['python', PAGURE_ADMIN, 'admin-token', 'list'] + output = _get_ouput(cmd)[0] + self.assertNotEqual(output, 'No user "pingou" found\n') + self.assertEqual(len(output.split('\n')), 2) + self.assertIn(' -- pingou -- ', output) + + # Retrieve pfrields's tokens + cmd = [ + 'python', PAGURE_ADMIN, + 'admin-token', 'list', '--user', 'pfrields'] + output = _get_ouput(cmd)[0] + self.assertEqual(output, 'No admin tokens found\n') + + @patch('pagure.cli.admin._get_input') + @patch('pagure.cli.admin._ask_confirmation') 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