Exemple #1
0
class TestRevokeFromRoleView(unittest.TestCase):
    """
    Test revoke permission from role.
    """
    @mock.patch('pulp.server.webservices.views.decorators._verify_auth',
                new=assert_auth_EXECUTE())
    @mock.patch(
        'pulp.server.webservices.views.permissions.generate_json_response')
    @mock.patch('pulp.server.webservices.views.permissions.factory')
    def test_revoke_from_role(self, mock_factory, mock_resp):
        """
        Test revoke permissions from role.
        """
        request = mock.MagicMock()
        request.body = json.dumps({
            'operations': ['READ'],
            'role_id': 'test',
            'resource': '/v2/some/'
        })
        mock_factory.role_manager.return_value.remove_permissions_from_role.return_value = None
        mock_factory.permission_manager.return_value.operation_names_to_values.return_value = [
            0
        ]
        revoke = RevokeFromRoleView()
        response = revoke.post(request)

        mock_resp.assert_called_once_with(None)
        self.assertTrue(response is mock_resp.return_value)
        mock_factory.role_manager.return_value.remove_permissions_from_role.assert_called_once_with(
            'test', '/v2/some/', [0])

    @mock.patch('pulp.server.webservices.views.decorators._verify_auth',
                new=assert_auth_EXECUTE())
    def test_revoke_from_role_invalid_param(self):
        """
        Test revoke permissions from role with missing required params.
        """
        request = mock.MagicMock()
        request.body = json.dumps({
            'operations': ['READ'],
            'resource': '/v2/some/'
        })
        revoke = RevokeFromRoleView()
        try:
            revoke.post(request)
        except MissingValue, response:
            self.assertEqual(response.http_status_code, 400)
            self.assertEqual(response.error_data['property_names'],
                             ['role_id'])
        else:
Exemple #2
0
class TestGrantToUserView(unittest.TestCase):
    """
    Test grant permission to user.
    """
    @mock.patch('pulp.server.webservices.views.decorators._verify_auth',
                new=assert_auth_EXECUTE())
    @mock.patch(
        'pulp.server.webservices.views.permissions.generate_json_response')
    @mock.patch('pulp.server.webservices.views.permissions.factory')
    def test_grant_to_user(self, mock_factory, mock_resp):
        """
        Test grant permissions to user.
        """
        request = mock.MagicMock()
        request.body = json.dumps({
            'operations': ['READ'],
            'login': '******',
            'resource': '/v2/some/'
        })
        mock_factory.permission_manager.return_value.grant.return_value = None
        mock_factory.permission_manager.return_value.operation_names_to_values.return_value = [
            0
        ]
        grant = GrantToUserView()
        response = grant.post(request)

        mock_resp.assert_called_once_with(None)
        self.assertTrue(response is mock_resp.return_value)
        mock_factory.permission_manager.return_value.grant.assert_called_once_with(
            '/v2/some/', 'test', [0])

    @mock.patch('pulp.server.webservices.views.decorators._verify_auth',
                new=assert_auth_EXECUTE())
    def test_grant_to_user_invalid_param(self):
        """
        Test grant permissions to user with missing required params.
        """
        request = mock.MagicMock()
        request.body = json.dumps({
            'operations': ['READ'],
            'resource': '/v2/some/'
        })
        grant = GrantToUserView()
        try:
            grant.post(request)
        except MissingValue, response:
            self.assertEqual(response.http_status_code, 400)
            self.assertEqual(response.error_data['property_names'], ['login'])
        else:
Exemple #3
0
class TestConsumerGroupUnassociateActionView(unittest.TestCase):
    """
    Tests consumer group membership.
    """
    @mock.patch('pulp.server.webservices.controllers.decorators._verify_auth',
                new=assert_auth_EXECUTE())
    @mock.patch(
        'pulp.server.webservices.views.consumer_groups.generate_json_response_with_pulp_encoder'
    )
    @mock.patch('pulp.server.webservices.views.consumer_groups.factory')
    def test_cons_group_unassociation_view(self, mock_factory, mock_resp):
        """
        Test consumer group unassociate a consumer.
        """
        grp = {'id': 'my-group', 'consumer_ids': []}
        mock_factory.consumer_group_manager.return_value.unassociate.return_value = 'ok'
        mock_factory.consumer_group_query_manager.return_value.get_group.return_value = grp
        request = mock.MagicMock()
        request.body_as_json = {'criteria': {'filters': {'id': 'c1'}}}
        consumer_group_unassociate = ConsumerGroupUnassociateActionView()
        response = consumer_group_unassociate.post(request, 'my-group')

        mock_resp.assert_called_once_with([])
        self.assertTrue(response is mock_resp.return_value)