def test_admin_actions(self, login_func): """ Test the admin_actions function. """ login_func.return_value = None user = FakeFasUserAdmin() with user_set(pkgdb2.APP, user): output = self.app.get('/admin/actions/') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Actions</h1>' in output.data) self.assertTrue( 'Restrict to package: <input type="text" name="package" />' in output.data) output = self.app.get( '/admin/actions/?page=abc&limit=def&status=ghi&package=test') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Actions</h1>' in output.data) self.assertTrue( 'Restrict to package: <input type="text" name="package" />' in output.data) self.assertTrue( 'class="errors">Incorrect limit provided, using default</' in output.data) self.assertTrue( '<li class="errors">No package exists</li>' in output.data) output = self.app.get('/admin/actions/?package=guake') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Actions</h1>' in output.data) self.assertTrue( 'Restrict to package: <input type="text" name="package" />' in output.data) self.assertTrue( '<p>No actions found</p>' in output.data) # Create some actions to see create_collection(pkgdb2.SESSION) create_package(pkgdb2.SESSION) create_admin_actions(pkgdb2.SESSION, n=2) # set the pagination pkgdb2.APP.config['ITEMS_PER_PAGE'] = 1 # Check the list output = self.app.get('/admin/actions/?status=all') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Actions</h1>' in output.data) self.assertTrue( 'Restrict to package: <input type="text" name="package" />' in output.data) # 2 actions = 2 pages self.assertTrue('<td>1 / 2</td>' in output.data) # Reset the pagination pkgdb2.APP.config['ITEMS_PER_PAGE'] = 50
def test_admin_actions(self, login_func): """ Test the admin_actions function. """ login_func.return_value = None user = FakeFasUserAdmin() with user_set(pkgdb2.APP, user): output = self.app.get('/admin/actions/') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Actions</h1>' in output.data) self.assertTrue( 'Restrict to package: <input type="text" name="package" />' in output.data) output = self.app.get( '/admin/actions/?page=abc&limit=def&status=ghi&package=test') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Actions</h1>' in output.data) self.assertTrue( 'Restrict to package: <input type="text" name="package" />' in output.data) self.assertTrue( 'class="errors">Incorrect limit provided, using default</' in output.data) self.assertTrue( '<li class="errors">No package exists</li>' in output.data) output = self.app.get('/admin/actions/?package=guake') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Actions</h1>' in output.data) self.assertTrue( 'Restrict to package: <input type="text" name="package" />' in output.data) self.assertTrue( '<p>No actions found</p>' in output.data) # Create some actions to see create_collection(pkgdb2.SESSION) create_package(pkgdb2.SESSION) create_admin_actions(pkgdb2.SESSION, n=2) # set the pagination pkgdb2.APP.config['ITEMS_PER_PAGE'] = 1 # Check the list output = self.app.get('/admin/actions/?status=all') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Actions</h1>' in output.data) self.assertTrue( 'Restrict to package: <input type="text" name="package" />' in output.data) # 3 actions = 3 pages self.assertTrue('<td>1 / 3</td>' in output.data) # Reset the pagination pkgdb2.APP.config['ITEMS_PER_PAGE'] = 50
def test_package_request_edit(self, login_func, mock_func): """ Test the package_request_edit function. """ login_func.return_value = None mock_func.get_packagers.return_value = ['pingou', 'toshio'] mock_func.log.return_value = 'foo bar' create_package_acl(self.session) data = { 'branches': ['epel7'], } user = FakeFasUser() user.username = '******' with user_set(pkgdb2.APP, user): output = self.app.post('/package/foobar/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue( '<li class="errors">No action found with this identifier.</li>' in output.data) create_admin_actions(self.session) # Package name / Admin Action do not match output = self.app.post('/package/foobar/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue( '<li class="errors">The specified action (id:1) is not ' 'related to the specified package: foobar.</li>' in output.data) # User not allowed to view request output = self.app.post('/package/guake/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue( '<li class="errors">Only package adminitrators (`approveacls`)' ' and the requester can review pending branch requests</li>' in output.data) # Before the edit user = FakeFasUser() user.username = '******' with user_set(pkgdb2.APP, user): output = self.app.get('/package/guake/requests/1') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Update request: 1</h1>' in output.data) self.assertTrue('<option selected value="Pending">' in output.data) csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = { 'status': 'Awaiting Review', 'csrf_token': csrf_token, } # User cannot approve their own request output = self.app.post('/package/guake/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue( '<td class="errors">Not a valid choice</td>' in output.data) data = { 'status': 'Obsolete', 'csrf_token': csrf_token, } user = FakeFasUser() with user_set(pkgdb2.APP, user): # Admin cannot obsolete a request that is not their output = self.app.post('/package/guake/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue( '<td class="errors">Not a valid choice</td>' in output.data) data['status'] = 'Awaiting Review' # All good output = self.app.post('/package/guake/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue('<li class="message">foo bar</li>' in output.data)
def test_package_request_edit(self, login_func, mock_func): """ Test the package_request_edit function. """ login_func.return_value = None mock_func.get_packagers.return_value = ['pingou', 'toshio'] mock_func.log.return_value = 'foo bar' create_package_acl(self.session) data = { 'branches': ['epel7'], } user = FakeFasUser() user.username = '******' with user_set(pkgdb2.APP, user): output = self.app.post( '/package/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue( '<li class="errors">No action found with this identifier.</li>' in output.data) create_admin_actions(self.session) # User not allowed to view request output = self.app.post( '/package/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue( '<li class="errors">Only package adminitrators (`approveacls`)' ' and the requester can review pending branch requests</li>' in output.data) # Before the edit user = FakeFasUser() user.username = '******' with user_set(pkgdb2.APP, user): output = self.app.get('/package/requests/1') self.assertEqual(output.status_code, 200) self.assertTrue('<h1>Update request: 1</h1>' in output.data) self.assertTrue( '<option selected value="Pending">' in output.data) csrf_token = output.data.split( 'name="csrf_token" type="hidden" value="')[1].split('">')[0] data = { 'status': 'Awaiting Review', 'csrf_token': csrf_token, } # User cannot approve their own request output = self.app.post( '/package/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue( '<td class="errors">Not a valid choice</td>' in output.data) data = { 'status': 'Obsolete', 'csrf_token': csrf_token, } user = FakeFasUser() with user_set(pkgdb2.APP, user): # Admin cannot obsolete a request that is not their output = self.app.post( '/package/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue( '<td class="errors">Not a valid choice</td>' in output.data) data['status'] = 'Awaiting Review' # All good output = self.app.post( '/package/requests/1', follow_redirects=True, data=data) self.assertEqual(output.status_code, 200) self.assertTrue('<li class="message">foo bar</li>'in output.data)