Skip to content

Commit

Permalink
finished adding delete tests and removed unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmills-DIT committed Oct 23, 2023
1 parent 01e7787 commit f03021d
Show file tree
Hide file tree
Showing 50 changed files with 764 additions and 120 deletions.
115 changes: 0 additions & 115 deletions taric_parsers/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,32 +229,6 @@ def commit_changes_from_message(

message.taric_object.issues.append(report_item)

def find_object_in_import(
self,
current_transaction,
identity_fields: dict,
object_type,
):
match = None

for transaction in self.parsed_transactions:
for message in transaction.parsed_messages:
if message.object_type == object_type:
# check keys
key_match = True
for key in identity_fields.keys():
if getattr(message.taric_object, key) != identity_fields[key]:
key_match = False

if key_match:
return message.taric_object

return match

def print_stats(self, update_stats: dict):
for key in update_stats.keys():
print(f"{key} : {update_stats[key]}")

@property
def status(self):
if len(self.issues("ERROR")) > 0:
Expand Down Expand Up @@ -595,95 +569,6 @@ def validate_update_type_for(self, parsed_message, parsed_transaction):

parsed_message.taric_object.issues.append(report_item)

def _verify_link(
self,
verifying_taric_object: BaseTaricParser,
link_data: ModelLink,
):
# verify either that the object exists on TAP or in current, previous transactions of current import
kwargs = {}
for field in link_data.fields:
kwargs[field.object_field_name] = getattr(
verifying_taric_object,
field.parser_field_name,
)

# check database
db_result = link_data.model.objects.latest_approved().filter(**kwargs)
xml_result = []

for transaction in self.parsed_transactions:
for taric_object in transaction.taric_objects:
# check transaction ID - only want to check ones that are less than current verifying object
if taric_object.transaction_id > verifying_taric_object.transaction_id:
continue

match = False
if taric_object.xml_object_tag == link_data.xml_tag_name:
# ok we have matched the type - now check property
int_match = True
for field in link_data.fields:
if getattr(
verifying_taric_object,
field.parser_field_name,
) != getattr(
taric_object,
field.object_field_name,
):
int_match = False

if int_match:
match = True
if match:
xml_result.append(taric_object)

# verify that there is only one match, otherwise it's wrong
record_match_count = db_result.count() + len(xml_result)
if record_match_count == 1:
return True
elif record_match_count > 1:
self.create_issue_report_item(
verifying_taric_object,
link_data,
"Multiple matches for possible related taric object",
)

return False

self.create_issue_report_item(
verifying_taric_object,
link_data,
"No matches for possible related taric object",
)

return False

def create_issue_report_item(
self,
target_taric_object: BaseTaricParser,
link_data,
description,
):
identity_keys = {}

for field in link_data.fields:
identity_keys[field.object_field_name] = getattr(
target_taric_object,
field.parser_field_name,
)

report_item = ImportIssueReportItem(
target_taric_object.xml_object_tag,
link_data.xml_tag_name,
identity_keys,
description,
taric_change_type=target_taric_object.update_type_name,
object_details=str(target_taric_object),
transaction_id=target_taric_object.transaction_id,
)

target_taric_object.issues.append(report_item)

def issues(self, filter_by_issue_type: str = None):
issues = []
for transaction in self.parsed_transactions:
Expand Down
3 changes: 3 additions & 0 deletions taric_parsers/parsers/measure_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class NewMeasurementUnitQualifierDescriptionParser(Writable, BaseTaricParser):
"code",
]

deletes_allowed = False
code: str = None
# language_id: str = None
description: str = None
Expand Down Expand Up @@ -283,6 +284,8 @@ class NewMonetaryUnitDescriptionParser(Writable, BaseTaricParser):
"code",
]

deletes_allowed = False

code: str = None
# language_id: str = None
description: str = None
Expand Down
1 change: 1 addition & 0 deletions taric_parsers/parsers/regulation_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class NewRegulationGroupDescriptionParser(Writable, BaseTaricParser):
"group_id",
]

deletes_allowed = False
group_id: str = None
# language_id: str = None
description: str = None
Expand Down
1 change: 0 additions & 1 deletion taric_parsers/tests.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<env:envelope id="000001" xmlns="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0" xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0">
<env:transaction id="1">
<env:app.message id="3">
<oub:transmission xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0"
xmlns:oub="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0">
<oub:record>
<oub:transaction.id>1</oub:transaction.id>
<oub:record.code>210</oub:record.code>
<oub:subrecord.code>00</oub:subrecord.code>
<oub:record.sequence.number>3</oub:record.sequence.number>
<oub:update.type>2</oub:update.type>
<oub:measurement.unit>
<oub:measurement.unit.code>XXX</oub:measurement.unit.code>
<oub:validity.start.date>2021-01-11</oub:validity.start.date>
<oub:validity.end.date>2022-01-01</oub:validity.end.date>
</oub:measurement.unit>
</oub:record>
</oub:transmission>
</env:app.message>
</env:transaction>
</env:envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<env:envelope id="000001" xmlns="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0" xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0">
<env:transaction id="1">
<env:app.message id="3">
<oub:transmission xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0"
xmlns:oub="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0">
<oub:record>
<oub:transaction.id>1</oub:transaction.id>
<oub:record.code>215</oub:record.code>
<oub:subrecord.code>00</oub:subrecord.code>
<oub:record.sequence.number>3</oub:record.sequence.number>
<oub:update.type>2</oub:update.type>
<oub:measurement.unit.qualifier>
<oub:measurement.unit.qualifier.code>A</oub:measurement.unit.qualifier.code>
<oub:validity.start.date>2021-01-11</oub:validity.start.date>
<oub:validity.end.date>2022-01-01</oub:validity.end.date>
</oub:measurement.unit.qualifier>
</oub:record>
</oub:transmission>
</env:app.message>
</env:transaction>
</env:envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<env:envelope id="000001" xmlns="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0" xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0">
<env:transaction id="1">
<env:app.message id="3">
<oub:transmission xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0"
xmlns:oub="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0">
<oub:record>
<oub:transaction.id>1</oub:transaction.id>
<oub:record.code>215</oub:record.code>
<oub:subrecord.code>05</oub:subrecord.code>
<oub:record.sequence.number>3</oub:record.sequence.number>
<oub:update.type>2</oub:update.type>
<oub:measurement.unit.qualifier.description>
<oub:measurement.unit.qualifier.code>A</oub:measurement.unit.qualifier.code>
<oub:language.id>ZZ</oub:language.id>
<oub:description>Some Description with changes</oub:description>
</oub:measurement.unit.qualifier.description>
</oub:record>
</oub:transmission>
</env:app.message>
</env:transaction>
</env:envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<env:envelope id="000001" xmlns="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0" xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0">
<env:transaction id="1">
<env:app.message id="3">
<oub:transmission xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0"
xmlns:oub="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0">
<oub:record>
<oub:transaction.id>1</oub:transaction.id>
<oub:record.code>225</oub:record.code>
<oub:subrecord.code>00</oub:subrecord.code>
<oub:record.sequence.number>3</oub:record.sequence.number>
<oub:update.type>2</oub:update.type>
<oub:monetary.unit>
<oub:monetary.unit.code>ZZZ</oub:monetary.unit.code>
<oub:validity.start.date>2021-01-11</oub:validity.start.date>
<oub:validity.end.date>2022-01-01</oub:validity.end.date>
</oub:monetary.unit>
</oub:record>
</oub:transmission>
</env:app.message>
</env:transaction>
</env:envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<env:envelope id="000001" xmlns="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0" xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0">
<env:transaction id="1">
<env:app.message id="3">
<oub:transmission xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0"
xmlns:oub="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0">
<oub:record>
<oub:transaction.id>1</oub:transaction.id>
<oub:record.code>225</oub:record.code>
<oub:subrecord.code>05</oub:subrecord.code>
<oub:record.sequence.number>3</oub:record.sequence.number>
<oub:update.type>2</oub:update.type>
<oub:monetary.unit.description>
<oub:monetary.unit.code>ZZZ</oub:monetary.unit.code>
<oub:language.id>zz</oub:language.id>
<oub:description>Some Description with changes</oub:description>
</oub:monetary.unit.description>
</oub:record>
</oub:transmission>
</env:app.message>
</env:transaction>

</env:envelope>
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ def test_import_update(self, superuser):
assert len(importer.issues()) == 0

assert MeasurementUnit.objects.all().count() == 2

def test_import_delete(self, superuser):
preload_import("measurement_unit_CREATE.xml", __file__, True)
importer = preload_import("measurement_unit_DELETE.xml", __file__)

assert len(importer.issues()) == 0

assert MeasurementUnit.objects.all().count() == 2
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,21 @@ def test_import_update(self, superuser):
assert len(importer.issues()) == 0

assert MeasurementUnitQualifier.objects.all().count() == 2

def test_import_delete(self, superuser):
preload_import(
"measurement_unit_qualifier_description_CREATE.xml",
__file__,
True,
)
importer = preload_import(
"measurement_unit_qualifier_description_DELETE.xml",
__file__,
)

assert len(importer.issues()) == 1

assert (
"Children of Taric objects of type MeasurementUnitQualifier can't be deleted directly"
in str(importer.issues()[0])
)
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ def test_import_update(self, superuser):
assert len(importer.issues()) == 0

assert MeasurementUnitQualifier.objects.all().count() == 2

def test_import_delete(self, superuser):
preload_import("measurement_unit_qualifier_CREATE.xml", __file__, True)
importer = preload_import("measurement_unit_qualifier_DELETE.xml", __file__)

assert len(importer.issues()) == 0

assert MeasurementUnitQualifier.objects.all().count() == 2
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,14 @@ def test_import_update(self, superuser):
assert len(importer.issues()) == 0

assert MonetaryUnit.objects.all().count() == 2

def test_import_delete(self, superuser):
preload_import("monetary_unit_description_CREATE.xml", __file__, True)
importer = preload_import("monetary_unit_description_DELETE.xml", __file__)

assert len(importer.issues()) == 1

assert (
"Children of Taric objects of type MonetaryUnit can't be deleted directly"
in str(importer.issues()[0])
)
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ def test_import_update(self, superuser):
assert len(importer.issues()) == 0

assert MonetaryUnit.objects.all().count() == 2

def test_import_delete(self, superuser):
preload_import("monetary_unit_CREATE.xml", __file__, True)
importer = preload_import("monetary_unit_DELETE.xml", __file__)

assert len(importer.issues()) == 0

assert MonetaryUnit.objects.all().count() == 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<env:envelope id="000001" xmlns="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0"
xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0">
<env:transaction id="1">
<env:app.message id="7">
<oub:transmission xmlns:oub="urn:publicid:-:DGTAXUD:TARIC:MESSAGE:1.0"
xmlns:env="urn:publicid:-:DGTAXUD:GENERAL:ENVELOPE:1.0">
<oub:record>
<oub:transaction.id>19971104</oub:transaction.id>
<oub:record.code>370</oub:record.code>
<oub:subrecord.code>05</oub:subrecord.code>
<oub:record.sequence.number>1</oub:record.sequence.number>
<oub:update.type>2</oub:update.type>
<oub:quota.association>
<oub:main.quota.definition.sid>99</oub:main.quota.definition.sid>
<oub:sub.quota.definition.sid>100</oub:sub.quota.definition.sid>
<oub:relation.type>EQ</oub:relation.type>
<oub:coefficient>1.1</oub:coefficient>
</oub:quota.association>
</oub:record>
</oub:transmission>
</env:app.message>
</env:transaction>
</env:envelope>
Loading

0 comments on commit f03021d

Please sign in to comment.