Skip to content

Commit

Permalink
minimally-update provenance tests to interface with provenance reimpl…
Browse files Browse the repository at this point in the history
…ementation
  • Loading branch information
alexdunnjpl committed Jan 31, 2024
1 parent d2ccfea commit b90fc9f
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tests/pds/registrysweepers/provenance/test_provenance.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import itertools
import json
import os.path
import unittest

from pds.registrysweepers import provenance
from pds.registrysweepers.provenance import ProvenanceRecord
from pds.registrysweepers.provenance import SWEEPERS_PROVENANCE_VERSION
from pds.registrysweepers.utils.db import Update


Expand All @@ -24,7 +27,6 @@ class ProvenanceBasicFunctionalTestCase(unittest.TestCase):
]

def test_correct_provenance_produced(self):
successors_by_lidvid = provenance.get_successors_by_lidvid(self.extant_lidvids)
expected_provenance = {
"urn:nasa:pds:bundle::1.0": "urn:nasa:pds:bundle::1.1",
"urn:nasa:pds:bundle::1.1": "urn:nasa:pds:bundle::2.0",
Expand All @@ -33,19 +35,33 @@ def test_correct_provenance_produced(self):
"urn:nasa:pds:bundle:collection:product::100.0": "urn:nasa:pds:bundle:collection:product::100.1",
"urn:nasa:pds:bundle:collection:product::100.1": "urn:nasa:pds:bundle:collection:product::200.0",
}
self.assertDictEqual(expected_provenance, successors_by_lidvid)

def crude_update_hash(update: Update) -> str:
d = {"id": update.id, "content": update.content}
return json.dumps(d, sort_keys=True)

updates = provenance.generate_updates(successors_by_lidvid)
records = [ProvenanceRecord.from_source({"lidvid": lidvid}) for lidvid in self.extant_lidvids]
record_chains = provenance.create_record_chains(records)
for record_chain in record_chains:
provenance.link_records_in_chain(record_chain)

updates = provenance.generate_updates(itertools.chain(*record_chains))
# previously, updates were not generated for latest products, so we need to exclude those from comparison for
# consistency
legacy_updates = [u for u in updates if u.content["ops:Provenance/ops:superseded_by"] is not None]
expected_updates = [
Update(id=k, content={"ops:Provenance/ops:superseded_by": v}) for k, v in expected_provenance.items()
Update(
id=k,
content={
"ops:Provenance/ops:superseded_by": v,
"ops:Provenance/ops:registry_sweepers_provenance_version": SWEEPERS_PROVENANCE_VERSION,
},
)
for k, v in expected_provenance.items()
]

self.assertSetEqual(
set(crude_update_hash(u) for u in expected_updates), set(crude_update_hash(u) for u in updates)
set(crude_update_hash(u) for u in expected_updates), set(crude_update_hash(u) for u in legacy_updates)
)


Expand Down

0 comments on commit b90fc9f

Please sign in to comment.