Skip to content

Commit 504c338

Browse files
committed
added test package and refactored logic for eligibility checker
1 parent fa1a4eb commit 504c338

428 files changed

Lines changed: 172554 additions & 15 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ted_sws/core/model/metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ class NormalisedMetadata(Metadata):
7979
legal_basis_directive: str
8080
form_number: str
8181
eforms_subtype: str
82-
xsd_version: str
82+
xsd_version: Optional[str]
8383
published_in_cellar_counter: int = Field(default=0)
8484
is_eform: Optional[bool] = False
85+
eform_sdk_version: Optional[str]
8586

8687

8788
class NormalisedMetadataView(Metadata):

ted_sws/mapping_suite_processor/services/conceptual_mapping_generate_metadata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
END_DATE_KEY = "end_date"
1919
MIN_XSD_VERSION_KEY = "min_xsd_version"
2020
MAX_XSD_VERSION_KEY = "max_xsd_version"
21+
EFORMS_SDK_VERSIONS_KEY = "eforms_sdk_versions"
2122
TITLE_KEY = "title"
2223
CREATED_KEY = "created_at"
2324
IDENTIFIER_KEY = "identifier"

ted_sws/notice_metadata_processor/adapters/notice_metadata_normaliser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
DEADLINE_DATE_KEY = "deadline_for_submission"
3737
NOTICE_TYPE_KEY = "notice_type"
3838
XSD_VERSION_KEY = "xsd_version"
39+
EFORM_SDK_VERSION_KEY = "eform_sdk_version"
3940
IS_EFORM_KEY = "is_eform"
4041
ENGLISH_LANGUAGE_TAG = "EN"
4142
mapping_registry = MappingFilesRegistry()
@@ -339,7 +340,7 @@ def normalise_metadata(self, extracted_metadata: ExtractedMetadata) -> Normalise
339340
LEGAL_BASIS_DIRECTIVE_KEY: get_map_value(mapping=legal_basis_map,
340341
value=legal_basis),
341342
E_FORMS_SUBTYPE_KEY: extracted_metadata.extracted_notice_subtype,
342-
XSD_VERSION_KEY: extracted_metadata.xml_schema_version,
343+
EFORM_SDK_VERSION_KEY: extracted_metadata.xml_schema_version,
343344
IS_EFORM_KEY: True
344345
}
345346

ted_sws/notice_metadata_processor/services/notice_eligibility.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,31 @@
88
from ted_sws.core.model.transform import MappingSuite
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, \
11-
MIN_XSD_VERSION_KEY, MAX_XSD_VERSION_KEY, E_FORMS_SUBTYPE_KEY
11+
MIN_XSD_VERSION_KEY, MAX_XSD_VERSION_KEY, E_FORMS_SUBTYPE_KEY, EFORMS_SDK_VERSIONS_KEY
12+
13+
14+
def format_version_with_zero_patch(version_string:str) -> semantic_version.Version:
15+
"""
16+
This will take a string version (1.7 or 1.7.6) and will transform it to a semantic version with 0 as patch
17+
1.7 -> 1.7.0
18+
1.7.6 -> 1.7.0
19+
"""
20+
parsed_version = semantic_version.Version.coerce(version_string)
21+
return semantic_version.Version(major=parsed_version.major, minor=parsed_version.minor, patch=0)
22+
23+
24+
def is_date_in_range(publication_date, constraint_start_date_value, constraint_end_date_value) -> bool:
25+
"""
26+
This will return True or False if publication_date is in range looking at the start and end date constraints in the
27+
metadata of a mapping suite
28+
"""
29+
if not constraint_start_date_value and not constraint_end_date_value:
30+
return True
31+
32+
start_date = datetime.datetime.fromisoformat(constraint_start_date_value[0])
33+
end_date = datetime.datetime.fromisoformat(
34+
constraint_end_date_value[0] if constraint_end_date_value else datetime.datetime.now().isoformat())
35+
return start_date <= publication_date <= end_date
1236

1337

1438
def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetadata):
@@ -18,22 +42,29 @@ def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetada
1842
:param mapping_suite:
1943
:return:
2044
"""
45+
2146
constraints = mapping_suite.metadata_constraints.constraints
2247

2348
eform_subtype = notice_metadata.eforms_subtype
2449
notice_publication_date = datetime.datetime.fromisoformat(notice_metadata.publication_date)
25-
notice_xsd_version = notice_metadata.xsd_version
2650

27-
end_date = constraints[END_DATE_KEY][0] if constraints[END_DATE_KEY] else datetime.datetime.now().isoformat()
28-
constraint_start_date = datetime.datetime.fromisoformat(constraints[START_DATE_KEY][0])
29-
constraint_end_date = datetime.datetime.fromisoformat(end_date)
30-
constraint_min_xsd_version = constraints[MIN_XSD_VERSION_KEY][0]
31-
constraint_max_xsd_version = constraints[MAX_XSD_VERSION_KEY][0]
51+
if notice_metadata.is_eform:
52+
notice_xsd_version = notice_metadata.eform_sdk_version
53+
eforms_sdk_version = notice_xsd_version.rsplit('-', 1)[1]
54+
constraint_version_range = [format_version_with_zero_patch(version) for version in
55+
constraints[EFORMS_SDK_VERSIONS_KEY]]
56+
in_version_range = format_version_with_zero_patch(eforms_sdk_version) in constraint_version_range
57+
else:
58+
notice_xsd_version = notice_metadata.xsd_version
59+
constraint_min_xsd_version = constraints[MIN_XSD_VERSION_KEY][0]
60+
constraint_max_xsd_version = constraints[MAX_XSD_VERSION_KEY][0]
61+
in_version_range = constraint_min_xsd_version <= notice_xsd_version <= constraint_max_xsd_version
62+
63+
in_date_range = is_date_in_range(publication_date=notice_publication_date,
64+
constraint_start_date_value=constraints[START_DATE_KEY],
65+
constraint_end_date_value=constraints[END_DATE_KEY])
3266
eform_subtype_constraint_values = [str(eforms_subtype_value) for eforms_subtype_value in
3367
constraints[E_FORMS_SUBTYPE_KEY]]
34-
35-
in_date_range = constraint_start_date <= notice_publication_date <= constraint_end_date
36-
in_version_range = constraint_min_xsd_version <= notice_xsd_version <= constraint_max_xsd_version
3768
covered_eform_type = eform_subtype in eform_subtype_constraint_values
3869

3970
return True if in_date_range and in_version_range and covered_eform_type else False

tests/conftest.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,36 @@ def normalised_metadata_object():
212212

213213
return NormalisedMetadata(**data)
214214

215+
@pytest.fixture
216+
def eform_normalised_metadata_object():
217+
data = {
218+
"title": [LanguageTaggedString(text="Eteläisen Salon liikuntapaikkojen hoidon hankinta", language="FIN")],
219+
"long_title": [
220+
LanguageTaggedString(text="FIN :: Eteläisen Salon liikuntapaikkojen hoidon hankinta", language="FIN")],
221+
"notice_publication_number": "00622690-2023",
222+
"publication_date": "2023-10-13T00:00:00",
223+
"ojs_issue_number": "198/2023",
224+
"ojs_type": "S",
225+
"city_of_buyer": None,
226+
"name_of_buyer": None,
227+
"original_language": None,
228+
"country_of_buyer": None,
229+
"eu_institution": None,
230+
"document_sent_date": "2023-10-12T00:00:00",
231+
"deadline_for_submission": None,
232+
"notice_type": "http://publications.europa.eu/resource/authority/notice-type/cn-standard",
233+
"form_type": "http://publications.europa.eu/resource/authority/form-type/competition",
234+
"place_of_performance": ["http://data.europa.eu/nuts/code/FI1C1"],
235+
"extracted_legal_basis_directive": "http://publications.europa.eu/resource/authority/legal-basis/32014L0024",
236+
"legal_basis_directive": "http://publications.europa.eu/resource/authority/legal-basis/32014L0024",
237+
"form_number": "",
238+
"eforms_subtype": "16",
239+
"eform_sdk_version": "eforms-sdk-1.7",
240+
"published_in_cellar_counter": 0,
241+
"is_eform": True
242+
}
243+
244+
return NormalisedMetadata(**data)
215245

216246
@pytest.fixture
217247
@mongomock.patch(servers=(('server.example.com', 27017),))
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"identifier": "package_EF16",
3+
"title": "Package EF16 v1.2",
4+
"description": "This is the conceptual mapping for bla bla bla",
5+
"mapping_version": "3.0.0-alpha.1",
6+
"ontology_version": "4.0.0",
7+
"metadata_constraints": {
8+
"constraints": {
9+
"min_xsd_version": ["R2.0.9.S04.E01"],
10+
"max_xsd_version": ["R2.0.9.S04.E01"],
11+
"eforms_subtype": [
12+
"16",
13+
"10",
14+
"11",
15+
"12",
16+
"13",
17+
"X1",
18+
"T1"
19+
],
20+
"start_date": null,
21+
"end_date": null,
22+
"eforms_sdk_versions": [
23+
"1.3",
24+
"1.4",
25+
"1.5",
26+
"1.6",
27+
"1.7",
28+
"1.8",
29+
"1.9",
30+
"1.10"
31+
]
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)