Skip to content
Snippets Groups Projects
Commit 5a58168e authored by Dmitrii Valuiskii (EPAM)'s avatar Dmitrii Valuiskii (EPAM) Committed by Siarhei Khaletski (EPAM)
Browse files

GONRG-1700: fix id composing

parent 58d9e72c
No related branches found
No related tags found
1 merge request!24Ingestion updates
......@@ -155,7 +155,7 @@ class ExtendedSearchId(SearchId):
def _extract_id_from_response(self, response: dict):
results = response.get("results")
record_ids = ["".join([elem.get("id"), str(elem.get("version"))]) for elem in results]
record_ids = [":".join([elem.get("id"), str(elem.get("version", ""))]) for elem in results]
record_ids.extend([elem.get("id") for elem in results])
logger.debug(f"response ids: {record_ids}")
return record_ids
......
[
"some_test_id",
"some_test_id:12345"
]
{
"results": [
{
"id": "some_test_id",
"version": 12345
}
],
"aggregations": null,
"totalCount": 45
......
......@@ -43,6 +43,7 @@ TRAVERSAL_MANIFEST_EMPTY_PATH = f"{DATA_PATH_PREFIX}/invalid/TraversalEmptyManif
SEARCH_VALID_RESPONSE_PATH = f"{DATA_PATH_PREFIX}/other/SearchResponseValid.json"
SEARCH_INVALID_RESPONSE_PATH = f"{DATA_PATH_PREFIX}/other/SearchResponseInvalid.json"
SEARCH_EXTRACTED_IDS_PATH = f"{DATA_PATH_PREFIX}/other/ExtractedIds.json"
SURROGATE_MANIFEST_WELLBORE = f"{DATA_PATH_PREFIX}/surrogate/Wellbore.0.3.0.json"
......
......@@ -12,8 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import os
import sys
import http
......@@ -26,13 +25,13 @@ sys.path.append(f"{os.getenv('AIRFLOW_SRC_DIR')}/dags")
from mock_providers import get_test_credentials
from file_paths import (
SEARCH_INVALID_RESPONSE_PATH,
SEARCH_VALID_RESPONSE_PATH
)
SEARCH_VALID_RESPONSE_PATH,
SEARCH_EXTRACTED_IDS_PATH)
from libs.exceptions import RecordsNotSearchableError
from libs.context import Context
from libs.refresh_token import AirflowTokenRefresher
from tenacity import stop_after_attempt
from libs.search_record_ids import SearchId
from libs.search_record_ids import SearchId, ExtendedSearchId
from mock_responses import MockSearchResponse
......@@ -133,3 +132,27 @@ class TestManifestProcessor:
with pytest.raises(ValueError):
SearchId("http://test", record_ids, AirflowTokenRefresher(get_test_credentials()),
Context(app_key="", data_partition_id=""))
@pytest.mark.parametrize(
"record_ids,search_response_path,extracted_ids_path",
[
pytest.param(
["test"],
SEARCH_VALID_RESPONSE_PATH,
SEARCH_EXTRACTED_IDS_PATH
)
]
)
def test_search_found_all_records(self, monkeypatch, record_ids: list,
search_response_path: str,
extracted_ids_path: str):
self.mock_storage_response(monkeypatch, search_response_path, total_count=len(record_ids))
with open(search_response_path) as f:
response = json.load(f)
id_searcher = ExtendedSearchId("http://test", record_ids,
AirflowTokenRefresher(get_test_credentials()),
Context(app_key="", data_partition_id=""))
record_ids = id_searcher._extract_id_from_response(response)
with open(extracted_ids_path) as f:
extracted_ids = json.load(f)
assert set(record_ids) == set(extracted_ids)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment