Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ndef based edge defs to addNodes API #2051

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions synapse/lib/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,11 @@ async def addNodes(self, nodedefs):
await node.setData(name, data)

for verb, n2iden in forminfo.get('edges', ()):
# check for embedded ndef rather than n2iden
if isinstance(n2iden, (list, tuple)):
n2form, n2valu = n2iden
n2node = await self.addNode(n2form, n2valu)
n2iden = n2node.iden()
await node.addEdge(verb, n2iden)

except asyncio.CancelledError: # pragma: no cover TODO: remove once >= py 3.8 only
Expand Down
2 changes: 2 additions & 0 deletions synapse/tests/test_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3025,6 +3025,7 @@ async def test_feed_syn_nodes(self):
await node1.setData('foo', 'bar')
pack = node1.pack()
pack[1]['nodedata']['foo'] = 'bar'
pack[1]['edges'] = (('refs', ('inet:ipv4', '1.2.3.4')),)
podes.append(pack)

node2 = (await core0.nodes('[ test:int=2 ] | [ +(refs)> { test:int=1 } ]'))[0]
Expand All @@ -3039,6 +3040,7 @@ async def test_feed_syn_nodes(self):

await core1.addFeedData('syn.nodes', podes)
await self.agenlen(3, core1.eval('test:int'))
self.len(1, await core1.nodes('test:int=1 -(refs)> inet:ipv4 +inet:ipv4=1.2.3.4'))

node1 = (await core1.nodes('test:int=1'))[0]
self.eq('bar', await node1.getData('foo'))
Expand Down