Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref fixes #337

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,32 @@
for sparql_assertion in sparql_assertions:
sparql_assertion_state = \
await sparql_assertion.get_state() \
if (sparql_assertion and isinstance(sparql_assertion, SPARQLTestFileResource)) else None
if isinstance(sparql_assertion, SPARQLTestFileResource) else None
if isinstance(sparql_assertion_state, SPARQLTestState):
sparql_assertions_states.append(sparql_assertion_state)

mapping_groups_states = []
if self.mapping_groups:
mapping_groups = [await mapping_group.fetch() for mapping_group in self.mapping_groups]
if mapping_groups:
mapping_groups_states = [await mapping_group.get_state() for mapping_group in mapping_groups]
mapping_groups_states = [

Check warning on line 210 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L210

Added line #L210 was not covered by tests
await mapping_group.get_state() for mapping_group in mapping_groups
if isinstance(mapping_group, MappingGroup)

Check warning on line 212 in mapping_workbench/backend/conceptual_mapping_rule/models/entity.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/conceptual_mapping_rule/models/entity.py#L212

Added line #L212 was not covered by tests
]

return ConceptualMappingRuleState(
oid=self.id,
min_sdk_version=self.min_sdk_version,
max_sdk_version=self.max_sdk_version,
source_structural_element=(
await source_structural_element.get_state()
) if (source_structural_element and isinstance(source_structural_element, StructuralElement)) else None,
) if isinstance(source_structural_element, StructuralElement) else None,
xpath_condition=self.xpath_condition,
target_class_path=self.target_class_path,
target_property_path=self.target_property_path,
triple_map_fragment=(
await triple_map_fragment.get_state()
) if (triple_map_fragment and isinstance(triple_map_fragment, GenericTripleMapFragment)) else None,
) if isinstance(triple_map_fragment, GenericTripleMapFragment) else None,
sparql_assertions=sparql_assertions_states,
status=self.status,
mapping_notes=self.mapping_notes,
Expand Down
5 changes: 4 additions & 1 deletion mapping_workbench/backend/mapping_package/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ async def get_mapping_groups_states(self) -> List[MappingGroupState]:
mapping_groups = await MappingGroup.find(
Eq(MappingGroup.project, self.project.to_ref())
).to_list()
mapping_groups_states = [await mapping_group.get_state() for mapping_group in mapping_groups]
mapping_groups_states = [
await mapping_group.get_state() for mapping_group in mapping_groups
if isinstance(mapping_group, MappingGroup)
]
return mapping_groups_states

async def get_test_data_suites_states(self) -> List[TestDataSuiteState]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def import_mapping_package_from_archive(
tempdir = tempfile.TemporaryDirectory()
tempdir_name = tempdir.name
tempdir_path = pathlib.Path(tempdir_name)
zf.extractall(tempdir_name)
zf.extractall(tempdir_name) # NOSONAR
dir_contents = list(tempdir_path.iterdir())
try:
assert len(dir_contents) == 1, "Archive must contain only the package folder!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ async def process_mapping_package(
task_progress.finish_current_action_step()
mwb_logger.log_all_info("Initializing Package State ... DONE")

# TODO: Store all package data in the Package State and make all the processing only on Package State Data

if tasks_to_run is None or TaskToRun.TRANSFORM_TEST_DATA.value in tasks_to_run:
mwb_logger.log_all_info(f"Transforming '{mapping_package.identifier}' Test Data ...")
task_progress.start_action_step(name=TaskToRun.TRANSFORM_TEST_DATA.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@
sparql_query_xpath = sparql_query_result.query.cm_rule.sdk_element_xpath.strip() \
if sparql_query_result.query.cm_rule else None
sparql_xpath_condition = sparql_query_result.query.cm_rule.xpath_condition.xpath_condition.strip() \
if sparql_query_result.query.cm_rule else None
if (sparql_query_result.query.cm_rule and
sparql_query_result.query.cm_rule.xpath_condition and
sparql_query_result.query.cm_rule.xpath_condition.xpath_condition) \
else None

Check warning on line 82 in mapping_workbench/backend/package_validator/adapters/sparql_validator.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/package_validator/adapters/sparql_validator.py#L80-L82

Added lines #L80 - L82 were not covered by tests
validation_xpaths = set()
validation_xpath_conditions = set()
for xpath_assertion in xpath_validation_results:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
return None
path_parts = [xpath]
parent = node.get_parent()
while parent and isinstance(parent, PyXdmNode) and parent.name:
while isinstance(parent, PyXdmNode) and parent.name:

Check warning on line 70 in mapping_workbench/backend/package_validator/adapters/xpath_validator.py

View check run for this annotation

Codecov / codecov/patch

mapping_workbench/backend/package_validator/adapters/xpath_validator.py#L70

Added line #L70 was not covered by tests
xpath = self.get_ns_tag(parent)
if xpath is not None:
path_parts.insert(0, xpath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

DEFAULT_RQ_NAME = 'cm_assertion_'

SPARQL_PREFIX_PATTERN = re.compile('(?:\\s+|^)([\\w\\-]+)?:')
SPARQL_PREFIX_PATTERN = re.compile('(?:\\s+|^)([\\w\\-]+)?:') # NOSONAR
SPARQL_PREFIX_LINE = 'PREFIX {prefix}: <{value}>'

SPARQL_XPATH_SEPARATOR = " ;; "
Expand Down
2 changes: 1 addition & 1 deletion mapping_workbench/backend/task_manager/adapters/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def generate_task_id_from_task_name(cls, task_name, created_at):
# Remove leading and trailing hyphens
task_id = task_id.strip('-')

return f"{task_id}_{created_at}_{random.randint(100, 999)}"
return f"{task_id}_{created_at}_{random.randint(100, 999)}" # NOSONAR

def set_future(self, future: ProcessFuture):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const ListTableRow = (props) => {
pathname: paths.app[sectionApi.section].resource_manager.edit,
query: {id: item_id, fid: resource_id}
});
return true;
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const ListTableRow = (props) => {
pathname: paths.app[sectionApi.section].resource_manager.edit,
query: {id: item_id, fid: resource_id}
});
return true;
}

const handleDeleteAction = () => {
Expand Down
17 changes: 10 additions & 7 deletions tests/e2e/backend/package_processor/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import pytest
from beanie import PydanticObjectId

from mapping_workbench.backend.mapping_package.models.entity import MappingPackage
from mapping_workbench.backend.fields_registry.models.field_registry import StructuralElement
from mapping_workbench.backend.project.models.entity import Project


@pytest.fixture
def dummy_mapping_package(dummy_project) -> MappingPackage:
return MappingPackage(
title="dummy_mapping_package_title",
description="dummy_mapping_package_description",
base_xpath="/TED_EXPORT/FORM_SECTION/F03_2014",
project=Project.link_from_id(dummy_project.id)
def dummy_structural_element(dummy_project):
return StructuralElement(
sdk_element_id="ND-Root",
absolute_xpath="/*",
relative_xpath="/*",
project=Project.link_from_id(dummy_project.id),
repeatable=False,
id=str(PydanticObjectId())
)
32 changes: 28 additions & 4 deletions tests/e2e/backend/package_processor/test_package_processor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
from pathlib import Path

import pytest
from mongomock_motor import enabled_gridfs_integration

from mapping_workbench.backend.mapping_package.models.entity import MappingPackageState, MappingPackage
from mapping_workbench.backend.fields_registry.models.field_registry import StructuralElement
from mapping_workbench.backend.mapping_package import PackageType
from mapping_workbench.backend.mapping_package.models.entity import MappingPackageState
from mapping_workbench.backend.package_importer.services.import_mapping_suite import \
import_mapping_package_from_archive, clear_project_data
from mapping_workbench.backend.package_processor.services.mapping_package_processor import process_mapping_package
from mapping_workbench.backend.project.models.entity import Project
from tests.test_data.mapping_package_archives import EFORMS_PACKAGE_PATH


def read_archive(archive_path: Path) -> bytes:
with open(archive_path, 'rb') as file:
return file.read()


@pytest.mark.asyncio
async def test_process_mapping_package(dummy_mapping_package: MappingPackage):
async def test_process_mapping_package(
dummy_project: Project,
dummy_structural_element: StructuralElement
):
await dummy_structural_element.create()

eforms_package = (await import_mapping_package_from_archive(
read_archive(EFORMS_PACKAGE_PATH), dummy_project, PackageType.EFORMS
)).mapping_package


with enabled_gridfs_integration():
await dummy_mapping_package.save()
mapping_package_state: MappingPackageState = await process_mapping_package(package_id=dummy_mapping_package.id)
mapping_package_state: MappingPackageState = await process_mapping_package(package_id=eforms_package.id)
assert mapping_package_state
assert mapping_package_state.validation

await clear_project_data(dummy_project, PackageType.EFORMS)
Loading