Skip to content

Commit 44b8a0b

Browse files
Merge pull request #517 from OP-TED/feature/TED4-84
update MappingSuite to support eForms
2 parents b03915a + 22f35bf commit 44b8a0b

8 files changed

Lines changed: 76 additions & 23 deletions

File tree

ted_sws/core/model/transform.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
""" """
99
import abc
1010
from datetime import datetime
11+
from enum import Enum
1112
from typing import List, Optional
1213

1314
from ted_sws.core.model import PropertyBaseModel
@@ -188,6 +189,14 @@ class ConceptualMapping(MappingSuiteComponent):
188189
cl2_organisations: List[ConceptualMappingControlList] = []
189190

190191

192+
class MappingSuiteType(str, Enum):
193+
STANDARD_FORMS = "standard_forms"
194+
ELECTRONIC_FORMS = "eforms"
195+
196+
def __str__(self):
197+
return self.value
198+
199+
191200
class MappingSuite(MappingSuiteComponent):
192201
"""
193202
@@ -199,6 +208,7 @@ class MappingSuite(MappingSuiteComponent):
199208
ontology_version: str = "0.0.1"
200209
git_latest_commit_hash: str = "no_hash"
201210
mapping_suite_hash_digest: str = "no_hash"
211+
mapping_type: Optional[MappingSuiteType] = MappingSuiteType.STANDARD_FORMS
202212
metadata_constraints: MetadataConstraints
203213
transformation_rule_set: TransformationRuleSet
204214
shacl_test_suites: List[SHACLTestSuite]

ted_sws/notice_metadata_processor/services/notice_eligibility.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
from ted_sws.core.model.metadata import NormalisedMetadata, NoticeSource
77
from ted_sws.core.model.notice import Notice
8-
from ted_sws.core.model.transform import MappingSuite
8+
from ted_sws.core.model.transform import MappingSuite, MappingSuiteType
99
from ted_sws.data_manager.adapters.repository_abc import MappingSuiteRepositoryABC, NoticeRepositoryABC
1010
from ted_sws.mapping_suite_processor.services.conceptual_mapping_generate_metadata import START_DATE_KEY, END_DATE_KEY, \
1111
MIN_XSD_VERSION_KEY, MAX_XSD_VERSION_KEY, E_FORMS_SUBTYPE_KEY, EFORMS_SDK_VERSIONS_KEY
1212

1313

14-
def format_version_with_zero_patch(version_string:str) -> semantic_version.Version:
14+
def format_version_with_zero_patch(version_string: str) -> semantic_version.Version:
1515
"""
1616
This will take a string version (1.7 or 1.7.6) and will transform it to a semantic version with 0 as patch
1717
1.7 -> 1.7.0
@@ -35,6 +35,25 @@ def is_date_in_range(publication_date, constraint_start_date_value, constraint_e
3535
return start_date <= publication_date <= end_date
3636

3737

38+
def is_version_in_range(notice_metadata: NormalisedMetadata, mapping_suite: MappingSuite) -> bool:
39+
constraints = mapping_suite.metadata_constraints.constraints
40+
if mapping_suite.mapping_type == MappingSuiteType.ELECTRONIC_FORMS and notice_metadata.notice_source == NoticeSource.ELECTRONIC_FORM:
41+
notice_xsd_version = notice_metadata.eform_sdk_version
42+
# eform sdk version value in metadata example: eforms-sdk-1.7 or eforms-sdk-1.7.9
43+
# we need to extract only the version i.e 1.7 or 1.7.9
44+
eforms_sdk_version = notice_xsd_version.rsplit('-', 1)[1]
45+
constraint_version_range = [format_version_with_zero_patch(version) for version in
46+
constraints[EFORMS_SDK_VERSIONS_KEY]]
47+
return format_version_with_zero_patch(eforms_sdk_version) in constraint_version_range
48+
elif mapping_suite.mapping_type == MappingSuiteType.STANDARD_FORMS and notice_metadata.notice_source == NoticeSource.STANDARD_FORM:
49+
notice_xsd_version = notice_metadata.xsd_version
50+
constraint_min_xsd_version = constraints[MIN_XSD_VERSION_KEY][0]
51+
constraint_max_xsd_version = constraints[MAX_XSD_VERSION_KEY][0]
52+
return constraint_min_xsd_version <= notice_xsd_version <= constraint_max_xsd_version
53+
54+
return False
55+
56+
3857
def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetadata):
3958
"""
4059
Check if mapping suite is valid for notice
@@ -47,20 +66,7 @@ def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetada
4766

4867
eform_subtype = notice_metadata.eforms_subtype
4968
notice_publication_date = datetime.datetime.fromisoformat(notice_metadata.publication_date)
50-
51-
if notice_metadata.notice_source == NoticeSource.ELECTRONIC_FORM:
52-
notice_xsd_version = notice_metadata.eform_sdk_version
53-
# eform sdk version value in metadata example: eforms-sdk-1.7 or eforms-sdk-1.7.9
54-
# we need to extract only the version i.e 1.7 or 1.7.9
55-
eforms_sdk_version = notice_xsd_version.rsplit('-', 1)[1]
56-
constraint_version_range = [format_version_with_zero_patch(version) for version in
57-
constraints[EFORMS_SDK_VERSIONS_KEY]]
58-
in_version_range = format_version_with_zero_patch(eforms_sdk_version) in constraint_version_range
59-
else:
60-
notice_xsd_version = notice_metadata.xsd_version
61-
constraint_min_xsd_version = constraints[MIN_XSD_VERSION_KEY][0]
62-
constraint_max_xsd_version = constraints[MAX_XSD_VERSION_KEY][0]
63-
in_version_range = constraint_min_xsd_version <= notice_xsd_version <= constraint_max_xsd_version
69+
in_version_range = is_version_in_range(notice_metadata=notice_metadata, mapping_suite=mapping_suite)
6470

6571
in_date_range = is_date_in_range(publication_date=notice_publication_date,
6672
constraint_start_date_value=constraints[START_DATE_KEY],

tests/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def normalised_metadata_object():
212212

213213
return NormalisedMetadata(**data)
214214

215+
215216
@pytest.fixture
216217
def eform_normalised_metadata_object():
217218
data = {
@@ -242,6 +243,7 @@ def eform_normalised_metadata_object():
242243

243244
return NormalisedMetadata(**data)
244245

246+
245247
@pytest.fixture
246248
@mongomock.patch(servers=(('server.example.com', 27017),))
247249
def mongodb_client():
@@ -302,4 +304,10 @@ def eform_notice_622690():
302304
notice = Notice(ted_id=ted_id)
303305
notice.set_xml_manifestation(xml_manifestation)
304306
notice.set_original_metadata(original_metadata)
305-
return notice
307+
return notice
308+
309+
310+
@pytest.fixture
311+
def indexed_eform_notice_622690(eform_notice_622690):
312+
eform_notice_622690.set_xml_metadata(XMLMetadata(unique_xpaths=["FAKE_INDEX_XPATHS"]))
313+
return eform_notice_622690

tests/test_data/notice_transformer/test_repository/test_package4/metadata.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
"description": "This is the conceptual mapping for bla bla bla",
55
"mapping_version": "3.0.0-alpha.1",
66
"ontology_version": "4.0.0",
7+
"mapping_type": "eforms",
78
"metadata_constraints": {
89
"constraints": {
9-
"min_xsd_version": ["R2.0.9.S04.E01"],
10-
"max_xsd_version": ["R2.0.9.S04.E01"],
1110
"eforms_subtype": [
1211
"16",
1312
"10",

tests/unit/data_manager/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ def file_system_repository_path():
1616
return TEST_DATA_PATH / "notice_transformer" / "test_file_system_repository"
1717

1818

19+
@pytest.fixture
20+
def file_system_repository_with_packages_path():
21+
return TEST_DATA_PATH / "notice_transformer" / "test_repository"
22+
23+
24+
@pytest.fixture
25+
def epo_mapping_suite_package_name():
26+
return "test_package4"
27+
1928
@pytest.fixture
2029
def fake_mapping_suite():
2130
metadata_constrains = MetadataConstraints(constraints=dict())

tests/unit/data_manager/test_mapping_suite_repository.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ def test_mapping_suite_repository_mongodb_update_invalid_id(mongodb_client, fake
3838
mongodb_client.drop_database(aggregates_database_name)
3939

4040

41+
def test_epo_mapping_suite_repository_in_file_system(file_system_repository_with_packages_path,
42+
epo_mapping_suite_package_name):
43+
assert file_system_repository_with_packages_path.exists()
44+
mapping_suite_repository = MappingSuiteRepositoryInFileSystem(
45+
repository_path=file_system_repository_with_packages_path)
46+
result_mapping_suite = mapping_suite_repository.get(reference=epo_mapping_suite_package_name)
47+
assert result_mapping_suite
48+
assert result_mapping_suite.identifier == "package_EF16"
49+
assert result_mapping_suite.title == "Package EF16 v1.2"
50+
assert result_mapping_suite.mapping_type == "eforms"
51+
assert result_mapping_suite.metadata_constraints.constraints
52+
constraints = result_mapping_suite.metadata_constraints.constraints
53+
assert constraints["eforms_subtype"]
54+
assert constraints["eforms_sdk_versions"]
55+
56+
4157
def test_mapping_suite_repository_in_file_system(file_system_repository_path, fake_mapping_suite):
4258
mapping_suite_repository = MappingSuiteRepositoryInFileSystem(repository_path=file_system_repository_path)
4359
mapping_suite_repository.clear_repository()

tests/unit/notice_metadata_processor/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ def notice_eligibility_repository_path():
1111
@pytest.fixture
1212
def file_system_repository_path():
1313
return TEST_DATA_PATH / "notice_transformer" / "mapping_suite_processor_repository"
14-

tests/unit/notice_metadata_processor/test_eligibility.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99
notice_eligibility_checker, notice_eligibility_checker_by_id, format_version_with_zero_patch, is_date_in_range
1010

1111

12-
# TODO remove min and max xsd version when the mapping loader is refactored tests/test_data/notice_transformer/test_repository/test_package4/metadata.json
13-
# TODO Add test for eform using mappinSuiteRepository
1412
def test_non_eligibility_by_notice(notice_eligibility_repository_path, indexed_notice):
1513
mapping_suite_repository = MappingSuiteRepositoryInFileSystem(repository_path=notice_eligibility_repository_path)
1614
normalise_notice(notice=indexed_notice)
1715
notice_eligibility_checker(notice=indexed_notice, mapping_suite_repository=mapping_suite_repository)
1816
assert indexed_notice.status == NoticeStatus.INELIGIBLE_FOR_TRANSFORMATION
1917

2018

19+
def test_eforms_eligibility_by_notice(notice_eligibility_repository_path, indexed_eform_notice_622690):
20+
mapping_suite_repository = MappingSuiteRepositoryInFileSystem(repository_path=notice_eligibility_repository_path)
21+
normalise_notice(notice=indexed_eform_notice_622690)
22+
notice_eligibility_checker(notice=indexed_eform_notice_622690, mapping_suite_repository=mapping_suite_repository)
23+
assert indexed_eform_notice_622690.status == NoticeStatus.ELIGIBLE_FOR_TRANSFORMATION
24+
25+
2126
def test_eligibility_by_notice(notice_eligibility_repository_path, notice_2020):
2227
mapping_suite_repository = MappingSuiteRepositoryInFileSystem(repository_path=notice_eligibility_repository_path)
2328
normalise_notice(notice=notice_2020)
@@ -42,7 +47,8 @@ def test_eligibility_by_notice_id(notice_eligibility_repository_path, notice_202
4247
assert notice_2020.status == NoticeStatus.ELIGIBLE_FOR_TRANSFORMATION
4348

4449

45-
def test_check_mapping_suite(notice_eligibility_repository_path, normalised_metadata_object, eform_normalised_metadata_object):
50+
def test_check_mapping_suite(notice_eligibility_repository_path, normalised_metadata_object,
51+
eform_normalised_metadata_object):
4652
mapping_suite_repository = MappingSuiteRepositoryInFileSystem(repository_path=notice_eligibility_repository_path)
4753
is_valid = check_package(mapping_suite=mapping_suite_repository.get("test_package"),
4854
notice_metadata=normalised_metadata_object)

0 commit comments

Comments
 (0)