Esempio n. 1
0
    def test_task_next_issue(self):
        # Create mock tasks
        num_tasks = 5
        job = data_mocking.create_job(
            {
                'name': 'my-test-job-{}'.format(1),
                'project': self.project
            }, self.session)
        all_tasks = []
        for i in range(0, num_tasks):
            task = data_mocking.create_task(
                {
                    'name': 'task{}'.format(i),
                    'job': job
                }, self.session)
            all_tasks.append(task)

        issue1 = data_mocking.create_discussion(
            {
                'title': 'test',
                'description': 'test',
                'project_id': self.project.id
            }, self.session)
        issue1.attach_element(session=self.session,
                              element={
                                  'type': 'task',
                                  'id': all_tasks[2].id
                              })
        issue2 = data_mocking.create_discussion(
            {
                'title': 'test2',
                'description': 'test2',
                'project_id': self.project.id
            }, self.session)
        issue2.attach_element(session=self.session,
                              element={
                                  'type': 'task',
                                  'id': all_tasks[4].id
                              })

        with self.client.session_transaction() as session:
            endpoint = "/api/v1/task/{}/next-task-with-issues".format(
                all_tasks[0].id)
            credentials = b64encode("{}:{}".format(
                self.auth_api.client_id,
                self.auth_api.client_secret).encode()).decode('utf-8')
            session['Authorization'] = credentials
            common_actions.add_auth_to_session(session, self.project.users[0])
        response = self.client.post(endpoint,
                                    data=json.dumps({}),
                                    headers={
                                        'directory_id':
                                        str(self.project.directory_default_id),
                                        'Authorization':
                                        'Basic {}'.format(credentials)
                                    })
        data = response.json
        self.assertEqual(response.status_code, 200)
        self.assertEqual(data['task_id'], all_tasks[2].id)
Esempio n. 2
0
    def test_attach_element(self):
        # Create mock issue
        issue = data_mocking.create_discussion(
            {
                'project_id': self.project.id,
                'name': 'test',
                'title': 'test',
            },
            self.session,
        )
        job = data_mocking.create_job({
            'name': 'my-test-job'
        }, self.session)

        file = data_mocking.create_file({'project_id': job.project.id, 'job_id': job.id}, self.session)
        issue_relation_file = issue.attach_element(
            session = self.session,
            element = {'type': 'file', 'id': file.id}
        )
        issue_relation_job = issue.attach_element(
            session = self.session,
            element = {'type': 'job', 'id': job.id}
        )
        self.session.commit()
        query_rel_file = self.session.query(DiscussionRelation).first()
        query_rel_job = self.session.query(DiscussionRelation).first()
        self.assertIsNotNone(issue_relation_file)
        self.assertIsNotNone(issue_relation_job)
        self.assertIsNotNone(query_rel_file)
        self.assertIsNotNone(query_rel_job)
    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)
    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)
Esempio n. 5
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)
Esempio n. 6
0
    def test_detach_all_instances(self):
        # Create mock discussion
        discussion = data_mocking.create_discussion({
            'title': 'test',
            'description': 'test',
            'member_created_id': self.member.id,
            'project_id': self.project.id
        }, self.session)
        member = self.member

        instance = data_mocking.create_instance({
            'project_id': self.project.id,
            'type': 'box',
            'x_min': 0,
            'x_max': 0,
            'y_min': 0,
            'y_max': 0,
        }, self.session)
        discussion.attach_element(session = self.session, element = {
            'type': 'instance',
            'id': instance.id
        })
        self.session.commit()
        discussion_updated = Discussion.update(
            session = self.session,
            discussion_id = discussion.id,
            attached_elements = []
        )
        attached = discussion_updated.serialize_attached_elements(self.session)
        self.assertEqual(len(attached), 1)
Esempio n. 7
0
    def test_test_task_next_issue_core(self):
        # Create mock tasks
        # Create mock tasks
        num_tasks = 5
        job = data_mocking.create_job(
            {
                'name': 'my-test-job-{}'.format(1),
                'project': self.project
            }, self.session)
        all_tasks = []
        for i in range(0, num_tasks):
            task = data_mocking.create_task(
                {
                    'name': 'task{}'.format(i),
                    'job': job
                }, self.session)
            all_tasks.append(task)

        issue1 = data_mocking.create_discussion(
            {
                'title': 'test',
                'description': 'test',
                'project_id': self.project.id
            }, self.session)
        issue1.attach_element(session=self.session,
                              element={
                                  'type': 'task',
                                  'id': all_tasks[2].id
                              })
        issue2 = data_mocking.create_discussion(
            {
                'title': 'test2',
                'description': 'test2',
                'project_id': self.project.id
            }, self.session)
        issue2.attach_element(session=self.session,
                              element={
                                  'type': 'task',
                                  'id': all_tasks[4].id
                              })

        result = task_next_issue.task_next_issue_core(session=self.session,
                                                      task_id=all_tasks[0].id)
Esempio n. 8
0
 def test_new(self):
     # Create mock issue
     discussion = data_mocking.create_discussion(
         {
             'project_id': self.project.id,
             'name': 'test',
             'title': 'test',
         },
         self.session,
     )
     content = 'thecontent'
     issue_comment = DiscussionComment.new(session=self.session,
                                           content=content,
                                           discussion_id=discussion.id)
     self.assertIsNotNone(issue_comment)
     self.assertEqual(issue_comment.content, content)
     self.assertEqual(issue_comment.discussion_id, discussion.id)
    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)
Esempio n. 10
0
 def test_serialize(self):
     discussion = data_mocking.create_discussion(
         {
             'project_id': self.project.id,
             'name': 'test',
             'title': 'test',
         },
         self.session,
     )
     issue_relation = data_mocking.create_discussion_relation({
         'discussion_id': discussion.id,
         'user_id': self.project_data['users'][0].id,
         'content': 'test'
     }, self.session)
     issue_relation_data = issue_relation.serialize(self.session)
     self.assertTrue('discussion_id' in issue_relation_data)
     self.assertTrue('created_time' in issue_relation_data)
     self.assertTrue('id' in issue_relation_data)
Esempio n. 11
0
    def test_new(self):
        # Create mock issue
        discussion = data_mocking.create_discussion(
            {
                'project_id': self.project.id,
                'name': 'test',
                'title': 'test',
            },
            self.session,
        )
        issue_relation = DiscussionRelation.new(
            session = self.session,
            discussion_id = discussion.id,
        )

        self.assertIsNotNone(issue_relation)
        query = self.session.query(DiscussionRelation).filter(DiscussionRelation.id == issue_relation.id).first()
        self.assertIsNotNone(query)
Esempio n. 12
0
    def test_issue_detail_core(self):
        discussion = data_mocking.create_discussion(
            {
                'project_id': self.project.id,
                'name': 'test',
                'title': 'test',
            },
            self.session,
        )
        issue_data, log = discussion_detail.discussion_detail_core(
            session=self.session,
            log=regular_log.default(),
            project=self.project,
            discussion_id=discussion.id)

        self.assertIsNotNone(issue_data)
        self.assertTrue(len(log['error'].keys()) == 0)
        self.assertEqual(discussion.id, issue_data['id'])
Esempio n. 13
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)
Esempio n. 14
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_new_discussion_comment_web(self):
        # Create mock tasks
        # Create mock job.
        job = data_mocking.create_job({
            'name': 'my-test-job',
            'project': self.project
        }, self.session)

        discussion = data_mocking.create_discussion({
            'title': 'test',
            'description': 'test',
            'project_id': self.project.id
        }, self.session)
        comment_content = 'the comment'
        request_data = {
            'content': comment_content
        }

        endpoint = "/api/v1/project/{}/discussion/{}/add-comment".format(self.project.project_string_id, discussion.id)
        auth_api = common_actions.create_project_auth(project = job.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(job.project.directory_default_id),
                'Authorization': 'Basic {}'.format(credentials)
            }
        )
        data = response.json
        self.assertEqual(response.status_code, 200)
        self.assertTrue('comment' in data)
        self.assertTrue('content' in data['comment'])
        self.assertTrue('user' in data['comment'])
        self.assertTrue(data['comment']['content'] == comment_content)
        self.assertTrue('member_created_id' in data['comment'])
        self.assertTrue('member_updated_id' in data['comment'])
        self.assertTrue('time_created' in data['comment'])
        self.assertTrue('time_updated' in data['comment'])
        self.assertTrue('id' in data['comment'])
    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)
    def test_new_discussion_comment_core(self):
        discussion = data_mocking.create_discussion({
            'title': 'test',
            'description': 'test',
            'project_id': self.project.id
        }, self.session)

        member = self.session.query(Member).filter(
            Member.id == self.project_data['users'][0].member_id
        ).first()
        comment_content = 'the comment.'
        result, log = discussion_comment_new.new_discussion_comment_core(
            session = self.session,
            log = regular_log.default(),
            user = None,
            member = member,
            project = self.project,
            discussion = discussion,
            content = comment_content
        )

        self.assertIsNotNone(result)
        self.assertEqual(len(log['error'].keys()), 0)
Esempio n. 18
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)
Esempio n. 19
0
 def test_update_attached_instances(self):
     # Create mock discussion
     discussion = data_mocking.create_discussion({
         'title': 'test',
         'description': 'test',
         'member_created_id': self.member.id,
         'project_id': self.project.id
     }, self.session)
     member = self.member
     instance = data_mocking.create_instance({
         'project_id': self.project.id,
         'type': 'box',
         'x_min': 0,
         'x_max': 0,
         'y_min': 0,
         'y_max': 0,
     }, self.session)
     discussion.update_attached_instances(
         session = self.session,
         attached_elements = [{'type': 'instance', 'instance_id': instance.id}]
     )
     self.session.commit()
     disc = Discussion.get_by_id(session = self.session, id=discussion.id)
     self.assertEqual(len(disc.serialize_attached_elements(self.session)), 2)
Esempio n. 20
0
    def test_issue_list_web(self):
        # Create mock tasks
        # Create mock job.
        discussion = data_mocking.create_discussion(
            {
                'project_id': self.project.id,
                'name': 'test',
                'title': 'test',
            },
            self.session,
        )
        issue2 = data_mocking.create_discussion(
            {
                'project_id': self.project.id,
                'name': 'test',
                'title': 'test',
            },
            self.session,
        )
        issue3 = data_mocking.create_discussion(
            {
                'project_id': self.project.id,
                'name': 'test',
                'title': 'test',
            },
            self.session,
        )
        job = data_mocking.create_job({
            'name': 'my-test-job',
            'project': self.project
        }, self.session)

        discussion.attach_element(
            session = self.session,
            element = {'type': 'job', 'id': job.id}
        )
        issue2.attach_element(
            session = self.session,
            element = {'type': 'job', 'id': job.id}
        )
        file = data_mocking.create_file({'project_id': job.project.id, 'job_id': job.id}, self.session)

        discussion.attach_element(
            session = self.session,
            element = {'type': 'file', 'id': file.id}
        )

        task = data_mocking.create_task({
            'name': 'task{}'.format(1),
            'job': job,
            'file': file,
        }, self.session)

        discussion.attach_element(
            session = self.session,
            element = {'type': 'task', 'id': task.id}
        )
        regular_methods.commit_with_rollback(self.session)

        rels = self.session.query(DiscussionRelation).all()
        request_data = {
            'project_id': self.project.id,
            'task_id': task.id,
        }

        endpoint = "/api/v1/project/" + self.project.project_string_id + "/discussions/list"
        auth_api = common_actions.create_project_auth(project=job.project, session=self.session)
        credentials = b64encode("{}:{}".format(auth_api.client_id, auth_api.client_secret).encode()).decode('utf-8')
        response_with_task_id = self.client.post(
            endpoint,
            data=json.dumps(request_data),
            headers={
                'directory_id': str(job.project.directory_default_id),
                'Authorization': 'Basic {}'.format(credentials)
            }
        )
        data = response_with_task_id.json
        self.assertEqual(response_with_task_id.status_code, 200)
        self.assertEqual(len(data['issues']), 1)
        request_data = {
            'project_id': self.project.id,
            'job_id': job.id,
        }
        response_with_job_id = self.client.post(
            endpoint,
            data=json.dumps(request_data),
            headers={
                'directory_id': str(job.project.directory_default_id),
                'Authorization': 'Basic {}'.format(credentials)
            }
        )

        data = response_with_job_id.json
        self.assertEqual(response_with_task_id.status_code, 200)
        self.assertEqual(len(data['issues']), 2)

        request_data = {
            'project_id': self.project.id,
        }
        response_project = self.client.post(
            endpoint,
            data=json.dumps(request_data),
            headers={
                'directory_id': str(job.project.directory_default_id),
                'Authorization': 'Basic {}'.format(credentials)
            }
        )

        data = response_project.json
        self.assertEqual(response_with_task_id.status_code, 200)
        self.assertEqual(len(data['issues']), 3)