Skip to content

Commit

Permalink
fixup! Fix: tdr_anvils fetch_bundle lacks test coverage (#5046)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadove-ucsc committed Jan 26, 2024
1 parent 5dbbb22 commit 9283e58
Showing 1 changed file with 24 additions and 36 deletions.
60 changes: 24 additions & 36 deletions test/indexer/test_tdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,49 +288,37 @@ def test_fetch_bundle(self):
bundle = self._load_canned_bundle(self.bundle_fqid)
# Test valid links
self._test_fetch_bundle(bundle, load_tables=True)
# Test invalid links
self._test_invalid_links(bundle)

def _test_invalid_links(self, bundle: TDRHCABundle):
# Directly modify the canned tables to test invalid links not present
# in the canned bundle.
# Test invalid links by modifying the canned bundle
spec = self.source.spec
plugin = self.plugin_for_source_spec(spec)
links = one(plugin.tdr.run_sql(f'''
SELECT links_id, content
FROM {plugin._full_table_name(spec, 'links')}
'''))
links_id, links_content = links['links_id'], json.loads(links['content'])
link = first(link
for link in links_content['links']
if link['link_type'] == 'supplementary_file_link')
# Test invalid entity_type in supplementary_file_link
assert link['entity']['entity_type'] == 'project'
link['entity']['entity_type'] = 'cell_suspension'
# Update table
plugin.tdr.run_sql(f'''
UPDATE {plugin._full_table_name(spec, 'links')}
SET content = {json.dumps(links_content)!r}
WHERE links_id = "{links_id}"
''')
# Invoke code under test
with self.assertRaises(RequirementError):
self._test_fetch_bundle(bundle,
load_tables=False) # Avoid resetting tables to canned state

# Undo previous change
link['entity']['entity_type'] = 'project'
# Test invalid entity_id in supplementary_file_link
link['entity']['entity_id'] += '_wrong'
# Update table
plugin.tdr.run_sql(f'''
UPDATE {plugin._full_table_name(spec, 'links')}
SET content = {json.dumps(links_content)!r}
WHERE links_id = "{links_id}"
''')
# Invoke code under test
with self.assertRaises(RequirementError):
self._test_fetch_bundle(bundle, load_tables=False)
link = first(
link
for link in links_content['links']
if link['link_type'] == 'supplementary_file_link'
)
linked_entity = link['entity']
assert linked_entity['entity_type'] == 'project', linked_entity
bad_link_fields = [
{'entity_type': 'cell_suspension'},
{'entity_id': linked_entity['entity_id'] + '_wrong'}
]
for field in bad_link_fields:
link['entity'] = linked_entity | field
# Update table with invalid link
plugin.tdr.run_sql(f'''
UPDATE {plugin._full_table_name(spec, 'links')}
SET content = {json.dumps(links_content)!r}
WHERE links_id = "{links_id}"
''')
# Invoke code under test
with self.assertRaises(RequirementError):
self._test_fetch_bundle(bundle,
load_tables=False) # Avoid resetting tables to canned state

def test_subgraph_stitching(self):
downstream_uuid = '4426adc5-b3c5-5aab-ab86-51d8ce44dfbe'
Expand Down

0 comments on commit 9283e58

Please sign in to comment.