Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Cisphyx committed May 31, 2024
1 parent a2163c2 commit 15cb23b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
8 changes: 5 additions & 3 deletions synapse/cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4521,7 +4521,7 @@ async def delViewWithLayer(self, iden):
return await self._push('view:delwithlayer', iden, view.layers[0].iden, newparent=pareiden)

@s_nexus.Pusher.onPush('view:delwithlayer', passitem=True)
async def _delViewAndLayer(self, viewiden, layriden, nexsitem, newparent=None):
async def _delViewWithLayer(self, viewiden, layriden, nexsitem, newparent=None):

if viewiden == self.view.iden:
raise s_exc.SynErr(mesg='Cannot delete the main view')
Expand All @@ -4535,14 +4535,16 @@ async def _delViewAndLayer(self, viewiden, layriden, nexsitem, newparent=None):
await self.feedBeholder('view:del', {'iden': viewiden}, gates=[viewiden])
await self.auth.delAuthGate(viewiden)

newview = self.views.get(newparent)
if newparent is not None:
newview = self.views.get(newparent)

for cview in self.views.values():
if cview.parent is not None and cview.parent.iden == viewiden:
cview.parent = newview
if newparent is None:
cview.parent = None
await cview.info.pop('parent')

Check warning on line 4545 in synapse/cortex.py

View check run for this annotation

Codecov / codecov/patch

synapse/cortex.py#L4544-L4545

Added lines #L4544 - L4545 were not covered by tests
else:
cview.parent = newview
await cview.info.set('parent', newparent)

if (layr := self.layers.get(layriden)) is not None:
Expand Down
38 changes: 38 additions & 0 deletions synapse/tests/test_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6292,12 +6292,14 @@ async def test_cortex_delLayerView(self):

# Can't delete the default view
await self.asyncraises(s_exc.SynErr, core.delView(core.view.iden))
await self.asyncraises(s_exc.SynErr, core._delViewWithLayer(core.view.iden, None, None))

# Can't delete a layer in a view
await self.asyncraises(s_exc.SynErr, core.delLayer(core.view.layers[0].iden))

# Can't delete a nonexistent view
await self.asyncraises(s_exc.NoSuchView, core.delView('XXX'))
await self.asyncraises(s_exc.NoSuchView, core.delViewWithLayer('XXX'))

# Can't delete a nonexistent layer
await self.asyncraises(s_exc.NoSuchLayer, core.delLayer('XXX'))
Expand All @@ -6310,6 +6312,42 @@ async def test_cortex_delLayerView(self):
await core.delView(view2_iden)
await self.asyncraises(s_exc.NoSuchView, core.delView(view2_iden))

layr = await core.addLayer()
layriden = layr['iden']
vdef3 = {'layers': (layriden,)}
view3_iden = (await core.addView(vdef3)).get('iden')

opts = {'view': view3_iden}
await core.callStorm('$lib.view.get().set(protected, $lib.true)', opts=opts)

await self.asyncraises(s_exc.CantDelView, core.delViewWithLayer(view3_iden))

await core.callStorm('$lib.view.get().set(protected, $lib.false)', opts=opts)

view3 = core.getView(view3_iden)
vdef4 = await view3.fork()

view4 = core.getView(vdef4.get('iden'))

await core.auth.rootuser.setPasswd('secret')
host, port = await core.dmon.listen('tcp://127.0.0.1:0/')
layr2 = await core.callStorm('$layer=$lib.layer.add() return($layer)')
varz = {'iden': layriden, 'tgt': layr2.get('iden'), 'port': port}
opts = {'vars': varz, 'view': view3_iden}

pullq = '$layer=$lib.layer.get($iden).addPull(`tcp://root:[email protected]:{$port}/*/layer/{$tgt}`)'
pushq = '$layer=$lib.layer.get($iden).addPush(`tcp://root:[email protected]:{$port}/*/layer/{$tgt}`)'
msgs = await core.stormlist(pullq, opts=opts)
self.stormHasNoWarnErr(msgs)

msgs = await core.stormlist(pushq, opts=opts)
self.stormHasNoWarnErr(msgs)

await core.delViewWithLayer(view3_iden)

self.none(view4.parent)
self.len(1, view4.layers)

async def test_cortex_view_opts(self):
'''
Test that the view opts work
Expand Down
5 changes: 4 additions & 1 deletion synapse/tests/test_lib_stormtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6762,6 +6762,7 @@ async def test_view_quorum(self):
midfork = core.getView(fork00['iden'])

fork01 = await midfork.fork()
self.true(midfork.hasKids())

opts = {'view': midfork.iden}
await core.callStorm('return($lib.view.get().setMergeRequest())', opts=opts)
Expand All @@ -6776,8 +6777,10 @@ async def test_view_quorum(self):
self.eq([], await core.callStorm(merging))

leaffork = core.getView(fork01['iden'])
self.eq(leaffork.parent, core.getView())
self.false(leaffork.hasKids())

self.len(2, leaffork.layers)
self.eq(leaffork.parent, core.getView())

# test coverage for bad state for merge request
opts = {'view': fork01['iden']}
Expand Down
10 changes: 10 additions & 0 deletions synapse/tests/test_lib_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,10 +859,20 @@ async def test_view_insert_parent_fork(self):
msgs = await core.stormlist('auth.user.addrule visi node --gate $lib.view.get().layers.0.iden')
self.stormHasNoWarnErr(msgs)

opts = {'vars': {'role': role.iden}}
quorum = await core.callStorm('return($lib.view.get().set(quorum, ({"count": 1, "roles": [$role]})))', opts=opts)

forkopts = {'view': view02.iden}
await core.callStorm('return($lib.view.get().setMergeRequest(comment=woot))', opts=forkopts)

merging = 'return($lib.view.get().getMergingViews()) '
self.eq([view02.iden], await core.callStorm(merging))

q = 'return($lib.view.get().insertParentFork(name=staging).iden)'
newiden = await core.callStorm(q, opts=forkopts)

self.eq([], await core.callStorm(merging))

view01 = core.getView(newiden)

self.ne(view02.parent, view00)
Expand Down
1 change: 0 additions & 1 deletion synapse/tests/test_model_inet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,6 @@ async def test_url(self):
'''
nodes = await core.nodes(q)
self.len(7, nodes)
print(nodes)
self.eq(nodes[0].get('base'), 'http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:80/index.html')
self.eq(nodes[0].get('proto'), 'http')
self.eq(nodes[0].get('path'), '/index.html')
Expand Down

0 comments on commit 15cb23b

Please sign in to comment.