def test_comment_update(self):
        # Configure the mock
        comment = test_data._generate_basic_comment(id=test_data.comment_update_request_data["id"])
        actions.db.Comment.get.return_value = [comment]

        # Mock actions
        default_user = {"user": "******"}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Store previous user (needed to check that it has not been modified)
        previous_user_id = comment.user_id

        # Call the action
        result = actions.datarequest_comment_update(self.context, test_data.comment_update_request_data)

        # Assertions
        actions.db.init_db.assert_called_once_with(self.context["model"])
        actions.tk.check_access.assert_called_once_with(
            constants.DATAREQUEST_COMMENT_UPDATE, self.context, test_data.comment_update_request_data
        )
        actions.db.Comment.get.assert_called_once_with(id=test_data.comment_update_request_data["id"])
        actions.validator.validate_comment.assert_called_once_with(self.context, test_data.comment_update_request_data)

        self.context["session"].add.assert_called_once_with(comment)
        self.context["session"].commit.assert_called_once()

        # Check the object stored in the database
        self.assertEquals(previous_user_id, comment.user_id)
        self.assertEquals(test_data.comment_update_request_data["datarequest_id"], comment.datarequest_id)
        self.assertEquals(test_data.comment_update_request_data["comment"], comment.comment)

        # Check the result
        self._check_comment(comment, result, default_user)
Example #2
0
    def test_comment_update(self):
        # Configure the mock
        comment = test_data._generate_basic_comment(id=test_data.comment_update_request_data['id'])
        actions.db.Comment.get.return_value = [comment]

        # Mock actions
        default_user = {'user': '******'}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Store previous user (needed to check that it has not been modified)
        previous_user_id = comment.user_id

        # Call the action
        result = actions.datarequest_comment_update(self.context, test_data.comment_update_request_data)

        # Assertions
        actions.db.init_db.assert_called_once_with(self.context['model'])
        actions.tk.check_access.assert_called_once_with(constants.DATAREQUEST_COMMENT_UPDATE, self.context, test_data.comment_update_request_data)
        actions.db.Comment.get.assert_called_once_with(id=test_data.comment_update_request_data['id'])
        actions.validator.validate_comment.assert_called_once_with(self.context, test_data.comment_update_request_data)

        self.context['session'].add.assert_called_once_with(comment)
        self.context['session'].commit.assert_called_once()

        # Check the object stored in the database
        self.assertEquals(previous_user_id, comment.user_id)
        self.assertEquals(test_data.comment_update_request_data['datarequest_id'], comment.datarequest_id)
        self.assertEquals(test_data.comment_update_request_data['comment'], comment.comment)

        # Check the result
        self._check_comment(comment, result, default_user)
    def test_comment_list(self, sort=None, desc=False):
        # Configure mock
        comments = []
        for i in range(0, 5):
            comments.append(test_data._generate_basic_comment())

        actions.db.Comment.get_ordered_by_date.return_value = comments

        # User
        default_user = {'user': '******'}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Call the function
        params = test_data.comment_show_request_data.copy()
        params.pop('id')

        if sort:
            params['sort'] = sort

        results = actions.list_datarequest_comments(self.context, params)

        # Check that the DB has been called appropriately
        actions.db.Comment.get_ordered_by_date.assert_called_once_with(datarequest_id=test_data.comment_show_request_data['datarequest_id'],
                                                                       desc=desc)

        # Check that the response is OK
        for i in range(0, len(results)):
            self._check_comment(comments[i], results[i], default_user)
Example #4
0
    def test_comment_list(self, sort=None, desc=False):
        # Configure mock
        comments = []
        for i in range(0, 5):
            comments.append(test_data._generate_basic_comment())

        actions.db.Comment.get_ordered_by_date.return_value = comments

        # User
        default_user = {'user': '******'}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Call the function
        params = test_data.comment_show_request_data.copy()
        params.pop('id')

        if sort:
            params['sort'] = sort

        results = actions.datarequest_comment_list(self.context, params)

        # Check that the DB has been called appropriately
        actions.db.Comment.get_ordered_by_date.assert_called_once_with(
            datarequest_id=test_data.
            comment_show_request_data['datarequest_id'],
            desc=desc)

        # Check that the response is OK
        for i in range(0, len(results)):
            self._check_comment(comments[i], results[i], default_user)
Example #5
0
    def test_comment_show(self):
        # Configure mock
        comment = test_data._generate_basic_comment()
        actions.db.Comment.get.return_value = [comment]

        # User
        default_user = {'user': '******'}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Call the function
        result = actions.datarequest_comment_show(self.context, test_data.comment_show_request_data)

        # Check that the response is OK
        self._check_comment(comment, result, default_user)
    def test_comment_show(self):
        # Configure mock
        comment = test_data._generate_basic_comment()
        actions.db.Comment.get.return_value = [comment]

        # User
        default_user = {"user": "******"}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Call the function
        result = actions.datarequest_comment_show(self.context, test_data.comment_show_request_data)

        # Check that the response is OK
        self._check_comment(comment, result, default_user)
Example #7
0
    def test_comment_list(self):
        # Configure mock
        comments = []
        for i in range(0, 5):
            comments.append(test_data._generate_basic_comment())

        actions.db.Comment.get_ordered_by_date.return_value = comments

        # User
        default_user = {'user': '******'}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Call the function
        results = actions.datarequest_comment_list(self.context, test_data.comment_show_request_data)

        # Check that the response is OK
        for i in range(0, len(results)):
            self._check_comment(comments[i], results[i], default_user)
    def test_comment_list(self):
        # Configure mock
        comments = []
        for i in range(0, 5):
            comments.append(test_data._generate_basic_comment())

        actions.db.Comment.get_ordered_by_date.return_value = comments

        # User
        default_user = {"user": "******"}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Call the function
        results = actions.datarequest_comment_list(self.context, test_data.comment_show_request_data)

        # Check that the response is OK
        for i in range(0, len(results)):
            self._check_comment(comments[i], results[i], default_user)
Example #9
0
    def test_comment_delete(self):
        # Configure the mock
        comment = test_data._generate_basic_comment(id=test_data.comment_update_request_data['id'])
        actions.db.Comment.get.return_value = [comment]

        default_user = {'user': '******'}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Call the function
        expected_data_dict = test_data.comment_delete_request_data.copy()
        result = actions.datarequest_comment_delete(self.context, test_data.comment_delete_request_data)

        # Assertions
        actions.db.init_db.assert_called_once_with(self.context['model'])
        actions.tk.check_access.assert_called_once_with(constants.DATAREQUEST_COMMENT_DELETE, self.context, expected_data_dict)
        self.context['session'].delete.assert_called_once_with(comment)
        self.context['session'].commit.assert_called_once_with()

        self._check_comment(comment, result, default_user)
    def test_comment_delete(self):
        # Configure the mock
        comment = test_data._generate_basic_comment(id=test_data.comment_update_request_data['id'])
        actions.db.Comment.get.return_value = [comment]

        default_user = {'user': '******'}
        test_data._initialize_basic_actions(actions, default_user, None, None)

        # Call the function
        expected_data_dict = test_data.comment_delete_request_data.copy()
        result = actions.delete_datarequest_comment(self.context, test_data.comment_delete_request_data)

        # Assertions
        actions.db.init_db.assert_called_once_with(self.context['model'])
        actions.tk.check_access.assert_called_once_with(constants.DELETE_DATAREQUEST_COMMENT, self.context, expected_data_dict)
        self.context['session'].delete.assert_called_once_with(comment)
        self.context['session'].commit.assert_called_once_with()

        self._check_comment(comment, result, default_user)