Created a new flow generator + tests for it.

This commit is contained in:
pablo 2020-12-31 18:28:48 +01:00
parent b8d4893026
commit 2b249063e0
2 changed files with 64 additions and 1 deletions

View file

@ -4,6 +4,7 @@ from bs4 import BeautifulSoup
from core.parsing_utils import (
ParsingFlow,
ParsingFlowGenerator,
ReferenciaFieldInstructions,
PrecioFieldInstructions,
TamanoCategoricoFieldInstructions,
@ -2725,3 +2726,30 @@ def test_parsing_flow_fails_for_unrelated_html(unrelated_html):
assert not parsing_flow.all_non_optional_fields_were_found and len(
parsing_flow.issues
) == len(all_instructions)
def test_parsing_flow_generator_returns_proper_flows():
four_instructions_with_params = {
ReferenciaFieldInstructions: {},
PrecioFieldInstructions: {},
TamanoCategoricoFieldInstructions: {},
SecondaryFeaturesFieldInstructions: {
"field_name": "personal",
"search_keyword": "Personal",
},
}
parsing_flow_generator = ParsingFlowGenerator(
parsing_flow_class=ParsingFlow,
instructions_to_attach_with_params=four_instructions_with_params,
)
a_new_parsing_flow = parsing_flow_generator.get_new_flow()
assert (
isinstance(a_new_parsing_flow, ParsingFlow),
len(a_new_parsing_flow._instructions) == len(four_instructions_with_params),
all([field.found is None for field in a_new_parsing_flow._instructions]),
all([field.valid is None for field in a_new_parsing_flow._instructions]),
)