🎨 Normalize field stripping #12
`strip_std_field()` will be used to strip fields from the `get_map_props()` in the next iterations. This modification aim to format data passed to `strip_std_field()` then we can use it easyly later for other options.
This commit is contained in:
parent
cc16378233
commit
6ed57de1aa
4
ldpy.py
4
ldpy.py
|
@ -124,7 +124,7 @@ def get_last_entries(entries_nb):
|
|||
last_entries = client.opnsrch_clt.search(body=query)
|
||||
logger.debug(pf(last_entries))
|
||||
|
||||
return last_entries
|
||||
return last_entries["hits"]["hits"]
|
||||
|
||||
|
||||
def get_map_props():
|
||||
|
@ -154,7 +154,7 @@ def strip_std_field(initial_entries):
|
|||
Returns a list populated with a dict for each entry.
|
||||
"""
|
||||
stripped_entries = []
|
||||
for initial_hit in initial_entries["hits"]["hits"]:
|
||||
for initial_hit in initial_entries:
|
||||
|
||||
for key in STD_FIELDS:
|
||||
del initial_hit["_source"][key]
|
||||
|
|
|
@ -90,31 +90,26 @@ def test_parse_args_last_const():
|
|||
@mark.parametrize("fields", [META_FIELDS, STD_FIELDS])
|
||||
def test_strip_std_field(fields):
|
||||
"""Remove keys/values present in all LDP stream."""
|
||||
payload = {
|
||||
"_shards": {},
|
||||
"hits": {
|
||||
"hits": [
|
||||
{
|
||||
"_id": "-",
|
||||
"_source": {
|
||||
"category": "-",
|
||||
"gl2_source_input": "",
|
||||
"gl2_source_node": "-",
|
||||
"id": "-",
|
||||
"message": "-",
|
||||
"rating_num": 42,
|
||||
"source": "-",
|
||||
"streams": [""],
|
||||
"timestamp": "2022-10-04 20:59:22.364402",
|
||||
"title": "-",
|
||||
"X-OVH-CONTENT-SIZE": 42,
|
||||
"X-OVH-DELIVERY-DATE": "2022-10-04T20:59:22.578894878Z",
|
||||
"X-OVH-INPUT": "",
|
||||
},
|
||||
},
|
||||
],
|
||||
payload = [
|
||||
{
|
||||
"_id": "-",
|
||||
"_source": {
|
||||
"category": "-",
|
||||
"gl2_source_input": "",
|
||||
"gl2_source_node": "-",
|
||||
"id": "-",
|
||||
"message": "-",
|
||||
"rating_num": 42,
|
||||
"source": "-",
|
||||
"streams": [""],
|
||||
"timestamp": "2022-10-04 20:59:22.364402",
|
||||
"title": "-",
|
||||
"X-OVH-CONTENT-SIZE": 42,
|
||||
"X-OVH-DELIVERY-DATE": "2022-10-04T20:59:22.578894878Z",
|
||||
"X-OVH-INPUT": "",
|
||||
},
|
||||
},
|
||||
}
|
||||
]
|
||||
stripped_entry = ldpy.strip_std_field(payload)[0]
|
||||
|
||||
assert isinstance(stripped_entry, dict)
|
||||
|
@ -138,7 +133,7 @@ def test_get_last_entries_out_of_range(entry_np):
|
|||
def test_get_last_entries_in_range(entry_np):
|
||||
"""Value is in range for the last entries."""
|
||||
response = ldpy.get_last_entries(entry_np)
|
||||
assert len(response["hits"]["hits"]) == entry_np
|
||||
assert len(response) == entry_np
|
||||
|
||||
|
||||
# ###
|
||||
|
|
Loading…
Reference in New Issue