def test_views_total_counters(tasks_count, annotations_count, predictions_count, business_client, project_id): # create payload = dict(project=project_id, data={"test": 1}) response = business_client.post( "/api/dm/views/", data=json.dumps(payload), content_type="application/json", ) assert response.status_code == 201, response.content view_id = response.json()["id"] project = Project.objects.get(pk=project_id) for _ in range(0, tasks_count): task_id = make_task({"data": {}}, project).id print('TASK_ID: %s' % task_id) for _ in range(0, annotations_count): print('COMPLETION') make_annotation({"result": []}, task_id) for _ in range(0, predictions_count): make_prediction({"result": []}, task_id) response = business_client.get(f"/api/dm/views/{view_id}/tasks/") response_data = response.json() assert response_data["total"] == tasks_count, response_data assert response_data[ "total_annotations"] == tasks_count * annotations_count, response_data assert response_data[ "total_predictions"] == tasks_count * predictions_count, response_data
def test_views_filters(filters, ids, business_client, project_id): payload = dict( project=project_id, data={"test": 1, "filters": filters}, ) response = business_client.post( "/api/dm/views/", data=json.dumps(payload), content_type="application/json", ) assert response.status_code == 201, response.content view_id = response.json()["id"] project = Project.objects.get(pk=project_id) task_data_field_name = settings.DATA_UNDEFINED_NAME task_id_1 = make_task({"data": {task_data_field_name: "some text1"}}, project).id make_annotation({"result": [{"1_first": True}]}, task_id_1) make_prediction({"result": [{"1_first": True}], "score": 1}, task_id_1) task_id_2 = make_task({"data": {task_data_field_name: "some text2"}}, project).id for _ in range(0, 2): make_annotation({"result": [{"2_second": True}], "was_cancelled": True}, task_id_2) for _ in range(0, 2): make_prediction({"result": [{"2_second": True}], "score": 2}, task_id_2) task_ids = [0, task_id_1, task_id_2] for _ in range(0, 2): task_id = make_task({"data": {task_data_field_name: "some text_"}}, project).id task_ids.append(task_id) for item in filters['items']: if item['type'] == 'Number': if isinstance(item['value'], dict): item['value']['min'] = task_ids[int(item['value']['min'])] item['value']['max'] = task_ids[int(item['value']['max'])] else: item['value'] = task_ids[int(item['value'])] updated_payload = dict( data={"filters": filters}, ) response = business_client.patch( f"/api/dm/views/{view_id}", data=json.dumps(payload), content_type="application/json", ) response = business_client.get(f"/api/dm/views/{view_id}/tasks/") response_data = response.json() assert 'tasks' in response_data, response_data response_ids = [task["id"] for task in response_data["tasks"]] correct_ids = [task_ids[i] for i in ids] assert response_ids == correct_ids
def test_views_ordering(ordering, element_index, undefined, business_client, project_id): payload = dict( project=project_id, data={ "test": 1, "ordering": ordering }, ) response = business_client.post( "/api/dm/views/", data=json.dumps(payload), content_type="application/json", ) assert response.status_code == 201, response.content view_id = response.json()["id"] project = Project.objects.get(pk=project_id) if undefined: task_field_name = settings.DATA_UNDEFINED_NAME else: task_field_name = 'text' task_id_1 = make_task({"data": {task_field_name: 1}}, project).id make_annotation({"result": [{"1": True}]}, task_id_1) make_prediction({"result": [{"1": True}], "score": 1}, task_id_1) task_id_2 = make_task({"data": {task_field_name: 2}}, project).id for _ in range(0, 2): make_annotation({ "result": [{ "2": True }], "was_cancelled": True }, task_id_2) for _ in range(0, 2): make_prediction({"result": [{"2": True}], "score": 2}, task_id_2) task_ids = [task_id_1, task_id_2] response = business_client.get(f"/api/dm/views/{view_id}/tasks/") response_data = response.json() assert response_data["tasks"][0]["id"] == task_ids[element_index]
def make_test_project(): project = make_project(project_config, user, False, org=user.active_organization) task1 = make_task({'data': { 'location': 'London', 'text': 'text A' }}, project) task2 = make_task({'data': { 'location': 'London', 'text': 'text A' }}, project) make_annotation( { 'result': [{ 'result': [{ 'r': 1 }], 'ground_truth': True }], 'completed_by': user }, task1.id) make_annotation( { 'result': [{ 'result': [{ 'r': 1 }], 'ground_truth': True }], 'completed_by': user }, task1.id) make_annotation( { 'result': [{ 'result': [{ 'r': 1 }], 'ground_truth': True }], 'completed_by': user }, task2.id)
def test_views_tasks_api(business_client, project_id): # create payload = dict(project=project_id, data={"test": 1}) response = business_client.post( "/api/dm/views/", data=json.dumps(payload), content_type="application/json", ) assert response.status_code == 201, response.content view_id = response.json()["id"] # no tasks response = business_client.get(f"/api/dm/views/{view_id}/tasks/") assert response.status_code == 200, response.content assert response.json()["total"] == 0 assert len(response.json()["tasks"]) == 0 project = Project.objects.get(pk=project_id) task_data = {"text": "bbb"} task_id = make_task({"data": task_data}, project).id annotation_result = { "from_name": "my_class", "to_name": "text", "type": "choices", "value": { "choices": ["pos"] } } make_annotation({"result": [annotation_result]}, task_id) make_annotation( { "result": [annotation_result], "was_cancelled": True, }, task_id, ) prediction_result = { "from_name": "my_class", "to_name": "text", "type": "choices", "value": { "choices": ["pos"] } } make_prediction( { "result": [prediction_result], }, task_id, ) response = business_client.get(f"/api/dm/views/{view_id}/tasks/") assert response.status_code == 200, response.content response_data = response.json() assert response_data["total"] == 1 assert len(response_data["tasks"]) == 1 assert response_data["tasks"][0]["id"] == task_id assert response_data["tasks"][0]["data"] == task_data assert response_data["tasks"][0]["total_annotations"] == 1 assert json.loads(response_data["tasks"][0]["annotations_results"]) == [[ annotation_result ], [annotation_result]] assert response_data["tasks"][0]["cancelled_annotations"] == 1 assert response_data["tasks"][0]["total_predictions"] == 1 assert json.loads(response_data["tasks"][0]["predictions_results"]) == [[ prediction_result ]]