def test_list_discussion_comments_core(self):
        # Create mock discussion
        discussion = data_mocking.create_discussion(
            {
                'title': 'test',
                'description': 'test',
                'project_id': self.project.id
            }, self.session)

        comment1 = data_mocking.create_discussion_comment(
            {
                'discussion_id': discussion.id,
                'project_id': self.project.id,
                'content': 'test'
            }, self.session)

        comment2 = data_mocking.create_discussion_comment(
            {
                'discussion_id': discussion.id,
                'project_id': self.project.id,
                'content': 'test'
            }, self.session)
        result, log = discussion_comment_list.list_discussion_comments_core(
            session=self.session,
            log=regular_log.default(),
            project=self.project,
            discussion=discussion,
        )
        self.assertIsNotNone(result)
        self.assertEqual(len(log['error'].keys()), 0)
        self.assertEqual(len(result), 2)
        ids = [x['id'] for x in result]
        self.assertTrue(comment1.id in ids)
        self.assertTrue(comment2.id in ids)
Пример #2
0
 def test_list(self):
     # Create mock issue
     discussion = data_mocking.create_discussion(
         {
             'project_id': self.project.id,
             'name': 'test',
             'title': 'test',
         },
         self.session,
     )
     comment1 = data_mocking.create_discussion_comment(
         {
             'discussion_id': discussion.id,
             'project_id': self.project.id,
             'user_id': self.project_data['users'][0].id,
             'content': 'test'
         }, self.session)
     comment2 = data_mocking.create_discussion_comment(
         {
             'discussion_id': discussion.id,
             'project_id': self.project.id,
             'user_id': self.project_data['users'][0].id,
             'content': 'test2'
         }, self.session)
     comments = DiscussionComment.list(session=self.session,
                                       project_id=self.project.id,
                                       discussion_id=discussion.id)
     self.assertIsNotNone(comments)
     self.assertEqual(len(comments), 2)
     ids = [comment.id for comment in comments]
     self.assertTrue(comment1.id in ids)
     self.assertTrue(comment2.id in ids)
    def test_update_discussion_comments_core(self):
        # Create mock discussion
        discussion = data_mocking.create_discussion(
            {
                'title': 'test',
                'description': 'test',
                'project_id': self.project.id
            }, self.session)

        member = self.project_data['users'][0].member

        comment1 = data_mocking.create_discussion_comment(
            {
                'discussion_id': discussion.id,
                'member_created_id': member.id,
                'project_id': self.project.id,
                'content': 'test'
            }, self.session)

        new_content = 'new content.'
        result, log = discussion_comment_update.update_discussion_comments_core(
            session=self.session,
            comment_id=comment1.id,
            content=new_content,
            member=member,
            log=regular_log.default(),
        )
        self.assertTrue(len(log['error'].keys()) == 0)
        self.assertIsNotNone(result)
        self.assertEqual(result['content'], new_content)
    def test_list_discussion_comment_web(self):
        # Create mock discussion
        discussion = data_mocking.create_discussion(
            {
                'title': 'test',
                'description': 'test',
                'project_id': self.project.id
            }, self.session)

        comment1 = data_mocking.create_discussion_comment(
            {
                'discussion_id': discussion.id,
                'project_id': self.project.id,
                'content': 'test'
            }, self.session)

        comment2 = data_mocking.create_discussion_comment(
            {
                'discussion_id': discussion.id,
                'project_id': self.project.id,
                'content': 'test'
            }, self.session)

        request_data = {}
        endpoint = "/api/v1/project/{}/discussion/{}/comments".format(
            self.project.project_string_id, discussion.id)
        auth_api = common_actions.create_project_auth(project=self.project,
                                                      session=self.session)
        credentials = b64encode(
            "{}:{}".format(auth_api.client_id,
                           auth_api.client_secret).encode()).decode('utf-8')
        response = self.client.post(endpoint,
                                    data=json.dumps(request_data),
                                    headers={
                                        'directory_id':
                                        str(self.project.directory_default_id),
                                        'Authorization':
                                        'Basic {}'.format(credentials)
                                    })
        data = response.json
        self.assertEqual(response.status_code, 200)
        self.assertTrue('comments' in data)
        self.assertEqual(len(data['comments']), 2)
        ids = [comment['id'] for comment in data['comments']]
        self.assertTrue(comment1.id in ids)
        self.assertTrue(comment2.id in ids)
Пример #5
0
    def test_get_by_id(self):
        # Create mock issue
        discussion = data_mocking.create_discussion(
            {
                'project_id': self.project.id,
                'name': 'test',
                'title': 'test',
            },
            self.session,
        )
        issue_comment = data_mocking.create_discussion_comment(
            {
                'discussion_id': discussion.id,
                'user_id': self.project_data['users'][0].id,
                'content': 'test'
            }, self.session)

        issue_comment2 = DiscussionComment.get_by_id(self.session,
                                                     issue_comment.id)
        self.assertEqual(issue_comment, issue_comment2)
Пример #6
0
 def test_serialize(self):
     discussion = data_mocking.create_discussion(
         {
             'project_id': self.project.id,
             'name': 'test',
             'title': 'test',
         },
         self.session,
     )
     discussion_comment = data_mocking.create_discussion_comment(
         {
             'discussion_id': discussion.id,
             'user_id': self.project_data['users'][0].id,
             'content': 'test'
         }, self.session)
     discussion_comment_data = discussion_comment.serialize()
     self.assertTrue('id' in discussion_comment_data)
     self.assertTrue('user' in discussion_comment_data)
     self.assertTrue('discussion_id' in discussion_comment_data)
     self.assertTrue('content' in discussion_comment_data)
    def test_update_discussion_comment_web(self):
        # Create mock discussion
        discussion = data_mocking.create_discussion(
            {
                'title': 'test',
                'description': 'test',
                'project_id': self.project.id
            }, self.session)
        auth_api = common_actions.create_project_auth(project=self.project,
                                                      session=self.session)
        member = auth_api.member
        comment1 = data_mocking.create_discussion_comment(
            {
                'discussion_id': discussion.id,
                'member_created_id': member.id,
                'project_id': self.project.id,
                'content': 'test'
            }, self.session)

        new_content = 'new content.'
        request_data = {'comment_id': comment1.id, 'content': new_content}
        endpoint = "/api/v1/project/{}/discussion/{}/update-comment".format(
            self.project.project_string_id, discussion.id)

        credentials = b64encode(
            "{}:{}".format(auth_api.client_id,
                           auth_api.client_secret).encode()).decode('utf-8')
        response = self.client.post(endpoint,
                                    data=json.dumps(request_data),
                                    headers={
                                        'directory_id':
                                        str(self.project.directory_default_id),
                                        'Authorization':
                                        'Basic {}'.format(credentials)
                                    })
        data = response.json
        self.assertEqual(response.status_code, 200)
        self.assertTrue('comment' in data)
        self.assertEqual(data['comment']['content'], new_content)
Пример #8
0
    def test_update(self):
        # Create mock issue
        discussion = data_mocking.create_discussion(
            {
                'project_id': self.project.id,
                'name': 'test',
                'title': 'test',
            },
            self.session,
        )
        comment1 = data_mocking.create_discussion_comment(
            {
                'discussion_id': discussion.id,
                'user_id': self.project_data['users'][0].id,
                'content': 'test'
            }, self.session)

        new_content = 'new_content'
        comment = DiscussionComment.update(session=self.session,
                                           comment_id=comment1.id,
                                           member=None,
                                           content=new_content)
        self.assertIsNotNone(comment)
        self.assertEqual(comment.content, new_content)