|
1 | 1 | from http import HTTPStatus |
2 | 2 |
|
3 | 3 | import pytest |
| 4 | +from fastapi import HTTPException |
4 | 5 |
|
5 | 6 | from collector_db.DTOs.InsertURLsInfo import InsertURLsInfo |
6 | 7 | from collector_db.DTOs.URLMapping import URLMapping |
|
11 | 12 | from core.DTOs.GetNextURLForAgencyAnnotationResponse import URLAgencyAnnotationPostInfo |
12 | 13 | from core.DTOs.RecordTypeAnnotationPostInfo import RecordTypeAnnotationPostInfo |
13 | 14 | from core.DTOs.RelevanceAnnotationPostInfo import RelevanceAnnotationPostInfo |
| 15 | +from core.classes.ErrorManager import ErrorTypes |
14 | 16 | from core.enums import RecordType, SuggestionType |
15 | 17 | from core.exceptions import FailedValidationException |
16 | 18 | from tests.helpers.complex_test_data_functions import AnnotateAgencySetupInfo, setup_for_annotate_agency, \ |
@@ -130,6 +132,36 @@ async def test_annotate_relevancy(api_test_helper): |
130 | 132 | assert results[0].relevant is True |
131 | 133 |
|
132 | 134 |
|
| 135 | +@pytest.mark.asyncio |
| 136 | +async def test_annotate_relevancy_already_annotated_by_different_user( |
| 137 | + api_test_helper |
| 138 | +): |
| 139 | + ath = api_test_helper |
| 140 | + |
| 141 | + creation_info: BatchURLCreationInfo = await ath.db_data_creator.batch_and_urls( |
| 142 | + url_count=1 |
| 143 | + ) |
| 144 | + |
| 145 | + await ath.db_data_creator.user_relevant_suggestion( |
| 146 | + url_id=creation_info.url_ids[0], |
| 147 | + user_id=2, |
| 148 | + relevant=True |
| 149 | + ) |
| 150 | + |
| 151 | + # Annotate with different user (default is 1) and get conflict error |
| 152 | + try: |
| 153 | + response = await ath.request_validator.post_relevance_annotation_and_get_next( |
| 154 | + url_id=creation_info.url_ids[0], |
| 155 | + relevance_annotation_post_info=RelevanceAnnotationPostInfo( |
| 156 | + is_relevant=False |
| 157 | + ) |
| 158 | + ) |
| 159 | + except HTTPException as e: |
| 160 | + assert e.status_code == HTTPStatus.CONFLICT |
| 161 | + assert e.detail["detail"]["code"] == ErrorTypes.ANNOTATION_EXISTS.value |
| 162 | + assert e.detail["detail"]["message"] == f"Annotation of type RELEVANCE already exists for url {creation_info.url_ids[0]}" |
| 163 | + |
| 164 | + |
133 | 165 | @pytest.mark.asyncio |
134 | 166 | async def test_annotate_relevancy_no_html(api_test_helper): |
135 | 167 | ath = api_test_helper |
@@ -250,6 +282,36 @@ async def test_annotate_record_type(api_test_helper): |
250 | 282 | if result.url_id == inner_info_1.url_info.url_id: |
251 | 283 | assert result.record_type == RecordType.BOOKING_REPORTS.value |
252 | 284 |
|
| 285 | +@pytest.mark.asyncio |
| 286 | +async def test_annotate_record_type_already_annotated_by_different_user( |
| 287 | + api_test_helper |
| 288 | +): |
| 289 | + ath = api_test_helper |
| 290 | + |
| 291 | + creation_info: BatchURLCreationInfo = await ath.db_data_creator.batch_and_urls( |
| 292 | + url_count=1 |
| 293 | + ) |
| 294 | + |
| 295 | + await ath.db_data_creator.user_record_type_suggestion( |
| 296 | + url_id=creation_info.url_ids[0], |
| 297 | + user_id=2, |
| 298 | + record_type=RecordType.ACCIDENT_REPORTS |
| 299 | + ) |
| 300 | + |
| 301 | + # Annotate with different user (default is 1) and get conflict error |
| 302 | + try: |
| 303 | + response = await ath.request_validator.post_record_type_annotation_and_get_next( |
| 304 | + url_id=creation_info.url_ids[0], |
| 305 | + record_type_annotation_post_info=RecordTypeAnnotationPostInfo( |
| 306 | + record_type=RecordType.ANNUAL_AND_MONTHLY_REPORTS |
| 307 | + ) |
| 308 | + ) |
| 309 | + except HTTPException as e: |
| 310 | + assert e.status_code == HTTPStatus.CONFLICT |
| 311 | + assert e.detail["detail"]["code"] == ErrorTypes.ANNOTATION_EXISTS.value |
| 312 | + assert e.detail["detail"]["message"] == f"Annotation of type RECORD_TYPE already exists for url {creation_info.url_ids[0]}" |
| 313 | + |
| 314 | + |
253 | 315 | @pytest.mark.asyncio |
254 | 316 | async def test_annotate_record_type_no_html_info(api_test_helper): |
255 | 317 | ath = api_test_helper |
|
0 commit comments