示例#1
0
 def test_grant_to_user_invalid_param(self):
     """
     Test grant permissions to user with invalid params.
     """
     request = mock.MagicMock()
     request.body = json.dumps({'operations': ['READ'], 'resource': '/v2/some/'})
     grant = GrantToUserView()
     try:
         grant.post(request)
     except InvalidValue, response:
         pass
示例#2
0
 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'])
示例#3
0
 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'])
示例#4
0
    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])
示例#5
0
    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])