예제 #1
0
 def test_grant_to_role_invalid_param(self):
     """
     Test grant permissions to role with missing required params.
     """
     request = mock.MagicMock()
     request.body = json.dumps({'operations': ['READ'], 'resource': '/v2/some/'})
     grant = GrantToRoleView()
     try:
         grant.post(request)
     except MissingValue, response:
         self.assertEqual(response.http_status_code, 400)
         self.assertEqual(response.error_data['property_names'], ['role_id'])
예제 #2
0
 def test_grant_to_role_invalid_param(self):
     """
     Test grant permissions to role with missing required params.
     """
     request = mock.MagicMock()
     request.body = json.dumps({'operations': ['READ'], 'resource': '/v2/some/'})
     grant = GrantToRoleView()
     try:
         grant.post(request)
     except MissingValue, response:
         self.assertEqual(response.http_status_code, 400)
         self.assertEqual(response.error_data['property_names'], ['role_id'])
예제 #3
0
    def test_grant_to_role(self, mock_factory, mock_resp):
        """
        Test grant permissions to role.
        """
        request = mock.MagicMock()
        request.body = json.dumps(
            {'operations': ['READ'], 'role_id': 'test', 'resource': '/v2/some/'})
        mock_factory.role_manager.return_value.add_permissions_to_role.return_value = None
        mock_factory.permission_manager.return_value.operation_names_to_values.return_value = [0]
        grant = GrantToRoleView()
        response = grant.post(request)

        mock_resp.assert_called_once_with(None)
        self.assertTrue(response is mock_resp.return_value)
        mock_factory.role_manager.return_value.add_permissions_to_role.assert_called_once_with(
            'test', '/v2/some/', [0])
예제 #4
0
    def test_grant_to_role(self, mock_factory, mock_resp):
        """
        Test grant permissions to role.
        """
        request = mock.MagicMock()
        request.body = json.dumps(
            {'operations': ['READ'], 'role_id': 'test', 'resource': '/v2/some/'})
        mock_factory.role_manager.return_value.add_permissions_to_role.return_value = None
        mock_factory.permission_manager.return_value.operation_names_to_values.return_value = [0]
        grant = GrantToRoleView()
        response = grant.post(request)

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