def test_get_by_id(self): issue = Discussion.new( session = self.session, title = 'test', description = 'description', project_id = self.project.id, status = 'open' ) issue2 = Discussion.get_by_id(self.session, issue.id) self.assertEqual(issue, issue2)
def test_serialize_attached_elements(self): issue = Discussion.new( session = self.session, title = 'test', description = 'description', project_id = self.project.id, status = 'open' ) 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) rel1 = issue.attach_element( session = self.session, element = {'type': 'file', 'id': file.id} ) rel2 = issue.attach_element( session = self.session, element = {'type': 'job', 'id': job.id} ) elements = issue.serialize_attached_elements(self.session) element_ids = [x['id'] for x in elements] self.assertEqual(len(elements), 3) self.assertTrue('type' in elements[0]) self.assertTrue('discussion_id' in elements[0]) self.assertTrue('id' in elements[0]) self.assertTrue('created_time' in elements[0]) self.assertTrue(rel1.id in element_ids) self.assertTrue(rel2.id in element_ids)
def test_serialize(self): issue = Discussion.new( session = self.session, title = 'test', description = 'description', project_id = self.project.id, status = 'open' ) 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) rel1 = issue.attach_element( session = self.session, element = {'type': 'file', 'id': file.id} ) rel2 = issue.attach_element( session = self.session, element = {'type': 'job', 'id': job.id} ) issue_data = issue.serialize(self.session) self.assertEqual(len(issue_data['attached_elements']), 3) self.assertTrue('id' in issue_data) self.assertTrue('created_time' in issue_data) self.assertTrue('description' in issue_data) self.assertTrue('title' in issue_data) self.assertTrue('project_id' in issue_data) self.assertTrue('status' in issue_data)
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)
def update_discussion_comment_web(project_string_id, discussion_id): """ Update comment's content of the given comment_id in the POST payload. :param project_string_id: :param discussion_id: :return: """ # For now, no filters needed. But might add in the future. issue_new_spec_list = [ { "comment_id": { 'kind': int } }, { "content": { 'kind': str } }, ] log, input, untrusted_input = regular_input.master( request=request, spec_list=issue_new_spec_list) if len(log["error"].keys()) >= 1: return jsonify(log=log), 400 with sessionMaker.session_scope() as session: project = Project.get_by_string_id(session, project_string_id) user = User.get(session) discussion = Discussion.get_by_id(session, id=discussion_id) if discussion is None: log['error']['discussion'] = 'Discussion ID not found' return jsonify(log=log), 400 if user: member = user.member else: client_id = request.authorization.get('username', None) auth = Auth_api.get(session, client_id) member = auth.member comment_data, log = update_discussion_comments_core( session=session, log=log, comment_id=input['comment_id'], member=member, content=input['content']) if len(log["error"].keys()) >= 1: return jsonify(log=log), 400 return jsonify(comment=comment_data), 200
def test_new(self): issue = Discussion.new( session = self.session, title = 'test', description = 'description', project_id = self.project.id, status = 'open' ) self.assertEqual(issue.title, 'test') self.assertEqual(issue.description, 'description') self.assertEqual(issue.project_id, self.project.id) self.assertEqual(issue.status, 'open')
def test_list(self): issue = Discussion.new( session = self.session, title = 'test', description = 'description', project_id = self.project.id, status = 'open' ) issue2 = Discussion.new( session = self.session, title = 'test', description = 'description', project_id = self.project.id, status = 'open' ) issues = Discussion.list( session = self.session, project_id = self.project.id, ) self.assertEqual(type(issues), list) self.assertEqual(len(issues), 2)
def new_discussion_core(session, log=regular_log.default(), member=None, project=None, title=None, description=None, marker_frame_number=None, marker_type=None, type='issue', marker_data=None, attached_elements=[]): """ Returns the created discussion as a python dictionary. :param session: :param log: :param member: :param project: :param title: :param description: :param attached_elements: :return: created discussion python dict. """ if project is None: log['error']['project'] = 'Provide project for issue creation.' return None, log if title is None: log['error']['title'] = 'Provide title for issue creation.' return None, log if description is None: log['error']['description'] = 'Provide description for issue creation.' return None, log issue = Discussion.new(session=session, title=title, description=description, marker_frame_number=marker_frame_number, marker_type=marker_type, marker_data=marker_data, project_id=project.id, type=type, member_created_id=member.id if member else None) if attached_elements is not None: for element in attached_elements: issue.attach_element(session, element) issue_data = issue.serialize(session=session) return issue_data, log
def test_serialize_for_list(self): issue = Discussion.new( session = self.session, title = 'test', description = 'description', project_id = self.project.id, status = 'open' ) job = data_mocking.create_job({ 'name': 'my-test-job' }, self.session) issue_data = issue.serialize(self.session) self.assertTrue('id' in issue_data) self.assertTrue('created_time' in issue_data) self.assertTrue('description' in issue_data) self.assertTrue('title' in issue_data) self.assertTrue('project_id' in issue_data) self.assertTrue('status' in issue_data)
def list_discussion_comment_web(project_string_id, discussion_id): """ List all the comments of the given discussion_id :param project_string_id: :param discussion_id: :return: """ # For now, no filters needed. But might add in the future. issue_new_spec_list = [] log, input, untrusted_input = regular_input.master( request=request, spec_list=issue_new_spec_list) if len(log["error"].keys()) >= 1: return jsonify(log=log), 400 with sessionMaker.session_scope() as session: project = Project.get_by_string_id(session, project_string_id) user = User.get(session) discussion = Discussion.get_by_id(session, id=discussion_id) if discussion is None: log['error']['discussion'] = 'Discussion ID not found' return jsonify(log=log), 400 if user: member = user.member else: client_id = request.authorization.get('username', None) auth = Auth_api.get(session, client_id) member = auth.member comments_data, log = list_discussion_comments_core( session=session, log=log, project=project, discussion=discussion, ) if len(log["error"].keys()) >= 1: return jsonify(log=log), 400 return jsonify(comments=comments_data), 200
def discussion_detail_core(session, log = regular_log.default(), project = None, discussion_id = None): """ Return serialized dictionary with data of the given discussion. :param session: :param log: :param project: :param discussion_id: :return: dictionary of the given discussion data. """ discussion = Discussion.get_by_id(session, id = discussion_id) if discussion.project_id != project.id: log['error']['project_id'] = 'Wrong project ID provided.' if discussion is None: log['error']['discussion_id'] = 'discussion ID not found' return None, log issue_data = discussion.serialize(session = session) return issue_data, log
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)