From 2dddd7f5ae1bec877e506da7fdefffba9fe2dea3 Mon Sep 17 00:00:00 2001 From: visi Date: Wed, 20 Jan 2021 10:46:55 -0500 Subject: [PATCH] added ndef based edge defs to addNodes API --- synapse/lib/snap.py | 5 +++++ synapse/tests/test_cortex.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/synapse/lib/snap.py b/synapse/lib/snap.py index 2aedbf0fb1..283dc976c0 100644 --- a/synapse/lib/snap.py +++ b/synapse/lib/snap.py @@ -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 diff --git a/synapse/tests/test_cortex.py b/synapse/tests/test_cortex.py index b13a73a423..3229f70392 100644 --- a/synapse/tests/test_cortex.py +++ b/synapse/tests/test_cortex.py @@ -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] @@ -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'))