Esempio n. 1
0
    def test_api_admin_action(self, login_func, mock_func):
        """ Test the api_admin_action function.  """

        output = self.app.get('/api/admin/action/')
        data = json.loads(output.data)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(
            data['error'], 'No Admin action with this identifier found')

        # Unretire the package
        from test_flask_ui_packages import FlaskUiPackagesTest
        test = FlaskUiPackagesTest('test_package_unretire')
        test.session = self.session
        test.app = self.app
        test.test_package_unretire()

        output = self.app.get('/api/admin/action/1')
        data = json.loads(output.data)
        self.assertEqual(
            sorted(data.keys()),
            ['action', 'collection', 'date_created', 'date_updated',
             'id', 'info', 'message', 'output', 'package',
             'status', 'user'])
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['action'], 'request.unretire')
        self.assertEqual(data['collection']['branchname'], 'f18')
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['package']['name'], 'guake')
        self.assertEqual(data['package']['acls'], [])
        self.assertEqual(data['status'], 'Awaiting Review')
        self.assertEqual(data['user'], 'toshio')

        output = self.app.get('/api/admin/action/?actionid=1')
        data = json.loads(output.data)
        self.assertEqual(
            sorted(data.keys()),
            ['action', 'collection', 'date_created', 'date_updated',
             'id', 'info', 'message', 'output', 'package',
             'status', 'user'])
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['action'], 'request.unretire')
        self.assertEqual(data['collection']['branchname'], 'f18')
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['package']['name'], 'guake')
        self.assertEqual(data['package']['acls'], [])
        self.assertEqual(data['status'], 'Awaiting Review')
        self.assertEqual(data['user'], 'toshio')

        output = self.app.get('/api/admin/action/100')
        data = json.loads(output.data)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(
            data['error'], 'No Admin action with this identifier found')
Esempio n. 2
0
    def test_api_admin_action(self, login_func, mock_func):
        """ Test the api_admin_action function.  """

        output = self.app.get('/api/admin/action/')
        data = json.loads(output.data)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(
            data['error'], 'No Admin action with this identifier found')

        # Unretire the package
        from test_flask_ui_packages import FlaskUiPackagesTest
        test = FlaskUiPackagesTest('test_package_unretire')
        test.session = self.session
        test.app = self.app
        test.test_package_unretire()

        output = self.app.get('/api/admin/action/1')
        data = json.loads(output.data)
        self.assertEqual(
            sorted(data.keys()),
            ['action', 'collection', 'date_created', 'date_updated',
             'from_collection', 'id', 'info', 'message', 'output', 'package',
             'status', 'user'])
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['action'], 'request.unretire')
        self.assertEqual(data['collection']['branchname'], 'f18')
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['package']['name'], 'guake')
        self.assertEqual(data['package']['acls'], [])
        self.assertEqual(data['status'], 'Awaiting Review')
        self.assertEqual(data['user'], 'toshio')

        output = self.app.get('/api/admin/action/?actionid=1')
        data = json.loads(output.data)
        self.assertEqual(
            sorted(data.keys()),
            ['action', 'collection', 'date_created', 'date_updated',
             'from_collection', 'id', 'info', 'message', 'output', 'package',
             'status', 'user'])
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['action'], 'request.unretire')
        self.assertEqual(data['collection']['branchname'], 'f18')
        self.assertEqual(data['output'], 'ok')
        self.assertEqual(data['package']['name'], 'guake')
        self.assertEqual(data['package']['acls'], [])
        self.assertEqual(data['status'], 'Awaiting Review')
        self.assertEqual(data['user'], 'toshio')

        output = self.app.get('/api/admin/action/100')
        data = json.loads(output.data)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(
            data['error'], 'No Admin action with this identifier found')
Esempio n. 3
0
    def test_api_admin_actions(self, login_func, mock_func):
        """ Test the api_admin_actions function.  """

        output = self.app.get('/api/admin/actions/')
        data = json.loads(output.data)
        self.assertEqual(data['actions'], [])
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(
            data['error'], 'No actions found for these parameters')

        output = self.app.get('/api/admin/actions/?page=abc&limit=abcd')
        data = json.loads(output.data)
        self.assertEqual(data['actions'], [])
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(
            data['error'], 'No actions found for these parameters')

        # Unretire the package
        from test_flask_ui_packages import FlaskUiPackagesTest
        test = FlaskUiPackagesTest('test_package_unretire')
        test.session = self.session
        test.app = self.app
        test.test_package_unretire()

        output = self.app.get('/api/admin/actions/?page=2&limit=1')
        data = json.loads(output.data)
        self.assertEqual(data['actions'], [])
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(
            data['error'], 'No actions found for these parameters')

        output = self.app.get('/api/admin/actions/?package=guake')
        data = json.loads(output.data)
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(len(data['actions']), 1)
        self.assertEqual(data['actions'][0]['action'], 'request.unretire')
        self.assertEqual(
            data['actions'][0]['collection']['branchname'], 'f18')
        self.assertEqual(data['actions'][0]['package']['name'], 'guake')
        self.assertEqual(data['actions'][0]['package']['acls'], [])
        self.assertEqual(data['output'], 'ok')
        self.assertFalse('error' in data)

        output = self.app.get('/api/admin/actions/?status=Awaiting Review')
        data = json.loads(output.data)
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(len(data['actions']), 1)
        self.assertEqual(data['actions'][0]['action'], 'request.unretire')
        self.assertEqual(
            data['actions'][0]['collection']['branchname'], 'f18')
        self.assertEqual(data['actions'][0]['package']['name'], 'guake')
        self.assertEqual(data['actions'][0]['package']['acls'], [])
        self.assertEqual(data['output'], 'ok')
        self.assertFalse('error' in data)

        output = self.app.get('/api/admin/actions/?action=request.unretire')
        data = json.loads(output.data)
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(len(data['actions']), 1)
        self.assertEqual(data['actions'][0]['action'], 'request.unretire')
        self.assertEqual(
            data['actions'][0]['collection']['branchname'], 'f18')
        self.assertEqual(data['actions'][0]['package']['name'], 'guake')
        self.assertEqual(data['actions'][0]['package']['acls'], [])
        self.assertEqual(data['output'], 'ok')
        self.assertFalse('error' in data)

        output = self.app.get('/api/admin/actions/?packager=pingou')
        data = json.loads(output.data)
        self.assertEqual(data['actions'], [])
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(
            data['error'], 'No actions found for these parameters')
Esempio n. 4
0
    def test_api_admin_action_edit_status(self, login_func):
        """ Test the api_admin_action_edit_status function.  """
        login_func.return_value = None

        # Redirect as you are not admin
        user = FakeFasUser()

        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/admin/action/status')
            self.assertEqual(output.status_code, 302)

        user = FakeFasUserAdmin()

        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/admin/action/status')
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                sorted(data),
                ['error', 'error_detail', 'output']
            )
            self.assertEqual(
                data['error'], "Invalid input submitted")

            self.assertEqual(
                data['output'], "notok")

            self.assertEqual(
                sorted(data['error_detail']),
                [
                    'id: This field is required.',
                    'status: Not a valid choice',
                ]
            )

        data = {
            'id': 'foo',
            'status': 'Approved',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "Invalid input submitted",
                    "error_detail": [
                        "id: Field must contain a number",
                    ],
                    "output": "notok"
                }

            )

        # Have another test create a pending Admin Action
        from test_flask_ui_packages import FlaskUiPackagesTest
        uitest = FlaskUiPackagesTest('test_package_request_branch')
        uitest.session = self.session
        uitest.app = self.app
        uitest.test_package_request_branch()

        # Before edit:
        output = self.app.get('/api/admin/actions/')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)
        self.assertEqual(len(data['actions']), 1)
        action = data['actions'][0]
        self.assertEqual(action['action'], "request.branch")
        self.assertEqual(action['id'], 1)
        self.assertEqual(action['collection']['branchname'], 'el6')
        self.assertEqual(action['package']['name'], 'guake')
        self.assertEqual(action['user'], 'pingou')

        data = {
            'id': 1,
            'status': 'Denied',
        }

        # User is not an admin
        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 302)

        # User is an admin
        user = FakeFasUserAdmin()
        with user_set(pkgdb2.APP, user):

            data = {
                'id': 10,
                'status': 'Denied',
            }

            # Wrong identifier
            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "No Admin action with this identifier found",
                    "output": "notok"
                }
            )

            data = {
                'id': 1,
                'status': 'Denied',
            }

            # Missing explanatory message for the user
            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "You must provide a message explaining why "
                    "when you block or deny a request",
                    "output": "notok"
                }
            )

            #Only the person creating the request can obsolete it
            data = {
                'id': 1,
                'status': 'Obsolete',
                'message': 'Because this is a test suite',
            }

            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "Only the person having made the request can "
                    "change its status to obsolete",
                    "output": "notok"
                }
            )

            # All good
            data = {
                'id': 1,
                'status': 'Denied',
                'message': 'Because this is a test suite',
            }

            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": [
                        "user: admin updated action: 1 of guake from "
                        "`Awaiting Review` to `Denied` with message: "
                        "Because this is a test suite"
                    ],
                    "output": "ok"
                }
            )

        # After Denying:
        output = self.app.get('/api/admin/actions')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)
        self.assertEqual(len(data['actions']), 1)
        action = data['actions'][0]
        self.assertEqual(action['action'], "request.branch")
        self.assertEqual(action['id'], 1)
        self.assertEqual(action['collection']['branchname'], 'el6')
        self.assertEqual(action['package']['name'], 'guake')
        self.assertEqual(action['user'], 'pingou')
        self.assertEqual(action['status'], 'Denied')


        # User is an admin
        user = FakeFasUserAdmin()
        with user_set(pkgdb2.APP, user):
            data = {
                'id': 1,
                'status': 'Approved',
            }

            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": [
                        "user: admin updated action: 1 of guake from "
                        "`Denied` to `Approved`"
                    ],
                    "output": "ok"
                }
            )

        # After approving:
        output = self.app.get('/api/admin/actions')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)
        self.assertEqual(len(data['actions']), 1)
        action = data['actions'][0]
        self.assertEqual(action['action'], "request.branch")
        self.assertEqual(action['id'], 1)
        self.assertEqual(action['collection']['branchname'], 'el6')
        self.assertEqual(action['package']['name'], 'guake')
        self.assertEqual(action['user'], 'pingou')
        self.assertEqual(action['status'], 'Approved')
Esempio n. 5
0
    def test_admin_action_edit_status(self, login_func):
        """ Test the admin_action_edit_status function. """
        login_func.return_value = None

        user = FakeFasUser()

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/admin/action/1/status')
            self.assertEqual(output.status_code, 302)

        user = FakeFasUserAdmin()

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/admin/action/1/status')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">No action found with this identifier.</li>'
                in output.data)

        # Have another test create a pending Admin Action
        from test_flask_ui_packages import FlaskUiPackagesTest
        uitest = FlaskUiPackagesTest('test_package_request_branch')
        uitest.session = self.session
        uitest.app = self.app
        uitest.test_package_request_branch()

        with user_set(pkgdb2.APP, user):
            # Before
            # No action Pending
            output = self.app.get('/admin/actions/?status=Pending')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Actions</h1>' in output.data)
            self.assertFalse(
                '<td class="col_odd">request.branch</td>' in output.data)
            self.assertFalse(
                '<td class="col_odd" >Awaiting Review</td>' in output.data)

            # But one action in total
            output = self.app.get('/admin/actions/?status=All')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Actions</h1>' in output.data)
            self.assertTrue(
                '<td class="col_odd">request.branch</td>' in output.data)
            self.assertEqual(
                output.data.count('<td class="col_odd">request.branch</td>'),
                1
            )
            self.assertTrue(
                '<td class="col_odd" >Awaiting Review</td>' in output.data)

            # One action Awaiting Review
            output = self.app.get('/admin/actions/?status=Awaiting Review')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Actions</h1>' in output.data)
            self.assertTrue(
                '<td class="col_odd">request.branch</td>' in output.data)
            self.assertEqual(
                output.data.count('<td class="col_odd">request.branch</td>'),
                1
            )
            self.assertTrue(
                '<td class="col_odd" >Awaiting Review</td>' in output.data)

            # Update
            output = self.app.get('/admin/action/1/status')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Update admin action: 1</h1>' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'status': 'Approved',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/admin/action/1/status', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">user: admin updated action: 1 of guake '
                'from `Awaiting Review` to `Approved`</li>' in output.data)

            # After
            output = self.app.get('/admin/actions/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Actions</h1>' in output.data)
            self.assertFalse(
                '<td class="col_odd">request.branch</td>' in output.data)
Esempio n. 6
0
    def test_api_admin_actions(self, login_func, mock_func):
        """ Test the api_admin_actions function.  """

        output = self.app.get('/api/admin/actions/')
        data = json.loads(output.data)
        self.assertEqual(data['actions'], [])
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(data['error'],
                         'No actions found for these parameters')

        output = self.app.get('/api/admin/actions/?page=abc&limit=abcd')
        data = json.loads(output.data)
        self.assertEqual(data['actions'], [])
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(data['error'],
                         'No actions found for these parameters')

        # Unretire the package
        from test_flask_ui_packages import FlaskUiPackagesTest
        test = FlaskUiPackagesTest('test_package_unretire')
        test.session = self.session
        test.app = self.app
        test.test_package_unretire()

        output = self.app.get('/api/admin/actions/?page=2&limit=1')
        data = json.loads(output.data)
        self.assertEqual(data['actions'], [])
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(data['error'],
                         'No actions found for these parameters')

        output = self.app.get('/api/admin/actions/?package=guake')
        data = json.loads(output.data)
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(len(data['actions']), 1)
        self.assertEqual(data['actions'][0]['action'], 'request.unretire')
        self.assertEqual(data['actions'][0]['collection']['branchname'], 'f18')
        self.assertEqual(data['actions'][0]['package']['name'], 'guake')
        self.assertEqual(data['actions'][0]['package']['acls'], [])
        self.assertEqual(data['output'], 'ok')
        self.assertFalse('error' in data)

        output = self.app.get('/api/admin/actions/?status=Awaiting Review')
        data = json.loads(output.data)
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(len(data['actions']), 1)
        self.assertEqual(data['actions'][0]['action'], 'request.unretire')
        self.assertEqual(data['actions'][0]['collection']['branchname'], 'f18')
        self.assertEqual(data['actions'][0]['package']['name'], 'guake')
        self.assertEqual(data['actions'][0]['package']['acls'], [])
        self.assertEqual(data['output'], 'ok')
        self.assertFalse('error' in data)

        output = self.app.get('/api/admin/actions/?action=request.unretire')
        data = json.loads(output.data)
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(len(data['actions']), 1)
        self.assertEqual(data['actions'][0]['action'], 'request.unretire')
        self.assertEqual(data['actions'][0]['collection']['branchname'], 'f18')
        self.assertEqual(data['actions'][0]['package']['name'], 'guake')
        self.assertEqual(data['actions'][0]['package']['acls'], [])
        self.assertEqual(data['output'], 'ok')
        self.assertFalse('error' in data)

        output = self.app.get('/api/admin/actions/?packager=pingou')
        data = json.loads(output.data)
        self.assertEqual(data['actions'], [])
        self.assertEqual(data['page'], 1)
        self.assertEqual(data['page_total'], 1)
        self.assertEqual(data['output'], 'notok')
        self.assertEqual(data['error'],
                         'No actions found for these parameters')
Esempio n. 7
0
    def test_api_admin_action_edit_status(self, login_func):
        """ Test the api_admin_action_edit_status function.  """
        login_func.return_value = None

        # Redirect as you are not admin
        user = FakeFasUser()

        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/admin/action/status')
            self.assertEqual(output.status_code, 302)

        user = FakeFasUserAdmin()

        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/admin/action/status')
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(sorted(data), ['error', 'error_detail', 'output'])
            self.assertEqual(data['error'], "Invalid input submitted")

            self.assertEqual(data['output'], "notok")

            self.assertEqual(sorted(data['error_detail']), [
                'id: This field is required.',
                'status: Not a valid choice',
            ])

        data = {
            'id': 'foo',
            'status': 'Approved',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data, {
                    "error": "Invalid input submitted",
                    "error_detail": [
                        "id: Field must contain a number",
                    ],
                    "output": "notok"
                })

        # Have another test create a pending Admin Action
        from test_flask_ui_packages import FlaskUiPackagesTest
        uitest = FlaskUiPackagesTest('test_package_request_branch')
        uitest.session = self.session
        uitest.app = self.app
        uitest.test_package_request_branch()

        # Before edit:
        output = self.app.get('/api/admin/actions/')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)
        self.assertEqual(len(data['actions']), 1)
        action = data['actions'][0]
        self.assertEqual(action['action'], "request.branch")
        self.assertEqual(action['id'], 1)
        self.assertEqual(action['collection']['branchname'], 'el6')
        self.assertEqual(action['package']['name'], 'guake')
        self.assertEqual(action['user'], 'pingou')

        data = {
            'id': 1,
            'status': 'Denied',
        }

        # User is not an admin
        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 302)

        # User is an admin
        user = FakeFasUserAdmin()
        with user_set(pkgdb2.APP, user):

            data = {
                'id': 10,
                'status': 'Denied',
            }

            # Wrong identifier
            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data, {
                    "error": "No Admin action with this identifier found",
                    "output": "notok"
                })

            data = {
                'id': 1,
                'status': 'Denied',
            }

            # Missing explanatory message for the user
            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data, {
                    "error": "You must provide a message explaining why "
                    "when you block or deny a request",
                    "output": "notok"
                })

            #Only the person creating the request can obsolete it
            data = {
                'id': 1,
                'status': 'Obsolete',
                'message': 'Because this is a test suite',
            }

            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data, {
                    "error": "Only the person having made the request can "
                    "change its status to obsolete",
                    "output": "notok"
                })

            # All good
            data = {
                'id': 1,
                'status': 'Denied',
                'message': 'Because this is a test suite',
            }

            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data, {
                    "messages": [
                        "user: admin updated action: 1 of guake from "
                        "`Awaiting Review` to `Denied` with message: "
                        "Because this is a test suite"
                    ],
                    "output":
                    "ok"
                })

        # After Denying:
        output = self.app.get('/api/admin/actions')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)
        self.assertEqual(len(data['actions']), 1)
        action = data['actions'][0]
        self.assertEqual(action['action'], "request.branch")
        self.assertEqual(action['id'], 1)
        self.assertEqual(action['collection']['branchname'], 'el6')
        self.assertEqual(action['package']['name'], 'guake')
        self.assertEqual(action['user'], 'pingou')
        self.assertEqual(action['status'], 'Denied')

        # User is an admin
        user = FakeFasUserAdmin()
        with user_set(pkgdb2.APP, user):
            data = {
                'id': 1,
                'status': 'Approved',
            }

            output = self.app.post('/api/admin/action/status', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data, {
                    "messages": [
                        "user: admin updated action: 1 of guake from "
                        "`Denied` to `Approved`"
                    ],
                    "output":
                    "ok"
                })

        # After approving:
        output = self.app.get('/api/admin/actions')
        self.assertEqual(output.status_code, 200)
        data = json.loads(output.data)
        self.assertEqual(len(data['actions']), 1)
        action = data['actions'][0]
        self.assertEqual(action['action'], "request.branch")
        self.assertEqual(action['id'], 1)
        self.assertEqual(action['collection']['branchname'], 'el6')
        self.assertEqual(action['package']['name'], 'guake')
        self.assertEqual(action['user'], 'pingou')
        self.assertEqual(action['status'], 'Approved')
Esempio n. 8
0
    def test_admin_action_edit_status(self, login_func):
        """ Test the admin_action_edit_status function. """
        login_func.return_value = None

        user = FakeFasUser()

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/admin/action/1/status')
            self.assertEqual(output.status_code, 302)

        user = FakeFasUserAdmin()

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/admin/action/1/status')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">No action found with this identifier.</li>'
                in output.data)

        # Have another test create a pending Admin Action
        from test_flask_ui_packages import FlaskUiPackagesTest
        uitest = FlaskUiPackagesTest('test_package_request_branch')
        uitest.session = self.session
        uitest.app = self.app
        uitest.test_package_request_branch()

        with user_set(pkgdb2.APP, user):
            # Before
            # No action Pending
            output = self.app.get('/admin/actions/?status=Pending')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Actions</h1>' in output.data)
            self.assertFalse(
                '<td class="col_odd">request.branch</td>' in output.data)
            self.assertFalse(
                '<td class="col_odd" >Awaiting Review</td>' in output.data)

            # But one action in total
            output = self.app.get('/admin/actions/?status=All')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Actions</h1>' in output.data)
            self.assertTrue(
                '<td class="col_odd">request.branch</td>' in output.data)
            self.assertEqual(
                output.data.count('<td class="col_odd">request.branch</td>'),
                1
            )
            self.assertTrue(
                '<td class="col_odd" >\n        Awaiting Review\n      </td>'
                in output.data)

            # One action Awaiting Review
            output = self.app.get('/admin/actions/?status=Awaiting Review')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Actions</h1>' in output.data)
            self.assertTrue(
                '<td class="col_odd">request.branch</td>' in output.data)
            self.assertEqual(
                output.data.count('<td class="col_odd">request.branch</td>'),
                1
            )
            self.assertTrue(
                '<td class="col_odd" >\n        Awaiting Review\n      </td>'
                in output.data)

            # Update
            output = self.app.get('/admin/action/1/status')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Update admin action: 1</h1>' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'status': 'Approved',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/admin/action/1/status', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">user: admin updated action: 1 of guake '
                'from `Awaiting Review` to `Approved`</li>' in output.data)

            # After
            output = self.app.get('/admin/actions/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<h1>Actions</h1>' in output.data)
            self.assertFalse(
                '<td class="col_odd">request.branch</td>' in output.data)